openvidu-test-e2e: REST api full test
This commit is contained in:
parent
248539fa42
commit
2c6e770db3
@ -285,6 +285,10 @@ public class SessionRestController {
|
||||
return this.generateErrorResponse("Type error in some parameter", "/api/tokens", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (sessionId == null) {
|
||||
return this.generateErrorResponse("Type error in some parameter", "/api/tokens", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
JsonObject kurentoOptions = null;
|
||||
|
||||
if (params.get("kurentoOptions") != null) {
|
||||
@ -369,6 +373,11 @@ public class SessionRestController {
|
||||
|
||||
log.info("REST API: POST /api/recordings/start {}", params.toString());
|
||||
|
||||
if (!this.openviduConfig.isRecordingModuleEnabled()) {
|
||||
// OpenVidu Server configuration property "openvidu.recording" is set to false
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
String sessionId;
|
||||
String name;
|
||||
String outputModeString;
|
||||
@ -397,81 +406,83 @@ public class SessionRestController {
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (!this.openviduConfig.isRecordingModuleEnabled()) {
|
||||
// OpenVidu Server configuration property "openvidu.recording" is set to false
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
io.openvidu.java.client.Recording.OutputMode finalOutputMode = null;
|
||||
RecordingLayout recordingLayout = null;
|
||||
if (outputModeString != null && !outputModeString.isEmpty()) {
|
||||
try {
|
||||
finalOutputMode = io.openvidu.java.client.Recording.OutputMode.valueOf(outputModeString);
|
||||
} catch (Exception e) {
|
||||
return this.generateErrorResponse("Type error in some parameter", "/api/recordings/start",
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
if (io.openvidu.java.client.Recording.OutputMode.COMPOSED.equals(finalOutputMode)) {
|
||||
if (resolution != null && !sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
|
||||
return this.generateErrorResponse(
|
||||
"Wrong \"resolution\" parameter. Acceptable values from 100 to 1999 for both width and height",
|
||||
"/api/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
if (recordingLayoutString != null && !recordingLayoutString.isEmpty()) {
|
||||
try {
|
||||
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
|
||||
} catch (Exception e) {
|
||||
return this.generateErrorResponse("Type error in some parameter", "/api/recordings/start",
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((hasAudio != null && hasVideo != null) && !hasAudio && !hasVideo) {
|
||||
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
||||
return this.generateErrorResponse(
|
||||
"Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false",
|
||||
"/api/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
Session session = sessionManager.getSession(sessionId);
|
||||
|
||||
if (session == null) {
|
||||
if (sessionManager.getSessionNotActive(sessionId) != null) {
|
||||
// Session is not active
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
session = sessionManager.getSessionNotActive(sessionId);
|
||||
if (session != null) {
|
||||
if (!(MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode()))
|
||||
|| this.recordingManager.sessionIsBeingRecorded(session.getSessionId())) {
|
||||
// Session is not in ROUTED MediMode or it is already being recorded
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
} else {
|
||||
// Session is not active
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
// Session does not exist
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if (!(MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode()))
|
||||
|| this.recordingManager.sessionIsBeingRecorded(session.getSessionId())) {
|
||||
// Session is not in ROUTED MediMode or it is already being recorded
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
if (session.getParticipants().isEmpty()) {
|
||||
// Session has no participants
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED))
|
||||
|| this.recordingManager.sessionIsBeingRecorded(session.getSessionId())) {
|
||||
// Session is not in ROUTED MediMode or it is already being recorded
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
|
||||
RecordingProperties.Builder builder = new RecordingProperties.Builder();
|
||||
if (finalOutputMode == null) {
|
||||
builder.outputMode(session.getSessionProperties().defaultOutputMode());
|
||||
}
|
||||
|
||||
io.openvidu.java.client.Recording.OutputMode outputMode;
|
||||
try {
|
||||
outputMode = io.openvidu.java.client.Recording.OutputMode.valueOf(outputModeString);
|
||||
} catch (Exception e) {
|
||||
outputMode = session.getSessionProperties().defaultOutputMode();
|
||||
}
|
||||
RecordingProperties.Builder builder = new RecordingProperties.Builder().name(name).outputMode(outputMode)
|
||||
.hasAudio(hasAudio != null ? hasAudio : true).hasVideo(hasVideo != null ? hasVideo : true);
|
||||
|
||||
if (outputMode.equals(io.openvidu.java.client.Recording.OutputMode.COMPOSED)) {
|
||||
|
||||
if (io.openvidu.java.client.Recording.OutputMode.COMPOSED.equals(finalOutputMode)) {
|
||||
if (resolution != null) {
|
||||
if (sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
|
||||
builder.resolution(resolution);
|
||||
} else {
|
||||
return new ResponseEntity<>(
|
||||
"Wrong \"resolution\" parameter. Acceptable values from 100 to 1999 for both width and height",
|
||||
HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
builder.resolution(resolution);
|
||||
}
|
||||
|
||||
RecordingLayout recordingLayout;
|
||||
if (recordingLayoutString == null || recordingLayoutString.isEmpty()) {
|
||||
// "recordingLayout" parameter not defined. Use global layout from
|
||||
// SessionProperties (it is always configured as it has RecordingLayout.BEST_FIT
|
||||
// as default value)
|
||||
recordingLayout = session.getSessionProperties().defaultRecordingLayout();
|
||||
} else {
|
||||
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
|
||||
}
|
||||
|
||||
builder.recordingLayout(recordingLayout);
|
||||
|
||||
builder.recordingLayout(recordingLayout == null ? session.getSessionProperties().defaultRecordingLayout()
|
||||
: recordingLayout);
|
||||
if (RecordingLayout.CUSTOM.equals(recordingLayout)) {
|
||||
customLayout = (customLayout == null || customLayout.isEmpty())
|
||||
? session.getSessionProperties().defaultCustomLayout()
|
||||
: customLayout;
|
||||
builder.customLayout(customLayout);
|
||||
builder.customLayout(
|
||||
customLayout == null ? session.getSessionProperties().defaultCustomLayout() : customLayout);
|
||||
}
|
||||
}
|
||||
|
||||
RecordingProperties properties = builder.build();
|
||||
if (!properties.hasAudio() && !properties.hasVideo()) {
|
||||
// Cannot start a recording with both "hasAudio" and "hasVideo" to false
|
||||
return new ResponseEntity<>("Cannot start a recording with both \"hasAudio\" and \"hasVideo\" set to false",
|
||||
HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
builder.name(name).hasAudio(hasAudio != null ? hasAudio : true).hasVideo(hasVideo != null ? hasVideo : true);
|
||||
|
||||
try {
|
||||
Recording startedRecording = this.recordingManager.startRecording(session, properties);
|
||||
Recording startedRecording = this.recordingManager.startRecording(session, builder.build());
|
||||
return new ResponseEntity<>(startedRecording.toJson().toString(), getResponseHeaders(), HttpStatus.OK);
|
||||
} catch (OpenViduException e) {
|
||||
return new ResponseEntity<>("Error starting recording: " + e.getMessage(), getResponseHeaders(),
|
||||
@ -484,11 +495,6 @@ public class SessionRestController {
|
||||
|
||||
log.info("REST API: POST /api/recordings/stop/{}", recordingId);
|
||||
|
||||
if (recordingId == null) {
|
||||
// "recordingId" parameter not found
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
Recording recording = recordingManager.getStartedRecording(recordingId);
|
||||
|
||||
if (recording == null) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,6 @@ import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.junit.Assert;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -57,8 +56,6 @@ public class CustomHttpClient {
|
||||
private String openviduUrl;
|
||||
private String headerAuth;
|
||||
|
||||
private JSONParser parser = new JSONParser();
|
||||
|
||||
public CustomHttpClient(String openviduUrl, String openviduSecret) {
|
||||
this.openviduUrl = openviduUrl.replaceFirst("/*$", "");
|
||||
this.headerAuth = "Basic " + Base64.getEncoder().encodeToString(("OPENVIDUAPP:" + openviduSecret).getBytes());
|
||||
@ -89,39 +86,40 @@ public class CustomHttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
public void rest(HttpMethod method, String path, int status) {
|
||||
this.commonRest(method, path, null, status);
|
||||
public JSONObject rest(HttpMethod method, String path, int status) {
|
||||
return this.commonRest(method, path, null, status);
|
||||
}
|
||||
|
||||
public void rest(HttpMethod method, String path, String body, int status) {
|
||||
this.commonRest(method, path, body, status);
|
||||
public JSONObject rest(HttpMethod method, String path, String body, int status) {
|
||||
return this.commonRest(method, path, body, status);
|
||||
}
|
||||
|
||||
public void rest(HttpMethod method, String path, String body, int status, boolean exactFields,
|
||||
String jsonElmentString) {
|
||||
public JSONObject rest(HttpMethod method, String path, String body, int status, boolean exactReturnedFields,
|
||||
String jsonReturnedValue) {
|
||||
JSONObject json = this.commonRest(method, path, body, status);
|
||||
JSONObject jsonObjExpected = null;
|
||||
jsonElmentString.replaceAll("'", "\"");
|
||||
jsonReturnedValue.replaceAll("'", "\"");
|
||||
try {
|
||||
jsonObjExpected = new JSONObject((String) jsonElmentString);
|
||||
jsonObjExpected = new JSONObject((String) jsonReturnedValue);
|
||||
} catch (JSONException e1) {
|
||||
Assert.fail("Expected json element is a string without a JSON format: " + jsonElmentString);
|
||||
Assert.fail("Expected json element is a string without a JSON format: " + jsonReturnedValue);
|
||||
}
|
||||
|
||||
if (exactFields) {
|
||||
if (exactReturnedFields) {
|
||||
Assert.assertEquals("Error in number of keys in JSON response to POST " + path, jsonObjExpected.length(),
|
||||
json.length());
|
||||
}
|
||||
for (String key : jsonObjExpected.keySet()) {
|
||||
json.get(key);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public void rest(HttpMethod method, String path, String body, int status, boolean exactFields,
|
||||
public JSONObject rest(HttpMethod method, String path, String body, int status, boolean exactReturnedFields,
|
||||
Map<String, ?> jsonResponse) {
|
||||
org.json.JSONObject json = this.commonRest(method, path, body, status);
|
||||
|
||||
if (exactFields) {
|
||||
if (exactReturnedFields) {
|
||||
Assert.assertEquals("Error in number of keys in JSON response to POST " + path, jsonResponse.size(),
|
||||
json.length());
|
||||
}
|
||||
@ -166,6 +164,7 @@ public class CustomHttpClient {
|
||||
Assert.fail("JSON response field cannot be parsed: " + entry.toString());
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
private org.json.JSONObject commonRest(HttpMethod method, String path, String body, int status) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user