Skip to content

Commit a3d0113

Browse files
author
TinaTiel
committed
Reorganized tests so that any tests requiring manually setting up OBS first are in the 'manual' package. By modifying the gradle build file, now those tests can be excluded and the rest of the integration tests can be run automatically
1 parent da3012d commit a3d0113

File tree

8 files changed

+129
-146
lines changed

8 files changed

+129
-146
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test {
5050

5151
integrationTest {
5252
useJUnitPlatform()
53+
exclude '**/manual'
5354
}
5455

5556
task javadocJar(type: Jar) {

obs-resources/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ instead of `REPLACE_ME\static\image.jpg`.
3030
Once you have imported the normalized scene collection, you can run the End-To-End tests (in `E2EUnsecuredIT.java`) in one window (or directly from your IDE)...
3131

3232
```
33-
gradlew :clean :integrationTest --info --tests "net.twasi.obsremotejava.test.ObsRemoteE2eObservationIT"
33+
gradlew :clean :integrationTest --info --tests "net.twasi.obsremotejava.test.manual.ObsRemoteE2eObservationIT"
3434
```
3535

3636
...And observe OBS in another.

src/integrationTest/java/net/twasi/obsremotejava/test/AbstractObsE2ETest.java

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,46 @@
66
import java.util.concurrent.LinkedBlockingQueue;
77
import java.util.function.Consumer;
88
import net.twasi.obsremotejava.OBSRemoteController;
9-
import org.junit.jupiter.api.BeforeAll;
109

1110
public abstract class AbstractObsE2ETest {
1211

13-
static OBSRemoteController remote;
14-
BlockingQueue resultQueue = new LinkedBlockingQueue();
12+
protected static OBSRemoteController remote;
13+
protected BlockingQueue resultQueue = new LinkedBlockingQueue();
1514

1615
// Scenes
17-
final static String SCENE1 = "scene1";
18-
final static String SCENE2 = "scene2";
19-
final static String SCENE3 = "emptyscene";
16+
protected final static String SCENE1 = "scene1";
17+
protected final static String SCENE2 = "scene2";
18+
protected final static String SCENE3 = "emptyscene";
2019

2120
// Sources
22-
final static String SOURCE_TEXT_SCENE1 = "scenename1";
23-
final static String SOURCE_TEXT_SCENE2 = "scenename2";
24-
final static String SOURCE_MEDIA = "media";
25-
final static String SOURCE_VLC_MEDIA = "vlc-media";
26-
final static String SOURCE_RED_SQUARE = "red_square";
27-
final static String SOURCE_RED_SQUARE_FILTER = "Color Correction";
28-
final static String SOURCE_BROWSER = "browser";
29-
final static String SOURCE_GROUP = "group";
30-
final static String SOURCE_GROUP_TEXT = "grouptext";
21+
protected final static String SOURCE_TEXT_SCENE1 = "scenename1";
22+
protected final static String SOURCE_TEXT_SCENE2 = "scenename2";
23+
protected final static String SOURCE_MEDIA = "media";
24+
protected final static String SOURCE_VLC_MEDIA = "vlc-media";
25+
protected final static String SOURCE_RED_SQUARE = "red_square";
26+
protected final static String SOURCE_RED_SQUARE_FILTER = "Color Correction";
27+
protected final static String SOURCE_BROWSER = "browser";
28+
protected final static String SOURCE_GROUP = "group";
29+
protected final static String SOURCE_GROUP_TEXT = "grouptext";
3130

3231
// Transitions and other OBS hard-coded names
33-
final static String TRANSITION_SLIDE = "Slide";
34-
final static String TRANSITION_CUT = "Cut";
35-
final static String TRANSITION_FADE = "Fade";
36-
final static String SOURCE_OBS_MIC = "Mic/Aux";
37-
final static String SOURCE_OBS_AUDIO = "Desktop Audio";
38-
39-
@BeforeAll
40-
static void beforeAll() {
41-
42-
// Connect to OBS
43-
remote = new OBSRemoteController("ws://localhost:4444", false);
44-
remote.registerConnectionFailedCallback(message -> {
45-
fail("Failed to connect to OBS: " + message);
46-
});
47-
remote.registerOnError((message, throwable) -> {
48-
fail("Failed to connect to OBS due to error: " + message);
49-
});
50-
remote.connect();
51-
52-
try {
53-
Thread.sleep(1000);
54-
} catch (InterruptedException e) {
55-
e.printStackTrace();
56-
}
57-
}
32+
protected final static String TRANSITION_SLIDE = "Slide";
33+
protected final static String TRANSITION_CUT = "Cut";
34+
protected final static String TRANSITION_FADE = "Fade";
35+
protected final static String SOURCE_OBS_MIC = "Mic/Aux";
36+
protected final static String SOURCE_OBS_AUDIO = "Desktop Audio";
5837

5938
// Test Helpers
60-
void obsShould(String expected) {
39+
protected void obsShould(String expected) {
6140
obsShould(expected, 3);
6241
}
6342

64-
void obsShould(String expected, int secondsTimeout) {
43+
protected void obsShould(String expected, int secondsTimeout) {
6544
System.out.println(">>> OBS SHOULD: " + expected);
6645
countDownFrom(secondsTimeout);
6746
}
6847

69-
void countDownFrom(int seconds) {
48+
protected void countDownFrom(int seconds) {
7049
for(int i = seconds; i > 0; i--) {
7150
System.out.println("> " + i);
7251
try {
@@ -77,7 +56,7 @@ void countDownFrom(int seconds) {
7756
}
7857
}
7958

80-
static void connectToObs() {
59+
protected static void connectToObs() {
8160
remote = new OBSRemoteController("ws://localhost:4444", false);
8261
remote.registerConnectionFailedCallback(message -> {
8362
fail("Failed to connect to OBS: " + message);
@@ -94,7 +73,7 @@ static void connectToObs() {
9473
}
9574
}
9675

97-
void setupObs() {
76+
protected void setupObs() {
9877

9978
// Cleanup all scenes
10079
cleanupScenes();
@@ -107,7 +86,7 @@ void setupObs() {
10786
});
10887
}
10988

110-
void cleanupScenes() {
89+
protected void cleanupScenes() {
11190
// Hide all visible elements in all scenes
11291
remote.getScenes(sceneListResponse -> {
11392
sceneListResponse.getScenes().forEach(scene -> {
@@ -124,28 +103,28 @@ void cleanupScenes() {
124103
});
125104
}
126105

127-
Consumer loggingCallback = (obj) -> {
106+
protected Consumer loggingCallback = (obj) -> {
128107
System.out.println("Received response: " + obj);
129108
};
130109

131-
void waitReasonably() {
110+
protected void waitReasonably() {
132111
waitReasonably(50);
133112
}
134113

135-
void waitReasonably(long ms) {
114+
protected void waitReasonably(long ms) {
136115
try {
137116
Thread.sleep(ms);
138117
} catch (InterruptedException e) {
139118
e.printStackTrace();
140119
}
141120
}
142121

143-
Consumer capturingCallback = (obj) -> {
122+
protected Consumer capturingCallback = (obj) -> {
144123
System.out.println("Received response: " + obj + "(" + obj.getClass().getSimpleName() + ")");
145124
resultQueue.add(obj);
146125
};
147126

148-
<T> T getResponseAs(Class<T> clazz) {
127+
protected <T> T getResponseAs(Class<T> clazz) {
149128
return clazz.cast(resultQueue.remove());
150129
}
151130

src/integrationTest/java/net/twasi/obsremotejava/test/OBSRemoteControllerUnsecuredIT.java

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,87 +17,6 @@ public class OBSRemoteControllerUnsecuredIT {
1717
private final String obsAddress = "ws://localhost:4444";
1818
private final String obsPassword = null;
1919

20-
@Test
21-
@Disabled
22-
void test() {
23-
final OBSRemoteController controller = new OBSRemoteController(obsAddress, false, null);
24-
25-
if (controller.isFailed()) {
26-
System.out.println("UPS DAS GET NET HÜLFEEE!");
27-
}
28-
29-
controller.registerDisconnectCallback(() -> System.out.println("Disconnected"));
30-
31-
controller.registerConnectCallback(response -> {
32-
System.out.println("Connected!");
33-
System.out.println(response.getObsStudioVersion());
34-
35-
controller.registerReplayStartedCallback(() -> System.out.println("Replay started"));
36-
37-
controller.registerReplayStartingCallback(() -> System.out.println("Replay starting"));
38-
39-
controller.registerReplayStoppedCallback(() -> System.out.println("Replay stopped"));
40-
41-
controller.registerReplayStoppingCallback(() -> System.out.println("Replay stopping"));
42-
43-
controller.startReplayBuffer(res -> System.out.println("Should start replay buffer"));
44-
45-
controller.saveReplayBuffer(res -> System.out.println("Should save replay buffer"));
46-
47-
controller.stopReplayBuffer(res -> System.out.println("Should stop replay buffer"));
48-
49-
controller.registerSwitchScenesCallback(event -> System.out.println("Switched to scene: " + event.getSceneName()));
50-
51-
controller.registerScenesChangedCallback(event -> System.out.println("Scenes changed"));
52-
53-
controller.registerSwitchTransitionCallback(event -> System.out.println("Switched active transition to: " + event.getTransitionName()));
54-
55-
controller.registerTransitionListChangedCallback(event -> System.out.println("Transition list changed"));
56-
57-
controller.registerTransitionBeginCallback(event -> System.out.println("Transition started from scene: '" + event.getFromScene() + "' to scene: '" + event.getToScene() + "'"));
58-
59-
controller.registerTransitionEndCallback(event -> System.out.println("Transition ended with scene: " + event.getToScene()));
60-
61-
controller.registerSourceFilterVisibilityChangedCallback(event -> System.out.println(String.format(
62-
"Source Filter visibility changed on filter '%s' in source '%s'", event.getFilterName(), event.getSourceName()
63-
)));
64-
65-
controller.registerPreviewSceneChangesCallback(event -> System.out.println("Preview Scene changed to: " + event.getSceneName()));
66-
67-
controller.registerStreamStartedCallback(() -> System.out.println("Stream Started"));
68-
69-
controller.registerStreamStoppedCallback(() -> System.out.println("Stream Stopped"));
70-
71-
controller.registerRecordingStartedCallback(() -> System.out.println("Recording Started"));
72-
73-
controller.registerRecordingStoppedCallback(() -> System.out.println("Recording Stopped"));
74-
75-
controller.registerOnMediaPlaying(event -> System.out.println("Media Playing source: " + event.getSourceName()));
76-
77-
controller.registerOnMediaPaused(event-> System.out.println("Media Paused source: " + event.getSourceName()));
78-
79-
controller.registerOnMediaRestarted(event-> System.out.println("Media Restarted source: " + event.getSourceName()));
80-
81-
controller.registerOnMediaStopped(event-> System.out.println("Media Stopped source: " + event.getSourceName()));
82-
83-
controller.registerOnMediaNext(event-> System.out.println("Media Next source: " + event.getSourceName()));
84-
85-
controller.registerOnMediaPrevious(event-> System.out.println("Media Previous source: " + event.getSourceName()));
86-
87-
controller.registerOnMediaStarted(event-> System.out.println("Media Started source: " + event.getSourceName()));
88-
89-
controller.registerOnMediaEnded(event-> System.out.println("Media Ended source: " + event.getSourceName()));
90-
91-
controller.registerOnSourceVolumeChanged(event-> System.out.println("Volume Changed source: " + event.getSourceName()));
92-
});
93-
94-
try {
95-
controller.await();
96-
} catch (InterruptedException e) {
97-
e.printStackTrace();
98-
}
99-
}
100-
10120
@Test
10221
void testConnectAndDisconnect() {
10322
AtomicReference<Boolean> testSuccessful = new AtomicReference<>(Boolean.FALSE);

src/integrationTest/java/net/twasi/obsremotejava/test/ObsRemoteE2eIT.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,20 @@
55

66
import java.util.ArrayList;
77
import java.util.Arrays;
8-
import java.util.HashSet;
98
import java.util.List;
10-
import java.util.Set;
11-
import java.util.concurrent.BlockingQueue;
12-
import java.util.concurrent.LinkedBlockingQueue;
13-
import java.util.function.Consumer;
149
import java.util.stream.Collectors;
15-
import net.twasi.obsremotejava.OBSRemoteController;
1610
import net.twasi.obsremotejava.objects.Scene;
1711
import net.twasi.obsremotejava.objects.Source;
1812
import net.twasi.obsremotejava.requests.GetSceneList.GetSceneListResponse;
1913
import net.twasi.obsremotejava.requests.GetSourcesList.GetSourcesListResponse;
2014
import org.junit.jupiter.api.AfterAll;
21-
import org.junit.jupiter.api.AfterEach;
2215
import org.junit.jupiter.api.BeforeAll;
2316
import org.junit.jupiter.api.BeforeEach;
2417
import org.junit.jupiter.api.Test;
2518

2619
/**
27-
* This test should be run manually, following the prompts in the command-line and
28-
* observing OBS for the desired behavior. Authentication should be disabled.
20+
* This test relies on your OBS instance having the expected scene collection installed;
21+
* See the README in the obs-resources directory for more information.
2922
*/
3023
public class ObsRemoteE2eIT extends AbstractObsE2ETest {
3124

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package net.twasi.obsremotejava.test.manual;
2+
3+
import net.twasi.obsremotejava.OBSRemoteController;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class CallbackObservationTest {
7+
8+
private final String obsAddress = "ws://localhost:4444";
9+
private final String obsPassword = null;
10+
11+
@Test
12+
void test() {
13+
final OBSRemoteController controller = new OBSRemoteController(obsAddress, false, null);
14+
15+
if (controller.isFailed()) {
16+
System.out.println("UPS DAS GET NET HÜLFEEE!");
17+
}
18+
19+
controller.registerDisconnectCallback(() -> System.out.println("Disconnected"));
20+
21+
controller.registerConnectCallback(response -> {
22+
System.out.println("Connected!");
23+
System.out.println(response.getObsStudioVersion());
24+
25+
controller.registerReplayStartedCallback(() -> System.out.println("Replay started"));
26+
27+
controller.registerReplayStartingCallback(() -> System.out.println("Replay starting"));
28+
29+
controller.registerReplayStoppedCallback(() -> System.out.println("Replay stopped"));
30+
31+
controller.registerReplayStoppingCallback(() -> System.out.println("Replay stopping"));
32+
33+
controller.startReplayBuffer(res -> System.out.println("Should start replay buffer"));
34+
35+
controller.saveReplayBuffer(res -> System.out.println("Should save replay buffer"));
36+
37+
controller.stopReplayBuffer(res -> System.out.println("Should stop replay buffer"));
38+
39+
controller.registerSwitchScenesCallback(event -> System.out.println("Switched to scene: " + event.getSceneName()));
40+
41+
controller.registerScenesChangedCallback(event -> System.out.println("Scenes changed"));
42+
43+
controller.registerSwitchTransitionCallback(event -> System.out.println("Switched active transition to: " + event.getTransitionName()));
44+
45+
controller.registerTransitionListChangedCallback(event -> System.out.println("Transition list changed"));
46+
47+
controller.registerTransitionBeginCallback(event -> System.out.println("Transition started from scene: '" + event.getFromScene() + "' to scene: '" + event.getToScene() + "'"));
48+
49+
controller.registerTransitionEndCallback(event -> System.out.println("Transition ended with scene: " + event.getToScene()));
50+
51+
controller.registerSourceFilterVisibilityChangedCallback(event -> System.out.println(String.format(
52+
"Source Filter visibility changed on filter '%s' in source '%s'", event.getFilterName(), event.getSourceName()
53+
)));
54+
55+
controller.registerPreviewSceneChangesCallback(event -> System.out.println("Preview Scene changed to: " + event.getSceneName()));
56+
57+
controller.registerStreamStartedCallback(() -> System.out.println("Stream Started"));
58+
59+
controller.registerStreamStoppedCallback(() -> System.out.println("Stream Stopped"));
60+
61+
controller.registerRecordingStartedCallback(() -> System.out.println("Recording Started"));
62+
63+
controller.registerRecordingStoppedCallback(() -> System.out.println("Recording Stopped"));
64+
65+
controller.registerOnMediaPlaying(event -> System.out.println("Media Playing source: " + event.getSourceName()));
66+
67+
controller.registerOnMediaPaused(event-> System.out.println("Media Paused source: " + event.getSourceName()));
68+
69+
controller.registerOnMediaRestarted(event-> System.out.println("Media Restarted source: " + event.getSourceName()));
70+
71+
controller.registerOnMediaStopped(event-> System.out.println("Media Stopped source: " + event.getSourceName()));
72+
73+
controller.registerOnMediaNext(event-> System.out.println("Media Next source: " + event.getSourceName()));
74+
75+
controller.registerOnMediaPrevious(event-> System.out.println("Media Previous source: " + event.getSourceName()));
76+
77+
controller.registerOnMediaStarted(event-> System.out.println("Media Started source: " + event.getSourceName()));
78+
79+
controller.registerOnMediaEnded(event-> System.out.println("Media Ended source: " + event.getSourceName()));
80+
81+
controller.registerOnSourceVolumeChanged(event-> System.out.println("Volume Changed source: " + event.getSourceName()));
82+
});
83+
84+
try {
85+
controller.await();
86+
} catch (InterruptedException e) {
87+
e.printStackTrace();
88+
}
89+
}
90+
91+
}

src/integrationTest/java/net/twasi/obsremotejava/test/OBSCommunicatorSecuredIT.java renamed to src/integrationTest/java/net/twasi/obsremotejava/test/manual/OBSCommunicatorSecuredIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.twasi.obsremotejava.test;
1+
package net.twasi.obsremotejava.test.manual;
22

33
import net.twasi.obsremotejava.OBSCommunicator;
44
import org.eclipse.jetty.websocket.api.Session;

0 commit comments

Comments
 (0)