Skip to content

Commit 4328913

Browse files
author
TinaTiel
committed
Added a bunch of manual tests (still more to do...), and added toString impl to a problematic class during some debugging. Woudl like to refactor this project eventually to use Lombok.
1 parent daec5f6 commit 4328913

File tree

7 files changed

+275
-133
lines changed

7 files changed

+275
-133
lines changed

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.E2EUnsecuredIT"
33+
gradlew :clean :integrationTest --info --tests "net.twasi.obsremotejava.test.ObsRemoteE2eIT"
3434
```
3535

3636
...And observe OBS in another.

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

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
package net.twasi.obsremotejava.test;
2+
3+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4+
import static org.junit.jupiter.api.Assertions.fail;
5+
6+
import java.io.File;
7+
import java.nio.file.Path;
8+
import java.nio.file.Paths;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import net.twasi.obsremotejava.OBSRemoteController;
13+
import net.twasi.obsremotejava.objects.Scene;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeAll;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
19+
20+
/**
21+
* This test should be run manually, following the prompts in the command-line and
22+
* observing OBS for the desired behavior. Authentication should be disabled.
23+
*/
24+
public class ObsRemoteE2eIT {
25+
26+
static OBSRemoteController remote;
27+
28+
@BeforeAll
29+
static void beforeAll() {
30+
31+
// Connect
32+
remote = new OBSRemoteController("ws://localhost:4444", false);
33+
remote.registerConnectionFailedCallback(message -> {
34+
fail("Failed to connect to OBS: " + message);
35+
});
36+
remote.registerOnError((message, throwable) -> {
37+
fail("Failed to connect to OBS due to error: " + message);
38+
});
39+
remote.connect();
40+
try {
41+
Thread.sleep(1000);
42+
} catch (InterruptedException e) {
43+
e.printStackTrace();
44+
}
45+
}
46+
47+
@BeforeEach
48+
public void beforeEach() {
49+
System.out.println("===============================");
50+
System.out.println(">> Resetting...");
51+
setupObs();
52+
System.out.println(">> ...Ready");
53+
}
54+
55+
@AfterAll
56+
static void afterAll() {
57+
remote.disconnect();
58+
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "Debug");
59+
}
60+
61+
@AfterEach
62+
public void afterEach() {
63+
try {
64+
Thread.sleep(1000);
65+
} catch (InterruptedException e) {
66+
e.printStackTrace();
67+
}
68+
System.out.println("<< Test Complete");
69+
70+
}
71+
72+
@Test
73+
void switchScene() {
74+
obsShould("Switch to scene2");
75+
remote.changeSceneWithTransition("scene2", "Cut", res -> {});
76+
}
77+
78+
@Test
79+
void showHideSceneItem() {
80+
obsShould("Show the red square");
81+
remote.setSourceVisibility(null, "red_square", true, res -> {});
82+
obsShould("Hide the red square");
83+
remote.setSourceVisibility(null, "red_square", false, res -> {});
84+
}
85+
86+
@Test
87+
void setTransition() {
88+
obsShould("Set current transition to Slide, with transition 2000ms");
89+
remote.setCurrentTransition("Slide", (res) -> {});
90+
remote.setTransitionDuration(2000, (res) -> {});
91+
obsShould("Set current transition back to 300ms");
92+
remote.setTransitionDuration(300, (res) -> {});
93+
obsShould("Set current transition back to Cut");
94+
remote.setCurrentTransition("Cut", (res) -> {});
95+
}
96+
97+
@Test
98+
void changeScenesWithTransition() {
99+
obsShould("Change to scene2, with the Slide transition");
100+
remote.changeSceneWithTransition("scene2", "Slide", (res) -> {});
101+
}
102+
103+
@Test
104+
void setSourceFilterVisibility() {
105+
106+
obsShould("Show a blue square (red square colored blue by a filter)");
107+
remote.setSourceVisibility(null, "red_square", true, (res) -> {});
108+
remote.setSourceFilterVisibility("red_square", "Color Correction", true, (res) -> {});
109+
obsShould("Return the red square to normal");
110+
remote.setSourceFilterVisibility("red_square", "Color Correction", false, (res) -> {});
111+
112+
}
113+
114+
@Test
115+
void exerciseStudioMode() {
116+
obsShould("Enable studio mode");
117+
remote.setStudioModeEnabled(true, (res) -> {});
118+
obsShould("Set preview scene to scene2");
119+
remote.setPreviewScene("scene2", (res) -> {});
120+
obsShould("Fade to scene2");
121+
remote.transitionToProgram("Fade", 1500, (res) -> {});
122+
obsShould("Disable studio mode");
123+
remote.setStudioModeEnabled(false, (res) -> {});
124+
125+
}
126+
127+
@Test
128+
void setSourceSettings() {
129+
obsShould("Curse the 'scene1' text");
130+
Map<String, Object> settings = new HashMap<>();
131+
settings.put("text", "S̼͚̞̼̩̱̽̓̍̽͊́ͨ̍̀ċͭ̚҉̪̖̤̥ͅȩ͉̣̜̖̖͙͇́̀̒ͥ̓̚͠͞n̦͍͆͑ͤ̕e̶̖̝̗̻͂̑̽̔ͩ̅́͜ͅ ̢͉̬͔͙̺̖͂͂ͣ͢1̮̥͇̏̇͋̈́ͨͥ͝ͅ");
132+
remote.setSourceSettings("scenename1", settings, (res) -> {});
133+
obsShould("Change the 'scene1' text back to normal");
134+
settings.put("text", "Scene 1");
135+
remote.setSourceSettings("scenename1", settings, (res) -> {});
136+
}
137+
138+
@Test
139+
void takeSourceScreenshot() throws Exception {
140+
String path = System.getProperty("user.home");
141+
assertThat(path).isNotNull();
142+
File file = new File(path, "test.png");
143+
String screenshotPath = file.getAbsolutePath();
144+
obsShould("Take a screenshot of the current scene, and save it to " + screenshotPath, 1);
145+
remote.takeSourceScreenshot(
146+
"scene1", "png",
147+
screenshotPath,
148+
null, 1,
149+
1080, 720,
150+
(res) -> { }
151+
);
152+
}
153+
154+
@Test
155+
void startStopStreaming() {
156+
obsShould("Start Streaming");
157+
remote.startStreaming((res) -> {});
158+
obsShould("Stop Streaming");
159+
remote.stopStreaming((res) -> {});
160+
}
161+
162+
@Test
163+
void startStopRecording() {
164+
obsShould("Start Recording");
165+
remote.startRecording((res) -> {});
166+
obsShould("Stop Recording");
167+
remote.stopRecording((res) -> {});
168+
}
169+
170+
@Test
171+
void setVolumeAndMute() {
172+
173+
obsShould("Set the volume to 50% (note, appears 67% due to log scaling; check % in advanced audio properties)");
174+
remote.setSourceVisibility(null, "media", true, (res) -> {});
175+
remote.setVolume("media", 0.50, (res) -> {});
176+
obsShould("Mute the volume");
177+
remote.setMute("media", true, (res) -> {});
178+
obsShould("Unmute the volume");
179+
remote.setMute("media", false, (res) -> {});
180+
obsShould("Set the volume to 100%");
181+
remote.setVolume("media", 1.00, (res) -> {});
182+
183+
}
184+
185+
// Private Test Helpers
186+
private void obsShould(String expected) {
187+
obsShould(expected, 3);
188+
}
189+
190+
private void obsShould(String expected, int secondsTimeout) {
191+
System.out.println(">>> OBS SHOULD: " + expected);
192+
countDownFrom(secondsTimeout);
193+
}
194+
195+
private void countDownFrom(int seconds) {
196+
for(int i = seconds; i > 0; i--) {
197+
System.out.println("> " + i);
198+
try {
199+
Thread.sleep(1000);
200+
} catch (InterruptedException e) {
201+
e.printStackTrace();
202+
}
203+
}
204+
}
205+
206+
private void setupObs() {
207+
208+
// Cleanup all scenes
209+
cleanupScenes();
210+
211+
// Change back to base scene
212+
remote.changeSceneWithTransition("scene1", "Cut", result -> {
213+
if(result.getError() != null && !result.getError().isEmpty()) {
214+
fail("Failed to switch to base scene");
215+
}
216+
});
217+
}
218+
219+
private void cleanupScenes() {
220+
// Hide all visible elements in all scenes
221+
remote.getScenes(sceneListResponse -> {
222+
sceneListResponse.getScenes().forEach(scene -> {
223+
scene.getSources().forEach(source -> {
224+
if(!source.getName().startsWith("scenename")) {
225+
remote.setSourceVisibility(scene.getName(), source.getName(), false, result -> {
226+
if(result.getError() != null && !result.getError().isEmpty()) {
227+
fail(String.format("Failed to hide source '%s' on scene '%s'", source.getName(), scene.getName()));
228+
}
229+
});
230+
}
231+
});
232+
});
233+
});
234+
}
235+
236+
}

0 commit comments

Comments
 (0)