Search in sources :

Example 6 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto in project che by eclipse.

the class StackServiceTest method stackShouldBeUpdated.

@Test
public void stackShouldBeUpdated() throws NotFoundException, ServerException, ConflictException {
    final String updatedDescription = "some description";
    final String updatedScope = "advanced";
    StackDto updatedStackDto = DtoFactory.getInstance().createDto(StackDto.class).withId(STACK_ID).withName(NAME).withDescription(updatedDescription).withScope(updatedScope).withCreator(CREATOR).withTags(tags).withSource(stackSourceDto).withComponents(componentsDto);
    StackImpl updateStack = new StackImpl(stackImpl);
    updateStack.setDescription(updatedDescription);
    updateStack.setScope(updatedScope);
    when(stackDao.getById(STACK_ID)).thenReturn(stackImpl).thenReturn(updateStack);
    when(stackDao.update(any())).thenReturn(updateStack).thenReturn(updateStack);
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).content(updatedStackDto).when().put(SECURE_PATH + "/stack/" + STACK_ID);
    assertEquals(response.getStatusCode(), 200);
    StackDto result = unwrapDto(response, StackDto.class);
    assertEquals(result.getId(), updatedStackDto.getId());
    assertEquals(result.getName(), updatedStackDto.getName());
    assertEquals(result.getDescription(), updatedStackDto.getDescription());
    assertEquals(result.getScope(), updatedStackDto.getScope());
    assertEquals(result.getTags().get(0), updatedStackDto.getTags().get(0));
    assertEquals(result.getTags().get(1), updatedStackDto.getTags().get(1));
    assertEquals(result.getComponents().get(0).getName(), updatedStackDto.getComponents().get(0).getName());
    assertEquals(result.getComponents().get(0).getVersion(), updatedStackDto.getComponents().get(0).getVersion());
    assertEquals(result.getSource().getType(), updatedStackDto.getSource().getType());
    assertEquals(result.getSource().getOrigin(), updatedStackDto.getSource().getOrigin());
    assertEquals(result.getCreator(), updatedStackDto.getCreator());
    verify(stackDao).update(any());
    verify(stackDao).getById(STACK_ID);
}
Also used : Response(com.jayway.restassured.response.Response) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 7 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto in project che by eclipse.

the class StackServiceTest method setUp.

@BeforeMethod
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    byte[] fileContent = STACK_ID.getBytes();
    stackIcon = new StackIcon(ICON_MEDIA_TYPE, "image/svg+xml", fileContent);
    componentsImpl = singletonList(new StackComponentImpl(COMPONENT_NAME, COMPONENT_VERSION));
    stackSourceImpl = new StackSourceImpl(SOURCE_TYPE, SOURCE_ORIGIN);
    CommandImpl command = new CommandImpl(COMMAND_NAME, COMMAND_LINE, COMMAND_TYPE);
    EnvironmentImpl environment = new EnvironmentImpl(null, null);
    WorkspaceConfigImpl workspaceConfig = WorkspaceConfigImpl.builder().setName(WORKSPACE_CONFIG_NAME).setDefaultEnv(DEF_ENVIRONMENT_NAME).setCommands(singletonList(command)).setEnvironments(singletonMap(ENVIRONMENT_NAME, environment)).build();
    stackSourceDto = newDto(StackSourceDto.class).withType(SOURCE_TYPE).withOrigin(SOURCE_ORIGIN);
    StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName(COMPONENT_NAME).withVersion(COMPONENT_VERSION);
    componentsDto = singletonList(stackComponentDto);
    stackDto = DtoFactory.getInstance().createDto(StackDto.class).withId(STACK_ID).withName(NAME).withDescription(DESCRIPTION).withScope(SCOPE).withCreator(CREATOR).withTags(tags).withSource(stackSourceDto).withComponents(componentsDto);
    stackImpl = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
    foreignStack = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(FOREIGN_CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
    when(uriInfo.getBaseUriBuilder()).thenReturn(new UriBuilderImpl());
    final Field uriField = service.getClass().getSuperclass().getDeclaredField("uriInfo");
    uriField.setAccessible(true);
    uriField.set(service, uriInfo);
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) Field(java.lang.reflect.Field) StackComponentImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl) StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) StackSourceImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl) StackSourceDto(org.eclipse.che.api.workspace.shared.dto.stack.StackSourceDto) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto in project che by eclipse.

