openvidu-test-e2e: update tests with new CustomHttpClient

pull/550/head
pabloFuente 2020-10-13 12:23:35 +02:00
parent 9e957eddf5
commit 5575bf60cf
5 changed files with 331 additions and 149 deletions

View File

@ -97,6 +97,12 @@
<artifactId>unirest-java</artifactId>
<version>${version.unirest}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>

View File

@ -24,7 +24,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Base64;
import java.util.Map;
import java.util.Map.Entry;
import javax.net.ssl.SSLContext;
@ -33,14 +33,14 @@ import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.mashape.unirest.http.HttpMethod;
import com.mashape.unirest.http.HttpResponse;
@ -89,98 +89,143 @@ public class CustomHttpClient {
return this.commonRest(method, path, body, status);
}
public JsonObject rest(HttpMethod method, String path, String body, int status, boolean exactReturnedFields,
String jsonReturnedValue) throws Exception {
JsonObject json = this.commonRest(method, path, body, status);
JsonObject jsonObjExpected = null;
/**
* "matchKeys" to true for the returned JSON to have the exact same keys as the
* expected JSON (same number, position and name). If false, then any key
* existing in the expected JSON must exist in the returned JSON, but the
* returned JSON may have extra keys not available in expected JSON.
*
* "matchValues" to true for the returned JSON to have the exact same value in
* all the key-value pairs declared in the expected JSON. If the returned JSON
* does not have any of the keys of the expected JSON, an Error is thrown. The
* value comparison applies to NULL, JSON arrays, JSON objects or primitive
* values, at all nested levels.
*
* "matchArrays" to true for the returned JSON to have the exact same JSON array
* as value that any array property of the expected JSON. That includes value
* and order. To false to check only that JSON array is the type of the returned
* value, but not to check its content. If "matchValues" is false, then this
* property will not have effect and shall be considered false.
*/
public JsonObject rest(HttpMethod method, String path, String body, int status, boolean matchKeys,
boolean matchValues, boolean matchArrays, String jsonReturnedValue) throws Exception {
JsonObject jsonExpected = null;
jsonReturnedValue.replaceAll("'", "\"");
try {
jsonObjExpected = JsonParser.parseString(jsonReturnedValue).getAsJsonObject();
jsonExpected = JsonParser.parseString(jsonReturnedValue).getAsJsonObject();
} catch (JsonSyntaxException e1) {
throw new Exception("Expected json element is a string without a JSON format: " + jsonReturnedValue);
throw new Exception("Expected JSON element is a string without a JSON format: " + jsonReturnedValue);
}
JsonObject jsonActual = this.commonRest(method, path, body, status);
check(jsonExpected, jsonActual, matchKeys, matchValues, matchArrays);
return jsonActual;
if (exactReturnedFields) {
if (jsonObjExpected.size() != json.size()) {
throw new Exception(
"Error in number of keys in JSON response to POST (" + json.toString() + ")" + path);
}
}
for (String key : jsonObjExpected.keySet()) {
Class<?> c1 = jsonObjExpected.get(key).getClass();
Class<?> c2 = json.get(key).getClass();
c1 = unifyNumberType(c1);
c2 = unifyNumberType(c2);
if (!c1.equals(c2)) {
throw new Exception("Wrong class of property " + key);
}
}
return json;
}
public JsonObject rest(HttpMethod method, String path, String body, int status, boolean exactReturnedFields,
Map<Object, Object> jsonResponse) throws Exception {
JsonObject json = this.commonRest(method, path, body, status);
if (exactReturnedFields) {
if (jsonResponse.size() != json.size())
throw new Exception("Error in number of keys in JSON response to POST " + path);
}
for (Map.Entry<Object, Object> entry : jsonResponse.entrySet()) {
String key = entry.getKey().toString();
Object value = entry.getValue();
if (value instanceof String) {
try {
JsonObject jsonObjExpected = JsonParser.parseString((String) value).getAsJsonObject();
JsonObject jsonObjActual = json.get(key).getAsJsonObject();
// COMPARE
} catch (Exception e1) {
try {
JsonArray jsonArrayExpected = JsonParser.parseString((String) value).getAsJsonArray();
JsonArray jsonArrayActual = json.get(key).getAsJsonArray();
// COMPARE
} catch (Exception e2) {
if (!((String) value).equals(json.get(key).getAsString())) {
throw new Exception("JSON field " + entry.getKey() + " has not expected value. Expected: "
+ value + ". Actual: " + json.get(key).getAsString());
}
}
public static void check(JsonObject jsonExpected, JsonObject jsonActual, boolean matchKeys, boolean matchValues,
boolean matchArrays) throws Exception {
if (matchKeys) {
checkSameKeys(jsonExpected, jsonActual, null, matchValues, matchArrays);
} else {
for (String key : jsonExpected.keySet()) {
JsonElement elExpected = jsonExpected.get(key);
JsonElement elActual = jsonActual.get(key);
if (elActual == null) {
throw new Exception(
"Expected property \"" + key + "\" did not exist in actual JSON " + jsonActual.toString());
}
checkSameType(elExpected, elActual, key, matchValues);
}
}
}
public static void checkSameKeys(JsonElement expected, JsonElement actual, String parent, boolean matchValues,
boolean matchArrays) throws Exception {
if (!expected.isJsonObject()) {
if (expected.isJsonArray()) {
JsonArray expectedArray = expected.getAsJsonArray();
JsonArray actualArray = actual.getAsJsonArray();
if (matchArrays) {
checkSameType(expectedArray, actualArray, parent, matchValues);
}
} else {
checkSameType(expected, actual, parent, matchValues);
}
} else {
JsonObject exp = expected.getAsJsonObject();
JsonObject act = actual.getAsJsonObject();
if (exp.size() != act.size()) {
throw new Exception("Error in number of keys in JSON object. Expected " + exp.size() + ". Actual: "
+ act.size() + ". Actual object: " + act.toString());
}
for (Entry<String, JsonElement> entry : exp.entrySet()) {
String key = entry.getKey();
if (!act.has(key)) {
throw new Exception("Property \"" + key + "\" is missing in actual object " + act.toString());
}
checkSameKeys(entry.getValue(), act.get(key), key, matchValues, matchArrays);
}
}
}
public static void checkSameType(JsonElement expected, JsonElement actual, String key, boolean checkAlsoSameValue)
throws Exception {
if (!expected.getClass().equals(actual.getClass())) {
throw new Exception("Expected JSON element has not the same class as the actual JSON element. Expected: "
+ expected.getClass().getSimpleName() + ". Actual: " + actual.getClass().getSimpleName());
}
if (expected.isJsonNull()) {
if (!actual.isJsonNull()) {
throw new Exception("Actual JSON element should be null");
}
}
if (expected.isJsonArray()) {
if (!actual.isJsonArray()) {
throw new Exception("Actual JSON element should be a JSON array");
}
JsonArray arrayExpected = expected.getAsJsonArray();
JsonArray arrayActual = actual.getAsJsonArray();
if (checkAlsoSameValue && !arrayExpected.equals(arrayActual)) {
throw new Exception("Property \"" + key + "\" expected an array " + arrayExpected.toString()
+ " but found " + arrayActual.toString());
}
}
if (expected.isJsonObject()) {
if (!actual.isJsonObject()) {
throw new Exception("Actual JSON element should be a JSON object");
}
JsonObject objectExpected = expected.getAsJsonObject();
JsonObject objectActual = actual.getAsJsonObject();
if (checkAlsoSameValue && !objectExpected.equals(objectActual)) {
throw new Exception("Property \"" + key + "\" expected a JSON object " + objectExpected.toString()
+ " but found " + objectActual.toString());
}
}
if (expected.isJsonPrimitive()) {
JsonPrimitive primitive1 = expected.getAsJsonPrimitive();
JsonPrimitive primitive2 = actual.getAsJsonPrimitive();
if (primitive1.isString()) {
String string1 = primitive1.getAsString();
String string2 = primitive2.getAsString();
if (checkAlsoSameValue && !string1.equals(string2)) {
throw new Exception("Property \"" + key + "\" expected " + string1 + " but was " + string2);
}
}
if (primitive1.isBoolean()) {
boolean boolean1 = primitive1.getAsBoolean();
boolean boolean2 = primitive2.getAsBoolean();
if (checkAlsoSameValue && !boolean1 == boolean2) {
throw new Exception("Property \"" + key + "\" expected " + boolean1 + " but was " + boolean2);
}
}
if (primitive1.isNumber()) {
Number number1 = primitive1.getAsNumber();
Number number2 = primitive2.getAsNumber();
if (checkAlsoSameValue && !number1.equals(number2)) {
throw new Exception("Property \"" + key + "\" expected " + number1 + " but was " + number2);
}
} else if (value instanceof Integer) {
if (((int) value) != json.get(key).getAsInt()) {
throw new Exception("JSON field " + entry.getKey() + " has not expected value. Expected: " + value
+ ". Actual: " + json.get(key).getAsInt());
}
} else if (value instanceof Long) {
if (((long) value) != json.get(key).getAsLong()) {
throw new Exception("JSON field " + entry.getKey() + " has not expected value. Expected: " + value
+ ". Actual: " + json.get(key).getAsLong());
}
} else if (value instanceof Double) {
if (((double) value) != json.get(key).getAsDouble()) {
throw new Exception("JSON field " + entry.getKey() + " has not expected value. Expected: " + value
+ ". Actual: " + json.get(key).getAsDouble());
}
} else if (value instanceof Boolean) {
if (((boolean) value) != json.get(key).getAsBoolean()) {
throw new Exception("JSON field " + entry.getKey() + " has not expected value. Expected: " + value
+ ". Actual: " + json.get(key).getAsBoolean());
}
} else if (value instanceof JSONArray || value instanceof JsonArray) {
JsonParser.parseString(entry.getValue().toString()).getAsJsonArray();
} else if (value instanceof JSONObject || value instanceof JsonObject) {
JsonParser.parseString(entry.getValue().toString()).getAsJsonObject();
} else {
throw new Exception("JSON response field cannot be parsed: " + entry.toString());
}
}
return json;
}
public void shutdown() throws IOException {
@ -263,11 +308,4 @@ public class CustomHttpClient {
return json;
}
private Class<?> unifyNumberType(Class<?> myClass) {
if (Number.class.isAssignableFrom(myClass)) {
return Number.class;
}
return myClass;
}
}

View File

@ -0,0 +1,124 @@
package io.openvidu.test.browsers;
import org.junit.Assert;
import org.junit.Test;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import io.openvidu.test.browsers.utils.CustomHttpClient;
public class CustomHttpClientTest {
@Test
public void testOneLevel() throws Exception {
String expected = "{}";
String actual = "{}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1'}";
actual = "{'prop1':'val1'}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1','prop2':'val2'}";
actual = "{'prop1':'val1','prop2':'val2'}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1'}";
actual = "{'prop1':'val1','prop2':'val2'}";
executeCheck(expected, actual, false, true, true);
expected = "{'prop1':'val1','prop2':'val2'}";
actual = "{'prop1':'WRONG','prop2':'WRONG'}";
executeCheck(expected, actual, true, false, true);
expected = "{'prop1':'val1','prop2':[{},{}]}";
actual = "{'prop1':'WRONG','prop2':[{}]}";
executeCheck(expected, actual, true, false, true);
}
@Test
public void testMultipleLevels() throws Exception {
String expected = "{'prop1':{'prop2':'val2'}}";
String actual = "{'prop1':{'prop2':'val2'}}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1','prop2':{'prop3':'val3'}}";
actual = "{'prop1':'val1','prop2':{'prop3':'val3'}}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1','prop2':{'prop3':'val3'}}";
actual = "{'prop1':'WRONG','prop2':{'prop3':'WRONG'}}";
executeCheck(expected, actual, true, false, true);
Assert.assertThrows(IllegalStateException.class, () -> {
String expected2 = "{'prop1':'val1','prop2':{'prop3':'val3'}}";
String actual2 = "{'prop1':'WRONG','prop2':'WRONG'}";
executeCheck(expected2, actual2, true, false, true);
});
Assert.assertThrows(IllegalStateException.class, () -> {
String expected2 = "{'prop1':'val1','prop2':{'prop3':'val3'}}";
String actual2 = "{'prop1':'WRONG','prop2':[12,34]}";
executeCheck(expected2, actual2, true, false, true);
});
expected = "{'prop1':'val1','prop1':{'prop3':'val3'}}";
actual = "{'prop1':'val1','prop1':{'prop3':'val3'},'WRONG':'val1'}";
executeCheck(expected, actual, false, true, true);
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':'val1','prop2':[12,34]}";
String actual2 = "{'prop1':'val1','prop2':[12,35]}";
executeCheck(expected2, actual2, false, true, true);
});
Assert.assertThrows(IllegalStateException.class, () -> {
String expected2 = "{'prop1':'val1','prop2':[12,34]}";
String actual2 = "{'prop1':'val1','prop2':{'WRONG':true}}";
executeCheck(expected2, actual2, true, false, true);
});
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':'val1','prop1':{'prop3':null}}";
String actual2 = "{'prop1':'val1','prop1':{'prop3':12.4},'WRONG':'val1'}";
executeCheck(expected2, actual2, false, true, true);
});
expected = "{'prop1':'val1','prop2':{'prop3':null}}";
actual = "{'prop1':'val1','prop2':{'prop3':null},'WRONG':'val1'}";
executeCheck(expected, actual, false, true, true);
expected = "{'prop1':'val1','prop2':{'prop3':12}}";
actual = "{'prop1':'val1','prop2':{'prop3':12}}";
executeCheck(expected, actual, true, true, true);
expected = "{'prop1':'val1','prop2':[true,false]}";
actual = "{'prop1':'val1','prop2':[true,false]}";
executeCheck(expected, actual, true, true, true);
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':'val1','prop2':[false,true]}";
String actual2 = "{'prop1':'val1','prop2':[true,false]}";
executeCheck(expected2, actual2, true, true, true);
});
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':'val1','prop2':[false,true]}";
String actual2 = "{'prop1':'val1','prop2':[true,false]}";
executeCheck(expected2, actual2, true, true, true);
});
expected = "{'prop1':'val1','prop2':[false,true]}";
actual = "{'prop1':'val1','prop2':[]}";
executeCheck(expected, actual, true, false, true);
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':'val1','prop2':[false,true]}";
String actual2 = "{'prop1':'val1','prop2':[],'prop3':false}";
executeCheck(expected2, actual2, false, true, true);
});
expected = "{'prop1':1,'prop2':[]}";
actual = "{'prop1':1,'prop2':[{'prop2':'val2'}]}";
executeCheck(expected, actual, true, true, false);
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':1,'prop2':[]}";
String actual2 = "{'prop1':0,'prop2':[{'prop2':'val2'}]}";
executeCheck(expected2, actual2, true, true, false);
});
Assert.assertThrows(Exception.class, () -> {
String expected2 = "{'prop1':1,'prop2':[]}";
String actual2 = "{'prop1':1,'prop2':[{'prop2':'val2'}]}";
executeCheck(expected2, actual2, true, true, true);
});
}
private void executeCheck(String expected, String actual, boolean matchKeys, boolean matchValues,
boolean matchArrays) throws JsonSyntaxException, Exception {
expected = expected.replaceAll("'", "\"");
actual = actual.replaceAll("'", "\"");
CustomHttpClient.check(JsonParser.parseString(expected).getAsJsonObject(),
JsonParser.parseString(actual).getAsJsonObject(), matchKeys, matchValues, matchArrays);
}
}

