Skip to content

Commit 4d52619

Browse files
Some final reorganizing of ITs, they're now a bit easier to run due to the auth/no-auth requirement being segregated into separate test classes. Finally closes #6
1 parent e047643 commit 4d52619

File tree

3 files changed

+86
-47
lines changed

3 files changed

+86
-47
lines changed

src/test/java/net/twasi/obsremotejava/test/OBSCommunicatorIT.java renamed to src/test/java/net/twasi/obsremotejava/test/OBSCommunicatorSecuredIT.java

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Read comment instructions before each test
1818
*/
19-
class OBSCommunicatorIT {
19+
class OBSCommunicatorSecuredIT {
2020

2121
/**
2222
* - Set these two values before running these tests
@@ -25,58 +25,14 @@ class OBSCommunicatorIT {
2525
private final String obsAddress = "ws://localhost:4444";
2626
private final String obsPassword = "password";
2727

28-
/**
29-
* Before running this test:
30-
* - Start OBS locally
31-
* - Disable websocket authentication
32-
* - Run test
33-
*/
34-
@Test
35-
void testConnectToUnsecureServerWithoutPassword() throws Exception {
36-
WebSocketClient client = new WebSocketClient();
37-
OBSCommunicator connector = new OBSCommunicator(true);
38-
39-
AtomicReference<String> testFailedReason = new AtomicReference<>();
40-
41-
try {
42-
client.start();
43-
44-
URI echoUri = new URI(obsAddress);
45-
ClientUpgradeRequest request = new ClientUpgradeRequest();
46-
client.connect(connector, echoUri, request);
47-
System.out.printf("Connecting to : %s%n", echoUri);
48-
49-
connector.registerOnDisconnect(response -> System.out.println("Disconnected"));
50-
51-
connector.registerOnConnect(response -> {
52-
System.out.println("Connected successfully without password!");
53-
closeConnectionAndStopClient(client, connector);
54-
});
55-
56-
connector.registerOnConnectionFailed(message -> {
57-
testFailedReason.set("Connection failed:" + message);
58-
closeConnectionAndStopClient(client, connector);
59-
});
60-
61-
connector.await();
62-
63-
} finally {
64-
closeConnectionAndStopClient(client, connector);
65-
}
66-
67-
if (testFailedReason.get() != null) {
68-
fail(testFailedReason.get());
69-
}
70-
}
71-
7228
/**
7329
* Before running this test:
7430
* - Start OBS locally
7531
* - Enable websocket authentication
7632
* - Run test
7733
*/
7834
@Test
79-
void testConnectToSecuredServerWithoutPassword() throws Exception {
35+
void testConnectToSecuredServerWithoutPasswordInvokesConnectionFailedCallback() throws Exception {
8036
String websocketPassword = null;
8137

8238
WebSocketClient client = new WebSocketClient();
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package net.twasi.obsremotejava.test;
2+
3+
import net.twasi.obsremotejava.OBSCommunicator;
4+
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
5+
import org.eclipse.jetty.websocket.client.WebSocketClient;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.net.URI;
9+
import java.util.concurrent.TimeUnit;
10+
import java.util.concurrent.atomic.AtomicReference;
11+
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
14+
public class OBSCommunicatorUnsecuredIT {
15+
/**
16+
* - Set these two values before running these tests
17+
* - Make sure your OBS is running and available for connection
18+
*/
19+
private final String obsAddress = "ws://localhost:4444";
20+
21+
/**
22+
* Before running this test:
23+
* - Start OBS locally
24+
* - Disable websocket authentication
25+
* - Run test
26+
*/
27+
@Test
28+
void testConnectToUnsecureServerWithoutPassword() throws Exception {
29+
WebSocketClient client = new WebSocketClient();
30+
OBSCommunicator connector = new OBSCommunicator(true);
31+
32+
AtomicReference<String> testFailedReason = new AtomicReference<>();
33+
34+
try {
35+
client.start();
36+
37+
URI echoUri = new URI(obsAddress);
38+
ClientUpgradeRequest request = new ClientUpgradeRequest();
39+
client.connect(connector, echoUri, request);
40+
System.out.printf("Connecting to : %s%n", echoUri);
41+
42+
connector.registerOnDisconnect(response -> System.out.println("Disconnected"));
43+
44+
connector.registerOnConnect(response -> {
45+
System.out.println("Connected successfully without password!");
46+
closeConnectionAndStopClient(client, connector);
47+
});
48+
49+
connector.registerOnConnectionFailed(message -> {
50+
testFailedReason.set("Connection failed:" + message);
51+
closeConnectionAndStopClient(client, connector);
52+
});
53+
54+
connector.await();
55+
56+
} finally {
57+
closeConnectionAndStopClient(client, connector);
58+
}
59+
60+
if (testFailedReason.get() != null) {
61+
fail(testFailedReason.get());
62+
}
63+
}
64+
65+
private void closeConnectionAndStopClient(WebSocketClient client, OBSCommunicator connector) {
66+
// wait for closed socket connection
67+
try {
68+
System.out.println("Closing connection");
69+
connector.awaitClose(1, TimeUnit.SECONDS);
70+
} catch (InterruptedException e) {
71+
e.printStackTrace();
72+
}
73+
74+
if (!client.isStopped() && !client.isStopping()) {
75+
try {
76+
System.out.println("Stopping client");
77+
client.stop();
78+
} catch (Exception e) {
79+
e.printStackTrace();
80+
}
81+
}
82+
}
83+
}

src/test/java/net/twasi/obsremotejava/test/OBSRemoteControllerIT.java renamed to src/test/java/net/twasi/obsremotejava/test/OBSRemoteControllerUnsecuredIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import static org.junit.jupiter.api.Assertions.fail;
1717

18-
public class OBSRemoteControllerIT {
18+
public class OBSRemoteControllerUnsecuredIT {
1919

2020
/**
2121
* - Setup OBS with the below address, and disable authentication

0 commit comments

Comments
 (0)