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);
}
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);
}
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());
}
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());
}
Aggregations