1
1
package io .obswebsocket .community .client .test ;
2
2
3
- import static org .assertj .core .api .Assertions .assertThat ;
3
+ import static org .assertj .core .api .Assertions .fail ;
4
4
5
5
import io .obswebsocket .community .client .OBSRemoteController ;
6
- import java .util .concurrent .BlockingQueue ;
7
- import java .util .concurrent .LinkedBlockingQueue ;
8
6
import java .util .function .Consumer ;
9
7
10
8
public abstract class AbstractObsE2ETest {
11
9
12
10
protected static OBSRemoteController remote ;
13
- protected BlockingQueue resultQueue = new LinkedBlockingQueue ();
14
11
15
12
// Scenes
16
13
protected final static String SCENE1 = "scene1" ;
@@ -32,8 +29,6 @@ public abstract class AbstractObsE2ETest {
32
29
protected final static String TRANSITION_SLIDE = "Slide" ;
33
30
protected final static String TRANSITION_CUT = "Cut" ;
34
31
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" ;
37
32
38
33
// Test Helpers
39
34
protected void obsShould (String expected ) {
@@ -59,19 +54,10 @@ protected void countDownFrom(int seconds) {
59
54
protected static void connectToObs () {
60
55
remote = OBSRemoteController .builder ()
61
56
.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 ))
66
59
.and ()
67
60
.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
- // });
75
61
remote .connect ();
76
62
77
63
try {
@@ -87,55 +73,34 @@ protected void setupObs() {
87
73
cleanupScenes ();
88
74
89
75
// 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
+ });
95
81
}
96
82
97
83
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
+ });
128
101
}
129
102
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 );
139
105
}
140
-
141
106
}
0 commit comments