Search in sources :

Example 11 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryByIdentifierWithValidation.

@Test
public void shouldReturnFactoryByIdentifierWithValidation() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    when(factoryManager.getFactoryImages(FACTORY_ID)).thenReturn(emptySet());
    doNothing().when(acceptValidator).validateOnAccept(any(FactoryDto.class));
    final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID + "?validate=true");
    assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 12 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithoutImages.

@Test
public void shouldSaveFactoryWithoutImages() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.saveFactory(any(FactoryDto.class))).thenReturn(factory);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(ContentType.JSON).body(factoryDto).expect().statusCode(200).post(SERVICE_PATH);
    assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 13 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithImagesFromFormData.

@Test
public void shouldSaveFactoryWithImagesFromFormData() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", JsonHelper.toJson(factoryDto), APPLICATION_JSON).multiPart("image", getImagePath().toFile(), FACTORY_IMAGE_MIME_TYPE).expect().statusCode(200).when().post(SERVICE_PATH);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    final boolean found = result.getLinks().stream().anyMatch(link -> link.getRel().equals("image") && link.getProduces().equals(FACTORY_IMAGE_MIME_TYPE) && !link.getHref().isEmpty());
    factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
    assertEquals(result, factoryDto);
    assertTrue(found);
}
Also used : Response(com.jayway.restassured.response.Response) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 14 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryWithImagesWhenImagesWithoutContent.

@Test
public void shouldSaveFactoryWithImagesWhenImagesWithoutContent() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    final FactoryDto factoryDto = asDto(factory, user);
    doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", DTO.toJson(factoryDto), APPLICATION_JSON).multiPart("image", File.createTempFile("img", ".jpeg"), "image/jpeg").expect().statusCode(200).when().post(SERVICE_PATH);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    verify(factoryManager).saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class));
    factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
    assertEquals(result, factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Aggregations

Factory (org.eclipse.che.api.core.model.factory.Factory)14 DtoFactory (org.eclipse.che.dto.server.DtoFactory)14 Test (org.testng.annotations.Test)12 Response (com.jayway.restassured.response.Response)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)10 InputStream (java.io.InputStream)5 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 APPLICATION_JSON (javax.ws.rs.core.MediaType.APPLICATION_JSON)2 TEXT_PLAIN (javax.ws.rs.core.MediaType.TEXT_PLAIN)2 UriInfo (javax.ws.rs.core.UriInfo)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2