openvidu-test-e2e: REST API test extended (fetch, force, close session)

pull/87/merge
pabloFuente 2018-07-23 10:53:24 +02:00
parent fcdf65f8e4
commit 2aaf4590d4
2 changed files with 110 additions and 5 deletions

View File

@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.Assert;
@ -1069,6 +1070,110 @@ public class OpenViduTestAppE2eTest {
}
@Test
@DisplayName("REST API: Fetch all, fetch one, force disconnect, force unpublish, close session")
void restApiFetchForce() throws Exception {
setupBrowser("chrome");
log.info("REST API: Fetch all, fetch one, force disconnect, force unpublish, close session");
user.getDriver().findElement(By.id("add-user-btn")).click();
user.getDriver().findElement(By.id("add-user-btn")).click();
// API REST test
user.getDriver().findElement(By.id("session-api-btn-0")).click();
Thread.sleep(1000);
// Close session (undefined)
user.getDriver().findElement(By.id("close-session-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
"Error [Session undefined]"));
// Fetch one (undefined)
user.getDriver().findElement(By.id("get-session-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value",
"Error [Session undefined]"));
// Fetch all (no active sessions)
user.getDriver().findElement(By.id("list-sessions-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value",
"Number: 0. Changes: false"));
user.getDriver().findElement(By.id("close-dialog-btn")).click();
Thread.sleep(1000);
user.getDriver().findElement(By.id("auto-join-checkbox")).click();
user.getDriver().findElement(By.id("one2one-btn")).click();
user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
user.getEventManager().waitUntilEventReaches("accessAllowed", 2);
user.getEventManager().waitUntilEventReaches("streamCreated", 4);
user.getEventManager().waitUntilEventReaches("streamPlaying", 4);
Assert.assertTrue(user.getEventManager().assertMediaTracks(user.getDriver().findElements(By.tagName("video")),
true, true));
// Fetch existing session (change)
user.getDriver().findElement(By.id("session-api-btn-0")).click();
Thread.sleep(1000);
user.getDriver().findElement(By.id("get-session-btn")).click();
user.getWaiter()
.until(ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value", "Changes: true"));
// Store connectionId and streamId
String response = user.getDriver().findElement(By.id("api-response-text-area")).getAttribute("value");
JSONObject json = (JSONObject) ((JSONArray) new JSONParser().parse(response.split("%")[1])).get(0);
String connectionId = (String) json.keySet().iterator().next();
String streamId = (String) ((JSONObject) ((JSONArray) json.get(connectionId)).get(0)).get("streamId");
// Fetch all sessions (no change)
user.getDriver().findElement(By.id("list-sessions-btn")).click();
user.getWaiter().until(ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value",
"Number: 1. Changes: false"));
// Force unpublish wrong
user.getDriver().findElement(By.id("resource-id-field")).clear();
user.getDriver().findElement(By.id("resource-id-field")).sendKeys("FAIL");
user.getDriver().findElement(By.id("force-unpublish-api-btn")).click();
user.getWaiter()
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [404]"));
// Force unpublish right
user.getDriver().findElement(By.id("resource-id-field")).clear();
user.getDriver().findElement(By.id("resource-id-field")).sendKeys(streamId);
user.getDriver().findElement(By.id("force-unpublish-api-btn")).click();
user.getWaiter().until(
ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Stream unpublished"));
user.getEventManager().waitUntilEventReaches("streamDestroyed", 2);
// Force disconnect wrong
user.getDriver().findElement(By.id("resource-id-field")).clear();
user.getDriver().findElement(By.id("resource-id-field")).sendKeys("FAIL");
user.getDriver().findElement(By.id("force-disconnect-api-btn")).click();
user.getWaiter()
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [404]"));
// Force disconnect right
user.getDriver().findElement(By.id("resource-id-field")).clear();
user.getDriver().findElement(By.id("resource-id-field")).sendKeys(connectionId);
user.getDriver().findElement(By.id("force-disconnect-api-btn")).click();
user.getWaiter()
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "User disconnected"));
user.getEventManager().waitUntilEventReaches("connectionDestroyed", 1);
// Close session
user.getDriver().findElement(By.id("close-session-btn")).click();
user.getWaiter()
.until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Session closed"));
user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 0));
user.getDriver().findElement(By.id("close-dialog-btn")).click();
gracefullyLeaveParticipants(1);
}
@Test
@Disabled
@DisplayName("One2One Opera [Video + Audio]")

View File

@ -10,13 +10,13 @@ import { OpenVidu as OpenViduAPI, Session as SessionAPI } from 'openvidu-node-cl
<h2 mat-dialog-title>API REST</h2>
<mat-dialog-content>
<label class="label">Sessions</label>
<button mat-button id="list-sessions-btn" (click)="fetchActiveConnections()">Fetch</button>
<button mat-button id="get-session-btn" (click)="fetchActiveConnections()">Fetch</button>
<button mat-button id="list-sessions-btn" (click)="fetchActiveSessions()">Fetch all</button>
<button mat-button id="close-session-btn" (click)="closeSession()">Close this session</button>
<mat-form-field class="inner-text-input">
<input matInput id="session-id-field" placeholder="resourceId" [(ngModel)]="resourceId">
<input matInput id="resource-id-field" placeholder="resourceId" [(ngModel)]="resourceId">
</mat-form-field>
<button mat-button id="force-disconnet-api-btn" (click)="forceDisconnect()" [disabled]="!resourceId">Force disconnect</button>
<button mat-button id="force-disconnect-api-btn" (click)="forceDisconnect()" [disabled]="!resourceId">Force disconnect</button>
<button mat-button id="force-unpublish-api-btn" (click)="forceUnpublish()" [disabled]="!resourceId">Force unpublish</button>
<mat-divider></mat-divider>
<label class="label">Recordings</label>
@ -155,7 +155,7 @@ export class SessionApiDialogComponent {
resp[con.connectionId].push(pub);
});
});
this.response = 'Session info fetched [' + JSON.stringify(resp) + ']. Changes: ' + anyChange;
this.response = 'Session info fetched %[' + JSON.stringify(resp) + ']%. Changes: ' + anyChange;
})
.catch(error => {
this.response = 'Error [' + error.message + ']';
@ -166,7 +166,7 @@ export class SessionApiDialogComponent {
console.log('Fetching all sessions info');
this.OV.fetch()
.then(anyChange => {
this.response = 'All sessions info fetched. Changes: ' + anyChange;
this.response = 'All sessions info fetched. Number: ' + this.OV.activeSessions.length + '. Changes: ' + anyChange;
})
.catch(error => {
this.response = 'Error [' + error.message + ']';