openvidu-server: update unit and integration tests to new JUnit version

pull/772/head
pabloFuente 2022-11-27 17:26:20 +01:00
parent 13f404d072
commit fe2f668d58
5 changed files with 170 additions and 245 deletions

View File

@ -20,7 +20,7 @@ package io.openvidu.server.test.integration;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -75,18 +75,18 @@ public class SessionGarbageCollectorIntegrationTest {
getSession(); getSession();
jsonResponse = listSessions(); jsonResponse = listSessions();
Assert.assertEquals("Wrong number of sessions", 1, jsonResponse.get("numberOfElements").getAsInt()); Assertions.assertEquals(1, jsonResponse.get("numberOfElements").getAsInt(), "Wrong number of sessions");
Thread.sleep(2000); Thread.sleep(2000);
jsonResponse = listSessions(); jsonResponse = listSessions();
Assert.assertEquals("Wrong number of sessions", 0, jsonResponse.get("numberOfElements").getAsInt()); Assertions.assertEquals(0, jsonResponse.get("numberOfElements").getAsInt(), "Wrong number of sessions");
getSession(); getSession();
getSession(); getSession();
Session session = getSession(); Session session = getSession();
jsonResponse = listSessions(); jsonResponse = listSessions();
Assert.assertEquals("Wrong number of sessions", 3, jsonResponse.get("numberOfElements").getAsInt()); Assertions.assertEquals(3, jsonResponse.get("numberOfElements").getAsInt(), "Wrong number of sessions");
String token = getToken(session); String token = getToken(session);
joinParticipant(session, token); joinParticipant(session, token);
@ -94,7 +94,7 @@ public class SessionGarbageCollectorIntegrationTest {
Thread.sleep(2000); Thread.sleep(2000);
jsonResponse = listSessions(); jsonResponse = listSessions();
Assert.assertEquals("Wrong number of sessions", 1, jsonResponse.get("numberOfElements").getAsInt()); Assertions.assertEquals(1, jsonResponse.get("numberOfElements").getAsInt(), "Wrong number of sessions");
} }
private Session getSession() { private Session getSession() {

View File

@ -23,7 +23,7 @@ import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -93,7 +93,7 @@ public class WebhookIntegrationTest {
try { try {
this.webhook = Whitebox.getInternalState(cdrLoggerWebhook, "webhookSender"); this.webhook = Whitebox.getInternalState(cdrLoggerWebhook, "webhookSender");
} catch (Exception e) { } catch (Exception e) {
Assert.fail("Error getting private property from stubbed object: " + e.getMessage()); Assertions.fail("Error getting private property from stubbed object: " + e.getMessage());
} }
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
@ -109,7 +109,7 @@ public class WebhookIntegrationTest {
try { try {
httpClient = Whitebox.getInternalState(webhook, "httpClient"); httpClient = Whitebox.getInternalState(webhook, "httpClient");
} catch (Exception e) { } catch (Exception e) {
Assert.fail("Error getting private property from stubbed object: " + e.getMessage()); Assertions.fail("Error getting private property from stubbed object: " + e.getMessage());
} }
httpClient = PowerMockito.spy(httpClient); httpClient = PowerMockito.spy(httpClient);
doAnswer(invocationOnMock -> { doAnswer(invocationOnMock -> {
@ -133,7 +133,7 @@ public class WebhookIntegrationTest {
try { try {
if (!initLatch.await(30, TimeUnit.SECONDS)) { if (!initLatch.await(30, TimeUnit.SECONDS)) {
Assert.fail("Timeout waiting for webhook springboot app to start"); Assertions.fail("Timeout waiting for webhook springboot app to start");
CustomWebhook.shutDown(); CustomWebhook.shutDown();
return; return;
} }
@ -206,11 +206,11 @@ public class WebhookIntegrationTest {
JsonObject signal5 = CustomWebhook.waitForEvent("signalSent", 25, TimeUnit.MILLISECONDS); JsonObject signal5 = CustomWebhook.waitForEvent("signalSent", 25, TimeUnit.MILLISECONDS);
// Order of webhook events should be honored // Order of webhook events should be honored
Assert.assertEquals("Wrong signal type", "1", signal1.get("type").getAsString()); Assertions.assertEquals("1", signal1.get("type").getAsString(), "Wrong signal type");
Assert.assertEquals("Wrong signal type", "2", signal2.get("type").getAsString()); Assertions.assertEquals("2", signal2.get("type").getAsString(), "Wrong signal type");
Assert.assertEquals("Wrong signal type", "3", signal3.get("type").getAsString()); Assertions.assertEquals("3", signal3.get("type").getAsString(), "Wrong signal type");
Assert.assertEquals("Wrong signal type", "4", signal4.get("type").getAsString()); Assertions.assertEquals("4", signal4.get("type").getAsString(), "Wrong signal type");
Assert.assertEquals("Wrong signal type", "5", signal5.get("type").getAsString()); Assertions.assertEquals("5", signal5.get("type").getAsString(), "Wrong signal type");
this.sessionRestController.closeConnection(sessionId, participant.getParticipantPublicId()); this.sessionRestController.closeConnection(sessionId, participant.getParticipantPublicId());

View File

@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.kurento.client.Continuation; import org.kurento.client.Continuation;
import org.kurento.client.KurentoClient; import org.kurento.client.KurentoClient;
import org.kurento.client.MediaPipeline; import org.kurento.client.MediaPipeline;
@ -46,7 +46,7 @@ public class IntegrationTestConfiguration {
try { try {
kmsProperties = invocation.getArgument(0); kmsProperties = invocation.getArgument(0);
} catch (Exception e) { } catch (Exception e) {
Assert.fail("Error getting argument from stubbed method: " + e.getMessage()); Assertions.fail("Error getting argument from stubbed method: " + e.getMessage());
} }
for (KmsProperties kmsProp : kmsProperties) { for (KmsProperties kmsProp : kmsProperties) {
@ -54,7 +54,7 @@ public class IntegrationTestConfiguration {
try { try {
loadManager = Whitebox.getInternalState(spy, "loadManager"); loadManager = Whitebox.getInternalState(spy, "loadManager");
} catch (Exception e) { } catch (Exception e) {
Assert.fail("Error getting private property from stubbed object: " + e.getMessage()); Assertions.fail("Error getting private property from stubbed object: " + e.getMessage());
} }
Kms kms = new Kms(kmsProp, loadManager, spy); Kms kms = new Kms(kmsProp, loadManager, spy);
KurentoClient kClient = mock(KurentoClient.class); KurentoClient kClient = mock(KurentoClient.class);

View File

@ -1,10 +1,13 @@
package io.openvidu.server.test.unit; package io.openvidu.server.test.unit;
import io.openvidu.java.client.IceServerProperties; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.DisplayName; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.openvidu.java.client.IceServerProperties;
public class IceServerPropertiesTest { public class IceServerPropertiesTest {
@ -12,160 +15,82 @@ public class IceServerPropertiesTest {
@DisplayName("IceServerProperty exceptions tests") @DisplayName("IceServerProperty exceptions tests")
public void iceServerPropertiesExceptionTest() { public void iceServerPropertiesExceptionTest() {
// Wrong urls // Wrong urls
notValidIceServerTest( notValidIceServerTest("wrongurl", null, null,
"wrongurl", null, null, "Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'");
"Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'" notValidIceServerTest("wrongurl", "anyuser", null,
); "Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'");
notValidIceServerTest( notValidIceServerTest("wrongurl", null, "anypassword",
"wrongurl", "anyuser", null, "Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'");
"Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'" notValidIceServerTest("wrongurl", "anyuser", "anypassword",
); "Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'");
notValidIceServerTest(
"wrongurl", null, "anypassword",
"Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'"
);
notValidIceServerTest(
"wrongurl", "anyuser", "anypassword",
"Not a valid TURN/STUN uri provided. No colons found in: 'wrongurl'"
);
// Wrong prefixes // Wrong prefixes
notValidIceServerTest( notValidIceServerTest("turnss:wrongurl", null, null,
"turnss:wrongurl", null, null, "The protocol 'turnss' is invalid. Only valid values are: [turn, turns] [stuns, stun]");
"The protocol 'turnss' is invalid. Only valid values are: [turn, turns] [stuns, stun]" notValidIceServerTest("stunss:wrongurl", "anyuser", null,
); "The protocol 'stunss' is invalid. Only valid values are: [turn, turns] [stuns, stun]");
notValidIceServerTest( notValidIceServerTest("anything:wrongurl", null, "anypassword",
"stunss:wrongurl", "anyuser", null, "The protocol 'anything' is invalid. Only valid values are: [turn, turns] [stuns, stun]");
"The protocol 'stunss' is invalid. Only valid values are: [turn, turns] [stuns, stun]" notValidIceServerTest(":", null, null,
); "The protocol '' is invalid. Only valid values are: [turn, turns] [stuns, stun]");
notValidIceServerTest( notValidIceServerTest("", null, null, "Not a valid TURN/STUN uri provided. No colons found in: ''");
"anything:wrongurl", null, "anypassword",
"The protocol 'anything' is invalid. Only valid values are: [turn, turns] [stuns, stun]"
);
notValidIceServerTest(
":", null, null,
"The protocol '' is invalid. Only valid values are: [turn, turns] [stuns, stun]"
);
notValidIceServerTest(
"", null, null,
"Not a valid TURN/STUN uri provided. No colons found in: ''"
);
// Try invalid host and ports // Try invalid host and ports
notValidIceServerTest( notValidIceServerTest("stun:hostname.com:99a99", null, null,
"stun:hostname.com:99a99", null, null, "The port defined in 'stun:hostname.com:99a99' is not a number (0-65535)");
"The port defined in 'stun:hostname.com:99a99' is not a number (0-65535)" notValidIceServerTest("stun:hostname.com:-1", null, null,
); "The port defined in 'stun:hostname.com:-1' is not a valid port number (0-65535)");
notValidIceServerTest( notValidIceServerTest("stun:hostname:port:more", null, null,
"stun:hostname.com:-1", null, null, "Host or port are not correctly defined in STUN/TURN uri: 'stun:hostname:port:more'");
"The port defined in 'stun:hostname.com:-1' is not a valid port number (0-65535)" notValidIceServerTest("stun:hostname.com:port more", null, null,
); "The port defined in 'stun:hostname.com:port more' is not a number (0-65535)");
notValidIceServerTest( notValidIceServerTest("stun:hostname.com:", null, null,
"stun:hostname:port:more", null, null, "Host or port are not correctly defined in STUN/TURN uri: 'stun:hostname.com:'");
"Host or port are not correctly defined in STUN/TURN uri: 'stun:hostname:port:more'" notValidIceServerTest("stun:[1:2:3:4:5:6:7:8]junk:1000", null, null,
); "Port is not specified correctly after IPv6 in uri: 'stun:[1:2:3:4:5:6:7:8]junk:1000'");
notValidIceServerTest( notValidIceServerTest("stun:[notvalid:]:1000", null, null,
"stun:hostname.com:port more", null, null, "Is not a valid Internet Address (IP or Domain Name): 'notvalid:'");
"The port defined in 'stun:hostname.com:port more' is not a number (0-65535)" notValidIceServerTest("stun::5555", null, null, "Host defined in 'stun::5555' is empty or null");
); notValidIceServerTest("stun:", null, null, "Host defined in 'stun:' is empty or null");
notValidIceServerTest(
"stun:hostname.com:", null, null,
"Host or port are not correctly defined in STUN/TURN uri: 'stun:hostname.com:'"
);
notValidIceServerTest(
"stun:[1:2:3:4:5:6:7:8]junk:1000", null, null,
"Port is not specified correctly after IPv6 in uri: 'stun:[1:2:3:4:5:6:7:8]junk:1000'"
);
notValidIceServerTest(
"stun:[notvalid:]:1000", null, null,
"Is not a valid Internet Address (IP or Domain Name): 'notvalid:'"
);
notValidIceServerTest(
"stun::5555", null, null,
"Host defined in 'stun::5555' is empty or null"
);
notValidIceServerTest(
"stun:", null, null,
"Host defined in 'stun:' is empty or null"
);
// Illegal Uri tests according to RFC 3986 and RFC 7064 (URI schemes for STUN and TURN) // Illegal Uri tests according to RFC 3986 and RFC 7064 (URI schemes for STUN
notValidIceServerTest( // and TURN)
"stun:/hostname.com", null, null, notValidIceServerTest("stun:/hostname.com", null, null,
"Is not a valid Internet Address (IP or Domain Name): '/hostname.com'" "Is not a valid Internet Address (IP or Domain Name): '/hostname.com'");
); notValidIceServerTest("stun:?hostname.com", null, null, "STUN uri can't have any '?' query param");
notValidIceServerTest( notValidIceServerTest("stun:#hostname.com", null, null,
"stun:?hostname.com", null, null, "Is not a valid Internet Address (IP or Domain Name): '#hostname.com'");
"STUN uri can't have any '?' query param"
);
notValidIceServerTest(
"stun:#hostname.com", null, null,
"Is not a valid Internet Address (IP or Domain Name): '#hostname.com'"
);
// illegal ?transport=xxx tests in turn uris // illegal ?transport=xxx tests in turn uris
notValidIceServerTest( notValidIceServerTest("turn:hostname.com?transport=invalid", "anyuser", "anypassword",
"turn:hostname.com?transport=invalid", "anyuser", "anypassword", "Wrong value specified in STUN/TURN uri: 'turn:hostname.com?transport=invalid'. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp");
"Wrong value specified in STUN/TURN uri: 'turn:hostname.com?transport=invalid'. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp" notValidIceServerTest("turn:hostname.com?transport=", "anyuser", "anypassword",
); "Wrong value specified in STUN/TURN uri: 'turn:hostname.com?transport='. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp");
notValidIceServerTest( notValidIceServerTest("turn:hostname.com?=", "anyuser", "anypassword",
"turn:hostname.com?transport=", "anyuser", "anypassword", "Wrong value specified in STUN/TURN uri: 'turn:hostname.com?='. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp");
"Wrong value specified in STUN/TURN uri: 'turn:hostname.com?transport='. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp" notValidIceServerTest("turn:hostname.com?", "anyuser", "anypassword",
); "Wrong value specified in STUN/TURN uri: 'turn:hostname.com?'. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp");
notValidIceServerTest( notValidIceServerTest("?", "anyuser", "anypassword",
"turn:hostname.com?=", "anyuser", "anypassword", "Not a valid TURN/STUN uri provided. No colons found in: '?'");
"Wrong value specified in STUN/TURN uri: 'turn:hostname.com?='. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp"
);
notValidIceServerTest(
"turn:hostname.com?", "anyuser", "anypassword",
"Wrong value specified in STUN/TURN uri: 'turn:hostname.com?'. Unique valid arguments after '?' are '?transport=tcp' or '?transport=udp"
);
notValidIceServerTest(
"?", "anyuser", "anypassword",
"Not a valid TURN/STUN uri provided. No colons found in: '?'"
);
// Transport can not be defined in STUN // Transport can not be defined in STUN
notValidIceServerTest( notValidIceServerTest("stun:hostname.com?transport=tcp", null, null, "STUN uri can't have any '?' query param");
"stun:hostname.com?transport=tcp", null, null, notValidIceServerTest("stun:hostname.com?transport=udp", null, null, "STUN uri can't have any '?' query param");
"STUN uri can't have any '?' query param"
);
notValidIceServerTest(
"stun:hostname.com?transport=udp", null, null,
"STUN uri can't have any '?' query param"
);
// Stun can not have credentials defined // Stun can not have credentials defined
notValidIceServerTest( notValidIceServerTest("stun:hostname.com", "username", "credential",
"stun:hostname.com", "username", "credential", "Credentials can not be defined while using stun.");
"Credentials can not be defined while using stun." notValidIceServerTest("stun:hostname.com", "username", "credential",
); "Credentials can not be defined while using stun.");
notValidIceServerTest( notValidIceServerTest("stun:hostname.com", "username", null,
"stun:hostname.com", "username", "credential", "Credentials can not be defined while using stun.");
"Credentials can not be defined while using stun." notValidIceServerTest("stun:hostname.com", null, "credential",
); "Credentials can not be defined while using stun.");
notValidIceServerTest(
"stun:hostname.com", "username", null,
"Credentials can not be defined while using stun."
);
notValidIceServerTest(
"stun:hostname.com", null, "credential",
"Credentials can not be defined while using stun."
);
// Turn must have credentials // Turn must have credentials
notValidIceServerTest( notValidIceServerTest("turn:hostname.com", null, null, "Credentials must be defined while using turn");
"turn:hostname.com", null, null, notValidIceServerTest("turn:hostname.com", "username", null, "Credentials must be defined while using turn");
"Credentials must be defined while using turn" notValidIceServerTest("turn:hostname.com", null, "credential", "Credentials must be defined while using turn");
);
notValidIceServerTest(
"turn:hostname.com", "username", null,
"Credentials must be defined while using turn"
);
notValidIceServerTest(
"turn:hostname.com", null, "credential",
"Credentials must be defined while using turn"
);
} }
@Test @Test

View File

@ -11,8 +11,8 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.java.client.VideoCodec; import io.openvidu.java.client.VideoCodec;