use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.
the class StackServiceTest method shouldReturnsAllStacksWhenListTagsIsEmpty.
/** Search stack by tags */
@Test
public void shouldReturnsAllStacksWhenListTagsIsEmpty() throws ServerException {
StackImpl stack2 = new StackImpl(stackImpl);
stack2.setTags(singletonList("subversion"));
List<StackImpl> stacks = asList(stackImpl, stack2);
when(stackDao.searchStacks(anyString(), anyList(), anyInt(), anyInt())).thenReturn(stacks);
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/stack");
assertEquals(response.getStatusCode(), 200);
verify(stackDao).searchStacks(anyString(), anyList(), anyInt(), anyInt());
List<StackDto> result = unwrapListDto(response, StackDto.class);
assertEquals(result.size(), 2);
assertEquals(result.get(0).getName(), stackImpl.getName());
assertEquals(result.get(1).getName(), stack2.getName());
}
use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.
the class StackServiceTest method shouldThrowNotFoundExceptionWhenIconWasNotFound.
@Test
public void shouldThrowNotFoundExceptionWhenIconWasNotFound() throws NotFoundException, ServerException {
StackImpl test = new StackImpl(stackImpl);
test.setStackIcon(null);
when(stackDao.getById(test.getId())).thenReturn(test);
Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/stack/" + stackImpl.getId() + "/icon");
assertEquals(response.getStatusCode(), 404);
String expectedErrorMessage = format("Image for stack with id '%s' was not found.", STACK_ID);
assertEquals(unwrapDto(response, ServiceError.class).getMessage(), expectedErrorMessage);
verify(stackDao).getById(test.getId());
}
use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.
the class StackService method removeIcon.
@DELETE
@Path("/{id}/icon")
@GenerateLink(rel = LINK_REL_DELETE_ICON)
@ApiOperation(value = "Delete icon for required stack", notes = "This operation can be performed only by authorized stack owner")
@ApiResponses({ @ApiResponse(code = 204, message = "Icon was successfully removed"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access upload image for stack with required id"), @ApiResponse(code = 404, message = "The stack or icon doesn't exist"), @ApiResponse(code = 409, message = "Conflict error occurred during stack update" + "(e.g. Stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public void removeIcon(@ApiParam("The stack Id") @PathParam("id") final String id) throws NotFoundException, ServerException, ConflictException, ForbiddenException, BadRequestException {
StackImpl stack = stackDao.getById(id);
stack.setStackIcon(null);
stackDao.update(stack);
}
use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.
the class StackService method getIcon.
@GET
@Path("/{id}/icon")
@Produces("image/*")
@GenerateLink(rel = LINK_REL_GET_ICON)
@ApiOperation(value = "Get icon by stack id", notes = "This operation can be performed only by authorized user", response = byte[].class)
@ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested image entity"), @ApiResponse(code = 403, message = "The user does not have access to get image entity"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response getIcon(@ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException {
StackImpl stack = stackDao.getById(id);
if (stack == null) {
throw new NotFoundException("Stack with id '" + id + "' was not found.");
}
StackIcon image = stack.getStackIcon();
if (image == null) {
throw new NotFoundException("Image for stack with id '" + id + "' was not found.");
}
return Response.ok(image.getData(), image.getMediaType()).build();
}
use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl 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);
}
Aggregations