the class StackServiceTest method stackByIdShouldBeReturned.

//    @Test
//    public void shouldThrowBadRequestExceptionOnCreateStackWithEmptyBody() {
//        final Response response = given().auth()
//                                         .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
//                                         .contentType(APPLICATION_JSON)
//                                         .when()
//                                         .post(SECURE_PATH + "/stack");
//
//        assertEquals(response.getStatusCode(), 400);
//        assertEquals(unwrapDto(response, ServiceError.class).getMessage(), "Stack required");
//    }
//    @Test
//    public void shouldThrowBadRequestExceptionOnCreateStackWithEmptyName() {
//        StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("Java").withVersion("1.8.45");
//        StackSourceDto stackSourceDto = newDto(StackSourceDto.class).withType("image").withOrigin("codenvy/ubuntu_jdk8");
//        StackDto stackDto = newDto(StackDto.class).withId(USER_ID)
//                                                  .withDescription("")
//                                                  .withScope("Simple java stack for generation java projects")
//                                                  .withTags(asList("java", "maven"))
//                                                  .withCreator("che")
//                                                  .withComponents(singletonList(stackComponentDto))
//                                                  .withSource(stackSourceDto);
//
//        Response response = given().auth()
//                                   .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
//                                   .contentType(APPLICATION_JSON)
//                                   .body(stackDto)
//                                   .when()
//                                   .post(SECURE_PATH + "/stack");
//
//        assertEquals(response.getStatusCode(), 400);
//        assertEquals(unwrapDto(response, ServiceError.class).getMessage(), "Stack name required");
//    }
/** Get stack by id */
@Test
public void stackByIdShouldBeReturned() throws NotFoundException, ServerException {
    when(stackDao.getById(STACK_ID)).thenReturn(stackImpl);
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/stack/" + STACK_ID);
    assertEquals(response.getStatusCode(), 200);
    StackDto result = unwrapDto(response, StackDto.class);
    assertEquals(result.getId(), stackImpl.getId());
    assertEquals(result.getName(), stackImpl.getName());
    assertEquals(result.getDescription(), stackImpl.getDescription());
    assertEquals(result.getScope(), stackImpl.getScope());
    assertEquals(result.getTags().get(0), stackImpl.getTags().get(0));
    assertEquals(result.getTags().get(1), stackImpl.getTags().get(1));
    assertEquals(result.getComponents().get(0).getName(), stackImpl.getComponents().get(0).getName());
    assertEquals(result.getComponents().get(0).getVersion(), stackImpl.getComponents().get(0).getVersion());
    assertEquals(result.getSource().getType(), stackImpl.getSource().getType());
    assertEquals(result.getSource().getOrigin(), stackImpl.getSource().getOrigin());
    assertEquals(result.getCreator(), stackImpl.getCreator());
}
Also used : Response(com.jayway.restassured.response.Response) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Test(org.testng.annotations.Test)

Example 9 with StackDto

use of org.eclipse.che.api.workspace.shared.dto.stack.StackDto in project che by eclipse.

the class StackServiceTest method shouldReturnsStackByTagList.

@Test
public void shouldReturnsStackByTagList() throws ServerException {
    StackImpl stack2 = new StackImpl(stackImpl);
    stack2.setTags(singletonList("Subversion"));
    when(stackDao.searchStacks(anyString(), eq(singletonList("Subversion")), anyInt(), anyInt())).thenReturn(singletonList(stack2));
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/stack?tags=Subversion");
    assertEquals(response.getStatusCode(), 200);
    verify(stackDao).searchStacks(anyString(), eq(singletonList("Subversion")), anyInt(), anyInt());
    List<StackDto> result = unwrapListDto(response, StackDto.class);
    assertEquals(result.size(), 1);
    assertEquals(result.get(0).getName(), stack2.getName());
}
Also used : Response(com.jayway.restassured.response.Response) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) Test(org.testng.annotations.Test)

Aggregations

StackDto (org.eclipse.che.api.workspace.shared.dto.stack.StackDto)9 Test (org.testng.annotations.Test)7 Response (com.jayway.restassured.response.Response)6 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)4 StackComponentDto (org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto)3 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)2 StackSourceDto (org.eclipse.che.api.workspace.shared.dto.stack.StackSourceDto)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)1 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)1 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)1 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)1 StackComponentImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl)1 StackSourceImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl)1 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)1