View File

@ -32,7 +32,6 @@ import org.jcodec.common.model.Picture;
import org.jcodec.scale.AWTUtil;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.TakesScreenshot;
@ -82,9 +81,7 @@ public class AbstractOpenViduTestAppE2eTest {
protected volatile static boolean isKurentoRestartTest;
protected static OpenVidu OV;
@BeforeAll()
protected static void setupAll() {
protected static void checkFfmpegInstallation() {
String ffmpegOutput = commandLine.executeCommand("which ffmpeg");
if (ffmpegOutput == null || ffmpegOutput.isEmpty()) {
log.error("ffmpeg package is not installed in the host machine");
@ -93,10 +90,24 @@ public class AbstractOpenViduTestAppE2eTest {
} else {
log.info("ffmpeg is installed and accesible");
}
}
protected static void setupBrowserDrivers() {
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
}
protected static void cleanFoldersAndSetUpOpenViduJavaClient() {
try {
log.info("Cleaning folder /opt/openvidu/recordings");
FileUtils.cleanDirectory(new File("/opt/openvidu/recordings"));
} catch (IOException e) {
log.error(e.getMessage());
}
OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
}
protected static void loadEnvironmentVariables() {
String appUrl = System.getProperty("APP_URL");
if (appUrl != null) {
APP_URL = appUrl;
@ -147,14 +158,6 @@ public class AbstractOpenViduTestAppE2eTest {
OPENVIDU_SECRET = openvidusecret;
}
log.info("Using secret {} to connect to openvidu-server", OPENVIDU_SECRET);
try {
log.info("Cleaning folder /opt/openvidu/recordings");
FileUtils.cleanDirectory(new File("/opt/openvidu/recordings"));
} catch (IOException e) {
log.error(e.getMessage());
}
OV = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
}
protected void setupBrowser(String browser) {

View File

@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -45,8 +46,6 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mashape.unirest.http.HttpMethod;
@ -82,6 +81,18 @@ import io.openvidu.test.browsers.utils.webhook.CustomWebhook;
@ExtendWith(SpringExtension.class)
public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
final String DEFAULT_JSON_SESSION = "{'id':'STR','object':'STR','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false}";
final String DEFAULT_JSON_TOKEN = "{'id':'STR','object':'STR','token':'STR','connectionId':0,'session':'STR','role':'STR','data':'STR','record':true}";
final String DEFAULT_JSON_CONNECTION = "{'id':'STR','object':'STR','connectionId':'STR','sessionId':'STR','createdAt':0,'location':'STR','platform':'STR','role':'STR','record':true,'serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}";
@BeforeAll()
protected static void setupAll() {
checkFfmpegInstallation();
loadEnvironmentVariables();
setupBrowserDrivers();
cleanFoldersAndSetUpOpenViduJavaClient();
}
@Test
@DisplayName("One2One Chrome [Video + Audio]")
void oneToOneVideoAudioSessionChrome() throws Exception {
@ -2520,8 +2531,6 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
log.info("REST API test");
final String DEFAULT_JSON_SESSION = "{'sessionId':'STR','id':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false}";
CustomHttpClient restClient = new CustomHttpClient(OPENVIDU_URL, "OPENVIDUAPP", OPENVIDU_SECRET);
// 401
@ -2532,8 +2541,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
/** GET /openvidu/api/sessions (before session created) **/
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions/NOT_EXISTS", HttpStatus.SC_NOT_FOUND);
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true,
ImmutableMap.of("numberOfElements", new Integer(0), "content", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true, true, true,
"{'numberOfElements': 0, 'content': []}");
/** POST /openvidu/api/sessions **/
// 400
@ -2552,10 +2561,11 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// 200
body = "{'mediaMode': 'ROUTED', 'recordingMode': 'MANUAL', 'customSessionId': 'CUSTOM_SESSION_ID', 'defaultOutputMode': 'COMPOSED', 'defaultRecordingLayout': 'BEST_FIT'}";
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", body, HttpStatus.SC_OK, true, DEFAULT_JSON_SESSION);
// Default values
JsonObject res = restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", "{}", HttpStatus.SC_OK, true,
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", body, HttpStatus.SC_OK, true, false, true,
DEFAULT_JSON_SESSION);
// Default values
JsonObject res = restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", "{}", HttpStatus.SC_OK, true, false,
true, DEFAULT_JSON_SESSION);
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/" + res.get("id").getAsString(),
HttpStatus.SC_NO_CONTENT);
@ -2564,10 +2574,10 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", body, HttpStatus.SC_CONFLICT);
/** GET /openvidu/api/sessions (after session created) **/
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true,
DEFAULT_JSON_SESSION);
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true,
ImmutableMap.of("numberOfElements", new Integer(1), "content", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true, false,
true, DEFAULT_JSON_SESSION);
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true, true, false,
"{'numberOfElements': 1, 'content': []}");
/** POST /openvidu/api/tokens **/
// 400
@ -2585,9 +2595,9 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_BAD_REQUEST);
// 200
body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'allowedFilters': ['GStreamerFilter']}}";
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true,
"{'id':'STR','connectionId':'STR','session':'STR','role':'STR','data':'STR','record':true,'token':'STR','kurentoOptions':{'allowedFilters':['STR']}}");
body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'videoMaxSendBandwidth':777,'allowedFilters': ['GStreamerFilter']}}";
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true,
"{'id':'STR','object':'STR','connectionId':'STR','session':'STR','role':'STR','data':'STR','record':true,'token':'STR','kurentoOptions':{'videoMaxSendBandwidth':777,'allowedFilters':['STR']}}");
final String token1 = res.get("token").getAsString();
Assert.assertEquals("JSON return value from /openvidu/api/tokens should have equal srtings in 'id' and 'token'",
res.get("id").getAsString(), token1);
@ -2595,8 +2605,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// Default values
body = "{'session': 'CUSTOM_SESSION_ID'}";
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true,
"{'id':'STR','connectionId':'STR','session':'STR','role':'STR','data':'STR','record':true,'token':'STR'}");
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true,
DEFAULT_JSON_TOKEN);
final String token2 = res.get("id").getAsString();
/** POST /openvidu/api/signal (NOT ACTIVE SESSION) **/
@ -2644,7 +2654,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// 409 (RELAYED media mode)
res = restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", "{'mediaMode':'RELAYED'}", HttpStatus.SC_OK,
true, DEFAULT_JSON_SESSION);
true, false, false, DEFAULT_JSON_SESSION);
body = "{'session':'" + res.get("id").getAsString() + "'}";
restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/start", body, HttpStatus.SC_CONFLICT);
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/" + res.get("id").getAsString(),
@ -2687,14 +2697,14 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
/** GET /openvidu/api/recordings (before recording started) **/
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings/NOT_EXISTS", HttpStatus.SC_NOT_FOUND);
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true,
ImmutableMap.of("count", new Integer(0), "items", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true, true, true,
"{'count':0,'items':[]}");
/** POST /openvidu/api/recordings/start (ACTIVE SESSION) **/
// 200
body = "{'session':'CUSTOM_SESSION_ID'}";
restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/start", body, HttpStatus.SC_OK, true,
"{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':null,'status':'STR'}");
restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/start", body, HttpStatus.SC_OK, true, false, true,
"{'id':'STR','object':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':null,'status':'STR'}");
user.getEventManager().waitUntilEventReaches("recordingStarted", 2);
@ -2713,13 +2723,14 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// 200
restClient.rest(HttpMethod.DELETE, "/openvidu/api/recordings/CUSTOM_SESSION_ID", HttpStatus.SC_CONFLICT);
restClient.rest(HttpMethod.POST, "/openvidu/api/recordings/stop/CUSTOM_SESSION_ID", body, HttpStatus.SC_OK,
true,
"{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}");
true, false, true,
"{'id':'STR','object':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}");
/** GET /openvidu/api/recordings (after recording created) **/
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true,
"{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}");
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true,
ImmutableMap.of("count", new Integer(1), "items", new JsonArray()));
false, true,
"{'id':'STR','object':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}");
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true, true, false,
"{'count':1,'items':[]}");
user.getEventManager().waitUntilEventReaches("recordingStopped", 2);
@ -2729,8 +2740,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.DELETE, "/openvidu/api/recordings/CUSTOM_SESSION_ID", HttpStatus.SC_NO_CONTENT);
// GET /openvidu/api/recordings should return empty again
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true,
ImmutableMap.of("count", new Integer(0), "items", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/recordings", null, HttpStatus.SC_OK, true, true, true,
"{'count':0,'items':[]}");
/** DELETE /openvidu/api/sessions/<SESSION_ID>/stream/<STREAM_ID> **/
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/NOT_EXISTS/stream/NOT_EXISTS",
@ -2738,7 +2749,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/CUSTOM_SESSION_ID/stream/NOT_EXISTS",
HttpStatus.SC_NOT_FOUND);
res = restClient.rest(HttpMethod.GET, "/openvidu/api/sessions/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true,
"{'sessionId':'STR','id':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':2,'content'"
false, true,
"{'id':'STR','object':'STR','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':2,'content'"
+ ":[{'connectionId':'STR','createdAt':0,'location':'STR','platform':'STR','token':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':["
+ "{'createdAt':0,'streamId':'STR','mediaOptions':{'hasAudio':false,'audioActive':false,'hasVideo':false,'videoActive':false,'typeOfVideo':'STR','frameRate':0,"
+ "'videoDimensions':'STR','filter':{}}}],'subscribers':[{'createdAt':0,'streamId':'STR','publisher':'STR'}]},{'connectionId':'STR','createdAt':0,'location':'STR',"
@ -2786,8 +2798,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/CUSTOM_SESSION_ID", HttpStatus.SC_NO_CONTENT);
// GET /openvidu/api/sessions should return empty again
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true,
ImmutableMap.of("numberOfElements", new Integer(0), "content", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true, true, true,
"{'numberOfElements':0,'content':[]}");
/**
* DELETE /openvidu/api/sessions/<SESSION_ID>/connection/<CONNECTION_ID> (unused
@ -2796,10 +2808,12 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
body = "{'customSessionId': 'CUSTOM_SESSION_ID'}";
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", body, HttpStatus.SC_OK);
body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'SUBSCRIBER'}";
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK);
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true,
DEFAULT_JSON_TOKEN);
final String tokenAConnectionId = res.get("connectionId").getAsString();
final String tokenA = res.get("token").getAsString();
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK);
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true,
DEFAULT_JSON_TOKEN);
final String tokenBConnectionId = res.get("connectionId").getAsString();
final String tokenB = res.get("token").getAsString();
@ -2855,11 +2869,11 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/CUSTOM_SESSION_ID", HttpStatus.SC_NO_CONTENT);
// GET /openvidu/api/sessions should return empty again
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true,
ImmutableMap.of("numberOfElements", new Integer(0), "content", new JsonArray()));
restClient.rest(HttpMethod.GET, "/openvidu/api/sessions", null, HttpStatus.SC_OK, true, true, true,
"{'numberOfElements':0,'content':[]}");
/** GET /openvidu/api/config **/
restClient.rest(HttpMethod.GET, "/openvidu/api/config", null, HttpStatus.SC_OK, true,
restClient.rest(HttpMethod.GET, "/openvidu/api/config", null, HttpStatus.SC_OK, true, false, true,
"{'VERSION':'STR','DOMAIN_OR_PUBLIC_IP':'STR','HTTPS_PORT':0,'OPENVIDU_PUBLICURL':'STR','OPENVIDU_CDR':false,'OPENVIDU_STREAMS_VIDEO_MAX_RECV_BANDWIDTH':0,'OPENVIDU_STREAMS_VIDEO_MIN_RECV_BANDWIDTH':0,"
+ "'OPENVIDU_STREAMS_VIDEO_MAX_SEND_BANDWIDTH':0,'OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH':0,'OPENVIDU_SESSIONS_GARBAGE_INTERVAL':0,'OPENVIDU_SESSIONS_GARBAGE_THRESHOLD':0,"
+ "'OPENVIDU_RECORDING':false,'OPENVIDU_RECORDING_VERSION':'STR','OPENVIDU_RECORDING_PATH':'STR','OPENVIDU_RECORDING_PUBLIC_ACCESS':false,'OPENVIDU_RECORDING_NOTIFICATION':'STR',"
@ -3198,7 +3212,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// Init a session and publish IP camera AS FIRST PARTICIPANT
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions", "{'customSessionId':'IP_CAM_SESSION'}",
HttpStatus.SC_OK, true, "{'id': 'STR', 'createdAt': 0}");
HttpStatus.SC_OK, true, false, true, DEFAULT_JSON_SESSION);
// No rtspUri [400]
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions/IP_CAM_SESSION/connection", "{}",
@ -3211,8 +3225,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// Publish IP camera. Dummy URL because no user will subscribe to it [200]
String ipCamBody = "{'type':'IPCAM','rtspUri':'rtsp://dummyurl.com','adaptativeBitrate':true,'onlyPlayWithSubscribers':true,'networkCache':1000,'data':'MY_IP_CAMERA'}";
JsonObject response = restClient.rest(HttpMethod.POST, "/openvidu/api/sessions/IP_CAM_SESSION/connection",
ipCamBody, HttpStatus.SC_OK, true,
"{'connectionId':'STR','createdAt':0,'location':'STR','platform':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}");
ipCamBody, HttpStatus.SC_OK, true, false, true, DEFAULT_JSON_CONNECTION);
CustomWebhook.waitForEvent("sessionCreated", 1);
CustomWebhook.waitForEvent("participantJoined", 1);
@ -3309,8 +3322,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
+ "','adaptativeBitrate':true,'onlyPlayWithSubscribers':true,'networkCache':1000,'data':'MY_IP_CAMERA'}";
restClient.rest(HttpMethod.POST, "/openvidu/api/sessions/TestSession/connection", ipCamBody,
HttpStatus.SC_OK, true,
"{'connectionId':'STR','createdAt':0,'location':'STR','platform':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}");
HttpStatus.SC_OK, true, false, true, DEFAULT_JSON_CONNECTION);
user.getEventManager().waitUntilEventReaches("connectionCreated", 2);
user.getEventManager().waitUntilEventReaches("streamCreated", 2);
@ -3337,8 +3349,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// Publish again the IPCAM
response = restClient.rest(HttpMethod.POST, "/openvidu/api/sessions/TestSession/connection", ipCamBody,
HttpStatus.SC_OK, true,
"{'connectionId':'STR','createdAt':0,'location':'STR','platform':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}");
HttpStatus.SC_OK, true, false, true, DEFAULT_JSON_CONNECTION);
user.getEventManager().waitUntilEventReaches("connectionCreated", 3);
user.getEventManager().waitUntilEventReaches("streamCreated", 3);
user.getEventManager().waitUntilEventReaches("streamPlaying", 3);