Skip to content

Commit 75641fc

Browse files
authored
Fix/e2e tests (#143)
* core: allow blocking calls, events/responses have no @nonnull fields, fix Scene definition * core: fix testcases * core: include getters in response/event classes * example: update to show blocking calls & convenience getters * core: re-generate messages * fix: expected scene type was incorrect * fix: don't add multiple onControllerError handlers * fix: cleanup after test * core: describe what happens when the timeout occurs * test: fix vlc todo * test: fix other todo's
1 parent b88ac1b commit 75641fc

File tree

136 files changed

+4675
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+4675
-697
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto eol=lf
1+
* text=auto eol=lf encoding=utf-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package io.obswebsocket.community.client.test;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
3+
import static org.assertj.core.api.Assertions.fail;
44

55
import io.obswebsocket.community.client.OBSRemoteController;
6-
import java.util.concurrent.BlockingQueue;
7-
import java.util.concurrent.LinkedBlockingQueue;
86
import java.util.function.Consumer;
97

108
public abstract class AbstractObsE2ETest {
119

1210
protected static OBSRemoteController remote;
13-
protected BlockingQueue resultQueue = new LinkedBlockingQueue();
1411

1512
// Scenes
1613
protected final static String SCENE1 = "scene1";
@@ -32,8 +29,6 @@ public abstract class AbstractObsE2ETest {
3229
protected final static String TRANSITION_SLIDE = "Slide";
3330
protected final static String TRANSITION_CUT = "Cut";
3431
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";
3732

3833
// Test Helpers
3934
protected void obsShould(String expected) {
@@ -59,19 +54,10 @@ protected void countDownFrom(int seconds) {
5954
protected static void connectToObs() {
6055
remote = OBSRemoteController.builder()
6156
.lifecycle()
62-
.onControllerError(((reasonThrowable) -> {
63-
System.out.println("An error occurred: " + reasonThrowable.getReason());
64-
reasonThrowable.getThrowable().printStackTrace();
65-
}))
57+
.onControllerError(((reasonThrowable) -> fail("An error occurred: " + reasonThrowable.getReason(), reasonThrowable)))
58+
.onCommunicatorError(e -> fail("Unable to connect", e))
6659
.and()
6760
.build();
68-
// remote = new OBSRemoteController("ws://localhost:4455", false);
69-
// remote.registerConnectionFailedCallback(message -> {
70-
// fail("Failed to connect to OBS: " + message);
71-
// });
72-
// remote.registerOnError((message, throwable) -> {
73-
// fail("Failed to connect to OBS due to error: " + message);
74-
// });
7561
remote.connect();
7662

7763
try {
@@ -87,55 +73,34 @@ protected void setupObs() {
8773
cleanupScenes();
8874

8975
// Change back to base scene
90-
// remote.changeSceneWithTransition("scene1", "Cut", result -> {
91-
// if(result.getError() != null && !result.getError().isEmpty()) {
92-
// fail("Failed to switch to base scene");
93-
// }
94-
// });
76+
remote.setCurrentProgramScene("scene1", result -> {
77+
if (!result.isSuccessful()) {
78+
fail("Failed to switch to base scene");
79+
}
80+
});
9581
}
9682

9783
protected void cleanupScenes() {
98-
// // Hide all visible elements in all scenes
99-
// remote.getSceneList(sceneListResponse -> {
100-
// sceneListResponse.getScenes().forEach(scene -> {
101-
// scene.getSources().forEach(source -> {
102-
// if(!source.getName().startsWith("scenename")) {
103-
// remote.setSourceVisibility(scene.getName(), source.getName(), false, result -> {
104-
// if(result.getError() != null && !result.getError().isEmpty()) {
105-
// fail(String.format("Failed to hide source '%s' on scene '%s'", source.getName(), scene.getName()));
106-
// }
107-
// });
108-
// }
109-
// });
110-
// });
111-
// });
112-
}
113-
114-
protected Consumer loggingCallback = (obj) -> {
115-
System.out.println("Received response: " + obj);
116-
};
117-
118-
protected void waitReasonably() {
119-
waitReasonably(500);
120-
}
121-
122-
protected void waitReasonably(long ms) {
123-
try {
124-
Thread.sleep(ms);
125-
} catch (InterruptedException e) {
126-
e.printStackTrace();
127-
}
84+
// Hide all visible elements in all scenes
85+
remote.getSceneList(sceneListResponse -> {
86+
sceneListResponse.getScenes().forEach(scene -> {
87+
remote.getSceneItemList(scene.getSceneName(), getSceneItemListResponse -> {
88+
getSceneItemListResponse.getSceneItems().forEach(sceneItem -> {
89+
if (!sceneItem.getSourceName().startsWith("scenename")) {
90+
remote.setSceneItemEnabled(scene.getSceneName(), sceneItem.getSceneItemId(), false, result -> {
91+
if (!result.isSuccessful()) {
92+
fail(String.format("Failed to hide sceneItem '%s' on scene '%s'", sceneItem.getSourceName(),
93+
scene.getSceneName()));
94+
}
95+
});
96+
}
97+
});
98+
});
99+
});
100+
});
128101
}
129102

130-
protected Consumer capturingCallback = (obj) -> {
131-
System.out.println("Received response: " + obj + "(" + obj.getClass().getSimpleName() + ")");
132-
resultQueue.add(obj);
133-
};
134-
135-
protected <T> T getPreviousResponseAs(Class<T> clazz) {
136-
Object previousResponse = resultQueue.remove();
137-
assertThat(previousResponse).isInstanceOf(clazz);
138-
return clazz.cast(previousResponse);
103+
protected <T> Consumer<T> loggingCallback() {
104+
return obj -> System.out.println("Received response: " + obj);
139105
}
140-
141106
}

client/src/endToEndManualTest/java/io/obswebsocket/community/client/test/ObsRemoteE2eIT.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ static void beforeAll() {
2727
@BeforeEach
2828
public void beforeEach() {
2929
setupObs();
30-
resultQueue.clear();
3130
}
3231

3332
@AfterAll
@@ -49,14 +48,9 @@ void getScenes() {
4948
.currentProgramSceneName(SCENE1).scenes(expectedScenes).build();
5049

5150
// When retrieved
52-
remote.getSceneList(capturingCallback);
53-
waitReasonably();
54-
55-
// Then scenes match as expected
56-
GetSceneListResponse res = getPreviousResponseAs(GetSceneListResponse.class);
51+
GetSceneListResponse res = remote.getSceneList(1000);
5752
assertThat(res.getMessageData().getResponseData())
5853
.usingRecursiveComparison().ignoringCollectionOrder().isEqualTo(expectedResponseData);
59-
6054
}
6155

6256
@Disabled
@@ -80,7 +74,6 @@ void getSourcesList() {
8074
// When retrieved
8175
// remote.getSourcesList(capturingCallback);
8276
fail("getSourcesList not implemented");
83-
waitReasonably();
8477

8578
// Then it matches as expected
8679
// GetSourcesListResponse res = getPreviousResponseAs(GetSourcesListResponse.class);

0 commit comments

Comments
 (0)