3
3
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
4
4
import static org .junit .jupiter .api .Assertions .fail ;
5
5
6
- import java .io .File ;
7
- import java .util .HashMap ;
8
- import java .util .Map ;
6
+ import java .util .ArrayList ;
7
+ import java .util .Arrays ;
8
+ import java .util .HashSet ;
9
+ import java .util .List ;
10
+ import java .util .Set ;
9
11
import java .util .concurrent .BlockingQueue ;
10
12
import java .util .concurrent .LinkedBlockingQueue ;
11
13
import java .util .function .Consumer ;
14
+ import java .util .stream .Collectors ;
12
15
import net .twasi .obsremotejava .OBSRemoteController ;
13
16
import net .twasi .obsremotejava .objects .Scene ;
17
+ import net .twasi .obsremotejava .objects .Source ;
14
18
import net .twasi .obsremotejava .requests .GetSceneList .GetSceneListResponse ;
19
+ import net .twasi .obsremotejava .requests .GetSourcesList .GetSourcesListResponse ;
15
20
import org .junit .jupiter .api .AfterAll ;
16
21
import org .junit .jupiter .api .AfterEach ;
17
22
import org .junit .jupiter .api .BeforeAll ;
22
27
* This test should be run manually, following the prompts in the command-line and
23
28
* observing OBS for the desired behavior. Authentication should be disabled.
24
29
*/
25
- public class ObsRemoteE2eIT {
26
-
27
- static OBSRemoteController remote ;
28
-
29
- BlockingQueue resultQueue = new LinkedBlockingQueue ();
30
+ public class ObsRemoteE2eIT extends AbstractObsE2ETest {
30
31
31
32
@ BeforeAll
32
33
static void beforeAll () {
33
-
34
- // Connect
35
- remote = new OBSRemoteController ("ws://localhost:4444" , false );
36
- remote .registerConnectionFailedCallback (message -> {
37
- fail ("Failed to connect to OBS: " + message );
38
- });
39
- remote .registerOnError ((message , throwable ) -> {
40
- fail ("Failed to connect to OBS due to error: " + message );
41
- });
42
- remote .connect ();
43
- try {
44
- Thread .sleep (1000 );
45
- } catch (InterruptedException e ) {
46
- e .printStackTrace ();
47
- }
34
+ connectToObs ();
48
35
}
49
36
50
37
@ BeforeEach
51
38
public void beforeEach () {
52
- System .out .println ("===============================" );
53
- System .out .println (">> Resetting..." );
54
39
setupObs ();
55
40
resultQueue .clear ();
56
- System .out .println (">> ...Ready" );
57
41
}
58
42
59
43
@ AfterAll
@@ -62,83 +46,76 @@ static void afterAll() {
62
46
System .setProperty (org .slf4j .impl .SimpleLogger .DEFAULT_LOG_LEVEL_KEY , "Debug" );
63
47
}
64
48
65
- @ AfterEach
66
- public void afterEach () {
67
- try {
68
- Thread .sleep (1000 );
69
- } catch (InterruptedException e ) {
70
- e .printStackTrace ();
71
- }
72
- System .out .println ("<< Test Complete" );
73
-
74
- }
75
-
76
49
@ Test
77
50
void getScenes () {
78
51
79
- remote .getScenes (capturingConsumer );
80
-
81
- waitMs (50 );
82
-
52
+ // Given expected scenes and sources
53
+ List <String > scenes = Arrays .asList (SCENE1 , SCENE2 , SCENE3 );
54
+ List <String > scene1Sources = Arrays .asList (
55
+ SOURCE_TEXT_SCENE1 ,
56
+ SOURCE_RED_SQUARE ,
57
+ SOURCE_MEDIA ,
58
+ SOURCE_VLC_MEDIA ,
59
+ SOURCE_BROWSER ,
60
+ SOURCE_GROUP
61
+ );
62
+ List <String > scene1SourcesWithChildren = new ArrayList <>(scene1Sources );
63
+ scene1SourcesWithChildren .add (SOURCE_GROUP_TEXT );
64
+ List <String > scene2Sources = Arrays .asList (SOURCE_TEXT_SCENE2 );
65
+
66
+ // When retrieved
67
+ remote .getScenes (capturingCallback );
68
+ waitReasonably ();
69
+
70
+ // Then scenes match as expected
83
71
GetSceneListResponse res = getResponseAs (GetSceneListResponse .class );
84
- assertThat (res .getScenes ().size ()).isEqualTo (3 );
72
+ assertThat (res .getScenes ().stream ().map (Scene ::getName ).collect (Collectors .toList ()))
73
+ .usingRecursiveComparison ().ignoringCollectionOrder ().isEqualTo (scenes );
85
74
75
+ // And their sources match as expected
86
76
Scene scene1 = res .getScenes ().get (0 );
87
- assertThat (scene1 .getSources ().size ()).isEqualTo (6 );
88
- assertThat (scene1 .getSourcesIncludingGroupChildren ().size ()).isEqualTo (7 );
77
+ assertThat (scene1 .getSources ().stream ().map (Source ::getName ).collect (Collectors .toList ()))
78
+ .usingRecursiveComparison ().ignoringCollectionOrder ().isEqualTo (scene1Sources );
79
+ assertThat (scene1 .getSourcesIncludingGroupChildren ().stream ().map (Source ::getName ).collect (Collectors .toList ()))
80
+ .usingRecursiveComparison ().ignoringCollectionOrder ().isEqualTo (scene1SourcesWithChildren );
81
+
82
+ Scene scene2 = res .getScenes ().get (1 );
83
+ assertThat (scene2 .getSources ().stream ().map (Source ::getName ).collect (Collectors .toList ()))
84
+ .usingRecursiveComparison ().ignoringCollectionOrder ().isEqualTo (scene2Sources );
89
85
90
86
Scene emptyScene = res .getScenes ().get (2 );
91
87
assertThat (emptyScene .getSources ().size ()).isZero ();
92
88
93
89
}
94
90
95
- // Private Test Helpers
96
-
97
- private void setupObs () {
98
-
99
- // Cleanup all scenes
100
- cleanupScenes ();
101
-
102
- // Change back to base scene
103
- remote .changeSceneWithTransition ("scene1" , "Cut" , result -> {
104
- if (result .getError () != null && !result .getError ().isEmpty ()) {
105
- fail ("Failed to switch to base scene" );
106
- }
107
- });
108
- }
109
-
110
- private void cleanupScenes () {
111
- // Hide all visible elements in all scenes
112
- remote .getScenes (sceneListResponse -> {
113
- sceneListResponse .getScenes ().forEach (scene -> {
114
- scene .getSources ().forEach (source -> {
115
- if (!source .getName ().startsWith ("scenename" )) {
116
- remote .setSourceVisibility (scene .getName (), source .getName (), false , result -> {
117
- if (result .getError () != null && !result .getError ().isEmpty ()) {
118
- fail (String .format ("Failed to hide source '%s' on scene '%s'" , source .getName (), scene .getName ()));
119
- }
120
- });
121
- }
122
- });
123
- });
124
- });
125
- }
126
-
127
- void waitMs (long ms ) {
128
- try {
129
- Thread .sleep (ms );
130
- } catch (InterruptedException e ) {
131
- e .printStackTrace ();
132
- }
133
- }
134
-
135
- Consumer capturingConsumer = (obj ) -> {
136
- System .out .println ("Received response: " + obj + "(" + obj .getClass ().getSimpleName () + ")" );
137
- resultQueue .add (obj );
138
- };
91
+ @ Test
92
+ void getSourcesList () {
93
+
94
+ // Given expected sources (all custom sources + mic and desktop audio default obs sources)
95
+ List <String > expectedNames = Arrays .asList (
96
+ SOURCE_TEXT_SCENE1 ,
97
+ SOURCE_TEXT_SCENE2 ,
98
+ SOURCE_RED_SQUARE ,
99
+ SOURCE_MEDIA ,
100
+ SOURCE_VLC_MEDIA ,
101
+ SOURCE_BROWSER ,
102
+ SOURCE_GROUP ,
103
+ SOURCE_GROUP_TEXT ,
104
+ "Mic/Aux" ,
105
+ "Desktop Audio"
106
+ );
107
+
108
+ // When retrieved
109
+ remote .getSourcesList (capturingCallback );
110
+ waitReasonably ();
111
+
112
+ // Then it matches as expected
113
+ GetSourcesListResponse res = getResponseAs (GetSourcesListResponse .class );
114
+ List <Source > sources = res .getSources ();
115
+ List <String > actualNames = sources .stream ().map (Source ::getName ).collect (Collectors .toList ());
116
+ assertThat (actualNames .size ()).isEqualTo (sources .size ());
117
+ assertThat (actualNames ).usingRecursiveComparison ().ignoringCollectionOrder ().isEqualTo (expectedNames );
139
118
140
- <T > T getResponseAs (Class <T > clazz ) {
141
- return clazz .cast (resultQueue .remove ());
142
119
}
143
120
144
121
}
0 commit comments