Skip to content

Commit e047643

Browse files
Reviewed integration tests, found a few failures and walked back some code changes I'd made in a prior commit. All tests pass now.
1 parent 603296b commit e047643

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/main/java/net/twasi/obsremotejava/OBSCommunicator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void await() throws InterruptedException {
149149
@OnWebSocketError
150150
public void onError(Session session, Throwable throwable) {
151151
// do nothing for now, this should at least repress "OnWebsocketError not registered" messages
152-
//runOnError("Websocket error occurred with session " + session, throwable);
152+
runOnConnectionFailed("Websocket error occurred with session " + session, throwable);
153153
}
154154

155155
@OnWebSocketClose
@@ -159,7 +159,7 @@ public void onClose(int statusCode, String reason) {
159159
try {
160160
this.onDisconnect.run(null);
161161
} catch (Throwable t) {
162-
runOnError("Could not close websocket connection", t);
162+
log.error("Unable to disconnect OBS Client", t);
163163
}
164164
}
165165

@@ -245,7 +245,7 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
245245
if ("ok".equals(authenticateResponse.getStatus())) {
246246
runOnConnect(versionInfo);
247247
} else {
248-
runOnConnectionFailed("Failed to authenticate with password. Error: " + authenticateResponse.getError());
248+
runOnConnectionFailed("Failed to authenticate with password. Error: " + authenticateResponse.getError(), null);
249249
}
250250

251251
break;
@@ -323,7 +323,7 @@ private void processIncomingEvent(String msg, EventType eventType) {
323323

324324
private void authenticateWithServer(String challenge, String salt) {
325325
if (password == null) {
326-
runOnConnectionFailed("Authentication required by server but no password set by client");
326+
runOnConnectionFailed("Authentication required by server but no password set by client", null);
327327
return;
328328
}
329329

@@ -344,7 +344,7 @@ private String generateAuthenticationResponseString(String challenge, String sal
344344
try {
345345
digest = MessageDigest.getInstance("SHA-256");
346346
} catch (NoSuchAlgorithmException e) {
347-
runOnConnectionFailed("Failed to perform password authentication with server");
347+
runOnConnectionFailed("Failed to perform password authentication with server", null);
348348
return null;
349349
}
350350

@@ -648,7 +648,7 @@ private void runOnError(String message, Throwable throwable) {
648648
}
649649
}
650650

651-
private void runOnConnectionFailed(String message) {
651+
private void runOnConnectionFailed(String message, Throwable throwable) {
652652
log.debug("Running onConnectionFailed, with message: " + message);
653653
if (onConnectionFailed == null) {
654654
log.debug("No onConnectionFailed callback was registered");

src/test/java/net/twasi/obsremotejava/test/OBSRemoteControllerIT.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class OBSRemoteControllerIT {
1919

2020
/**
21-
* - Set these two values before running these tests
21+
* - Setup OBS with the below address, and disable authentication
2222
* - Make sure your OBS is running and available for connection
2323
*/
2424
private final String obsAddress = "ws://localhost:4444";
@@ -324,50 +324,72 @@ void testConnectAndDisconnect() {
324324
}
325325

326326
@Test
327-
void testConnectWithNoCallbacksRegistered() {
327+
void disconnectShouldNotHaveErrorsWhenNoConnectDisconnectCallbacksRegistered() {
328328
AtomicReference<String> testFailedReason = new AtomicReference<>();
329329

330+
// Given a controller that auto-connects...When connected
330331
final OBSRemoteController controller = new OBSRemoteController(obsAddress, true,
331332
obsPassword, true);
332333

334+
// Then no errors should have occurred
333335
if (controller.isFailed()) {
334336
fail("Failed to connect to websocket");
335337
}
336338

339+
// And given no callbacks registered for connect/disconnect
337340
controller.registerDisconnectCallback(null);
338341
controller.registerConnectCallback(null);
339-
controller.registerConnectionFailedCallback(message -> testFailedReason.set("ConnectionFailedCallback called unexpectedly"));
340-
controller.registerOnError((message, throwable) -> testFailedReason.set("OnError called unexpectedly"));
341342

343+
// And given on connection failure and on error callbacks are set
344+
controller.registerConnectionFailedCallback(message ->
345+
testFailedReason.set("ConnectionFailedCallback called unexpectedly")
346+
);
347+
controller.registerOnError((message, throwable) ->
348+
testFailedReason.set("OnError called unexpectedly")
349+
);
350+
351+
// When disconnected
342352
controller.disconnect();
343353

354+
// Then the error or connection failure callbacks should not have been called
344355
if (testFailedReason.get() != null) {
345356
fail(testFailedReason.get());
346357
}
347358
}
348359

349360
@Test
350-
void testConnectWithInvalidCallbacksRegistered() {
361+
void disconnectShouldNotHaveErrorsWhenConnectDisconnectCallbacksThrowErrors() {
351362
AtomicReference<String> testFailedReason = new AtomicReference<>();
352363

364+
// Given controller that auto-connects...When connected
353365
final OBSRemoteController controller = new OBSRemoteController(obsAddress, true,
354366
obsPassword, true);
355367

368+
// Then no failure was expected on connection
356369
if (controller.isFailed()) {
357370
fail("Failed to connect to websocket");
358371
}
359372

373+
// And given (invalid) connect and disconnect callbacks are registered
360374
controller.registerDisconnectCallback(response -> {
361375
throw new Error("Disconnect callback error");
362376
});
363377
controller.registerConnectCallback(response -> {
364378
throw new Error("Connect callback error");
365379
});
366-
controller.registerConnectionFailedCallback(message -> testFailedReason.set("ConnectionFailedCallback called unexpectedly"));
367-
controller.registerOnError((message, throwable) -> testFailedReason.set("OnError called unexpectedly"));
368380

381+
// And given on connection failure and on error callbacks are set
382+
controller.registerConnectionFailedCallback(message ->
383+
testFailedReason.set("ConnectionFailedCallback called unexpectedly")
384+
);
385+
controller.registerOnError((message, throwable) ->
386+
testFailedReason.set("OnError called unexpectedly")
387+
);
388+
389+
// When the controller is disconnected
369390
controller.disconnect();
370391

392+
// Then the connection failure and error callbacks should NOT have been called
371393
if (testFailedReason.get() != null) {
372394
fail(testFailedReason.get());
373395
}

src/test/resources/simplelogger.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ org.eclipse.jetty.LEVEL=OFF
44

55
# Default levels for the project
66
org.slf4j.simpleLogger.defaultLogLevel=info
7-
org.slf4j.simpleLogger.log.net.twasi.obsremotejava=off
7+
org.slf4j.simpleLogger.log.net.twasi.obsremotejava=debuggi

0 commit comments

Comments
 (0)