mirror of https://github.com/OpenVidu/openvidu.git
openvidu-java-client: RecordingPropertiesTest
parent
84f23f6beb
commit
e5fc3927b5
|
@ -540,6 +540,7 @@ public class RecordingProperties {
|
||||||
Boolean ignoreFailedStreamsParam;
|
Boolean ignoreFailedStreamsParam;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String session = (String) params.get("session");
|
||||||
nameParam = (String) params.get("name");
|
nameParam = (String) params.get("name");
|
||||||
hasAudioParam = (Boolean) params.get("hasAudio");
|
hasAudioParam = (Boolean) params.get("hasAudio");
|
||||||
hasVideoParam = (Boolean) params.get("hasVideo");
|
hasVideoParam = (Boolean) params.get("hasVideo");
|
||||||
|
@ -631,7 +632,7 @@ public class RecordingProperties {
|
||||||
if (frameRateParam != null) {
|
if (frameRateParam != null) {
|
||||||
if (!FormatChecker.isAcceptableRecordingFrameRate(frameRateParam.intValue())) {
|
if (!FormatChecker.isAcceptableRecordingFrameRate(frameRateParam.intValue())) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height");
|
"Wrong 'frameRate' parameter. Acceptable values are within range [1,120]");
|
||||||
}
|
}
|
||||||
frameRateFinal = frameRateParam.intValue();
|
frameRateFinal = frameRateParam.intValue();
|
||||||
} else {
|
} else {
|
||||||
|
@ -640,7 +641,7 @@ public class RecordingProperties {
|
||||||
|
|
||||||
if (shmSizeParam != null) {
|
if (shmSizeParam != null) {
|
||||||
if (!FormatChecker.isAcceptableRecordingShmSize(shmSizeParam)) {
|
if (!FormatChecker.isAcceptableRecordingShmSize(shmSizeParam)) {
|
||||||
throw new IllegalStateException("Wrong \"shmSize\" parameter. Must be 134217728 (128 MB) minimum");
|
throw new IllegalStateException("Wrong 'shmSize' parameter. Must be 134217728 (128 MB) minimum");
|
||||||
}
|
}
|
||||||
shmSizeFinal = shmSizeParam;
|
shmSizeFinal = shmSizeParam;
|
||||||
} else {
|
} else {
|
||||||
|
@ -684,7 +685,11 @@ public class RecordingProperties {
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// Not a json object
|
// Not a json object
|
||||||
if (params.containsKey("mediaNode")) {
|
if (params.containsKey("mediaNode")) {
|
||||||
mediaNodeDefault = (String) params.get("mediaNode");
|
try {
|
||||||
|
mediaNodeDefault = (String) params.get("mediaNode");
|
||||||
|
} catch (Exception e2) {
|
||||||
|
throw new IllegalArgumentException("Wrong 'mediaNode' parameter. Wrong type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -430,7 +431,12 @@ public class SessionProperties {
|
||||||
}
|
}
|
||||||
String mediaNode;
|
String mediaNode;
|
||||||
try {
|
try {
|
||||||
mediaNode = mediaNodeJson.get("id").getAsString();
|
JsonPrimitive primitive = mediaNodeJson.get("id").getAsJsonPrimitive();
|
||||||
|
if (!primitive.isString()) {
|
||||||
|
throw new IllegalArgumentException("Type error in parameter 'mediaNode.id': not a String");
|
||||||
|
} else {
|
||||||
|
mediaNode = primitive.getAsString();
|
||||||
|
}
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new IllegalArgumentException("Type error in parameter 'mediaNode.id': " + e.getMessage());
|
throw new IllegalArgumentException("Type error in parameter 'mediaNode.id': " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
package io.openvidu.java.client.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import io.openvidu.java.client.RecordingProperties;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
public class RecordingPropertiesTest extends TestCase {
|
||||||
|
|
||||||
|
public RecordingPropertiesTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(RecordingPropertiesTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* { "session":"ses_YnDaGYNcd7", "name": "MyRecording", "hasAudio": true,
|
||||||
|
* "hasVideo": true, "outputMode": "COMPOSED", "recordingLayout": "CUSTOM",
|
||||||
|
* "customLayout": "mySimpleLayout", "resolution": "1280x720", "frameRate": 25,
|
||||||
|
* "shmSize": 536870912, "ignoreFailedStreams": false, "mediaNode": { "id":
|
||||||
|
* "media_i-0c58bcdd26l11d0sd" } }
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void testRecordingFromJsonSuccess() {
|
||||||
|
String jsonString = "{'session':'MY_CUSTOM_STRING','name':'MY_CUSTOM_STRING','hasAudio':false,'hasVideo':true,'outputMode':'COMPOSED','recordingLayout':'CUSTOM','customLayout':'MY_CUSTOM_STRING','resolution':'1000x1000','frameRate':33,'shmSize':333333333,'mediaNode':{'id':'MY_CUSTOM_STRING'}}";
|
||||||
|
Map<String, ?> map = mapFromJsonString(jsonString);
|
||||||
|
RecordingProperties.Builder builder = RecordingProperties.fromJson(map, null);
|
||||||
|
RecordingProperties props = builder.build();
|
||||||
|
JsonObject finalJson = props.toJson();
|
||||||
|
|
||||||
|
JsonObject originalJson = new Gson().fromJson(jsonString, JsonObject.class);
|
||||||
|
originalJson = adaptProps(originalJson);
|
||||||
|
|
||||||
|
assertEquals(originalJson, finalJson);
|
||||||
|
|
||||||
|
jsonString = "{'session':'MY_CUSTOM_STRING','name':'MY_CUSTOM_STRING','hasAudio':false,'hasVideo':true,'outputMode':'INDIVIDUAL','ignoreFailedStreams':true}";
|
||||||
|
map = mapFromJsonString(jsonString);
|
||||||
|
builder = RecordingProperties.fromJson(map, null);
|
||||||
|
props = builder.build();
|
||||||
|
finalJson = props.toJson();
|
||||||
|
|
||||||
|
originalJson = new Gson().fromJson(jsonString, JsonObject.class);
|
||||||
|
originalJson = adaptProps(originalJson);
|
||||||
|
|
||||||
|
assertEquals(originalJson, finalJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFromJsonError() {
|
||||||
|
Map<String, ?> map = mapFromJsonString("{'session':false}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'session':123}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'name':true}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'name':0}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'name':{'object':true}}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'name':[]}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'hasAudio':'str'}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'hasVideo':123}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'hasVideo':123}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'outputMode':false}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'recordingLayout':123}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'customLayout':{}}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'resolution':false}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'frameRate':'str'}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'shmSize':'str'}");
|
||||||
|
assertException(map, "Type error in some parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'hasAudio':false,'hasVideo':false}");
|
||||||
|
assertException(map, "Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false",
|
||||||
|
IllegalStateException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'resolution':'99x1000'}");
|
||||||
|
assertException(map, "Wrong 'resolution' parameter", IllegalStateException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'frameRate':121}");
|
||||||
|
assertException(map, "Wrong 'frameRate' parameter", IllegalStateException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'shmSize':134217727}");
|
||||||
|
assertException(map, "Wrong 'shmSize' parameter", IllegalStateException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'mediaNode':true}");
|
||||||
|
assertException(map, "Wrong 'mediaNode' parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'mediaNode':{}}");
|
||||||
|
assertException(map, "Wrong 'mediaNode' parameter", IllegalArgumentException.class);
|
||||||
|
|
||||||
|
map = mapFromJsonString("{'mediaNode':{'id':false}}");
|
||||||
|
assertException(map, "Wrong 'mediaNode' parameter", IllegalArgumentException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject adaptProps(JsonObject json) {
|
||||||
|
json.remove("session");
|
||||||
|
if (json.has("mediaNode")) {
|
||||||
|
json.addProperty("mediaNode", json.get("mediaNode").getAsJsonObject().get("id").getAsString());
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, ?> mapFromJsonString(String json) {
|
||||||
|
return new Gson().fromJson(json, Map.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Exception> void assertException(Map<String, ?> params, String containsError,
|
||||||
|
Class<T> exceptionClass) {
|
||||||
|
if (exceptionClass != null) {
|
||||||
|
T exception = assertThrows(exceptionClass, () -> RecordingProperties.fromJson(params, null));
|
||||||
|
assertTrue(exception.getMessage().contains(containsError));
|
||||||
|
} else {
|
||||||
|
Exception exception = assertThrows(RuntimeException.class,
|
||||||
|
() -> RecordingProperties.fromJson(params, null));
|
||||||
|
assertTrue(exception.getMessage().contains(containsError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue