Search in sources :

Example 1 with DevfileDto

use of org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto in project che-server by eclipse-che.

the class WorkspaceServiceTest method shouldCreateWorkspaceFromDevfile.

@Test
public void shouldCreateWorkspaceFromDevfile() throws Exception {
    final DevfileDto devfileDto = createDevfileDto();
    final WorkspaceImpl workspace = createWorkspace(devfileDto);
    when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(devfileDto).when().post(SECURE_PATH + "/workspace/devfile" + "?namespace=test" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(wsManager).createWorkspace(any(Devfile.class), eq("test"), eq(ImmutableMap.of("factoryId", "factory123", "custom", "custom:value")), any());
}
Also used : Response(io.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) DevfileDto(org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) Test(org.testng.annotations.Test)

Example 2 with DevfileDto

use of org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto in project devspaces-images by redhat-developer.

the class WorkspaceServiceTest method shouldCreateWorkspaceFromDevfile.

@Test
public void shouldCreateWorkspaceFromDevfile() throws Exception {
    final DevfileDto devfileDto = createDevfileDto();
    final WorkspaceImpl workspace = createWorkspace(devfileDto);
    when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())).thenReturn(workspace);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(devfileDto).when().post(SECURE_PATH + "/workspace/devfile" + "?namespace=test" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 201);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
    verify(wsManager).createWorkspace(any(Devfile.class), eq("test"), eq(ImmutableMap.of("factoryId", "factory123", "custom", "custom:value")), any());
}
Also used : Response(io.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) DevfileDto(org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) Test(org.testng.annotations.Test)

Example 3 with DevfileDto

use of org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto in project che-server by eclipse-che.

the class WorkspaceServiceTest method shouldReturnBadRequestOnInvalidDevfile.

@Test
public void shouldReturnBadRequestOnInvalidDevfile() throws Exception {
    final DevfileDto devfileDto = createDevfileDto();
    final WorkspaceImpl workspace = createWorkspace(devfileDto);
    when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())).thenThrow(new ValidationException("boom"));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(devfileDto).when().post(SECURE_PATH + "/workspace/devfile" + "?namespace=test" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 400);
    String error = unwrapError(response);
    assertEquals(error, "boom");
}
Also used : Response(io.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ValidationException(org.eclipse.che.api.core.ValidationException) DevfileDto(org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) Test(org.testng.annotations.Test)

Example 4 with DevfileDto

use of org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto in project devspaces-images by redhat-developer.

the class WorkspaceServiceTest method shouldReturnBadRequestOnInvalidDevfile.

@Test
public void shouldReturnBadRequestOnInvalidDevfile() throws Exception {
    final DevfileDto devfileDto = createDevfileDto();
    final WorkspaceImpl workspace = createWorkspace(devfileDto);
    when(wsManager.createWorkspace(any(Devfile.class), anyString(), any(), any())).thenThrow(new ValidationException("boom"));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(devfileDto).when().post(SECURE_PATH + "/workspace/devfile" + "?namespace=test" + "&attribute=factoryId:factory123" + "&attribute=custom:custom:value");
    assertEquals(response.getStatusCode(), 400);
    String error = unwrapError(response);
    assertEquals(error, "boom");
}
Also used : Response(io.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ValidationException(org.eclipse.che.api.core.ValidationException) DevfileDto(org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Devfile(org.eclipse.che.api.core.model.workspace.devfile.Devfile) Test(org.testng.annotations.Test)

Aggregations

Response (io.restassured.response.Response)4 Devfile (org.eclipse.che.api.core.model.workspace.devfile.Devfile)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 DevfileDto (org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto)4 Test (org.testng.annotations.Test)4 ValidationException (org.eclipse.che.api.core.ValidationException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2