Search in sources :

Example 11 with StackImpl

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

Example 12 with StackImpl

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());
}
Also used : Response(com.jayway.restassured.response.Response) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 13 with StackImpl

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);
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with StackImpl

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();
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 15 with StackImpl

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

Aggregations

StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)26 Test (org.testng.annotations.Test)15 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)5 Response (com.jayway.restassured.response.Response)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)4 Consumes (javax.ws.rs.Consumes)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 StackDto (org.eclipse.che.api.workspace.shared.dto.stack.StackDto)3 TypeLiteral (com.google.inject.TypeLiteral)2 Transactional (com.google.inject.persist.Transactional)2 EntityManager (javax.persistence.EntityManager)2 POST (javax.ws.rs.POST)2 AccountImpl (org.eclipse.che.account.spi.AccountImpl)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ServerException (org.eclipse.che.api.core.ServerException)2 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)2