Search in sources :

Example 1 with SnapshotDto

use of org.eclipse.che.api.machine.shared.dto.SnapshotDto in project che by eclipse.

the class WorkspaceServiceTest method shouldReturnEmptyListIfNotSnapshotsFound.

@Test
public void shouldReturnEmptyListIfNotSnapshotsFound() throws Exception {
    // given
    String workspaceId = "testWsId1";
    when(wsManager.getSnapshot(workspaceId)).thenReturn(Collections.emptyList());
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspaceId + "/snapshot");
    // then
    assertEquals(response.getStatusCode(), 200);
    List<SnapshotDto> snapshotDtos = unwrapDtoList(response, SnapshotDto.class);
    assertTrue(snapshotDtos.isEmpty());
    verify(wsManager).getSnapshot(workspaceId);
}
Also used : Response(com.jayway.restassured.response.Response) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 2 with SnapshotDto

use of org.eclipse.che.api.machine.shared.dto.SnapshotDto in project che by eclipse.

the class WorkspaceServiceTest method shouldReturnSnapshotsOnGetSnapshot.

@Test
public void shouldReturnSnapshotsOnGetSnapshot() throws Exception {
    // given
    String workspaceId = "testWsId1";
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().setCreationDate(System.currentTimeMillis()).setDescription("description").setDev(true).setEnvName("envName").setId("snap1").setMachineName("machine1").setMachineSource(new MachineSourceImpl("type").setContent("content")).setType("type").setWorkspaceId(workspaceId);
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.setDev(false).build();
    List<SnapshotImpl> originSnapshots = Arrays.asList(snapshot1, snapshot2);
    when(wsManager.getSnapshot(workspaceId)).thenReturn(originSnapshots);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspaceId + "/snapshot");
    // then
    assertEquals(response.getStatusCode(), 200);
    List<SnapshotDto> snapshotDtos = unwrapDtoList(response, SnapshotDto.class);
    List<SnapshotImpl> newSnapshots = snapshotDtos.stream().map(SnapshotImpl::new).collect(Collectors.toList());
    originSnapshots.forEach(snapshot -> snapshot.setMachineSource(null));
    assertEquals(newSnapshots, originSnapshots);
    verify(wsManager).getSnapshot(workspaceId);
}
Also used : Response(com.jayway.restassured.response.Response) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

Response (com.jayway.restassured.response.Response)2 SnapshotDto (org.eclipse.che.api.machine.shared.dto.SnapshotDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Test (org.testng.annotations.Test)2 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)1 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)1