Search in sources :

Example 21 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto 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 22 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto 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)

Example 23 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldValidateTrackedParamsIfOrgIdIsMissingButOnPremisesTrue.

@Test
public void shouldValidateTrackedParamsIfOrgIdIsMissingButOnPremisesTrue() throws Exception {
    final DtoFactory dtoFactory = getInstance();
    FactoryDto factory = dtoFactory.createDto(FactoryDto.class);
    factory.withV("4.0").withPolicies(dtoFactory.createDto(PoliciesDto.class).withSince(System.currentTimeMillis() + 1_000_000).withUntil(System.currentTimeMillis() + 10_000_000).withReferer("codenvy.com"));
    validator = new TesterFactoryBaseValidator();
}
Also used : DtoFactory(org.eclipse.che.dto.server.DtoFactory) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 24 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldValidateOpenfileAction.

@Test
public void shouldValidateOpenfileAction() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    Map<String, String> params = new HashMap<>();
    params.put("file", "pom.xml");
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile").withProperties(params));
    IdeDto ide = newDto(IdeDto.class).withOnProjectsLoaded(newDto(OnProjectsLoadedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) HashMap(java.util.HashMap) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 25 with FactoryDto

use of org.eclipse.che.api.factory.shared.dto.FactoryDto in project che by eclipse.

the class FactoryBaseValidatorTest method shouldNotValidateIfrunCommandActionInsufficientParams.

@Test(expectedExceptions = BadRequestException.class)
public void shouldNotValidateIfrunCommandActionInsufficientParams() throws Exception {
    //given
    validator = new TesterFactoryBaseValidator();
    List<IdeActionDto> actions = singletonList(newDto(IdeActionDto.class).withId("openFile"));
    IdeDto ide = newDto(IdeDto.class).withOnProjectsLoaded(newDto(OnProjectsLoadedDto.class).withActions(actions));
    FactoryDto factoryWithAccountId = requireNonNull(getInstance().clone(factory)).withIde(ide);
    //when
    validator.validateProjectActions(factoryWithAccountId);
}
Also used : IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Aggregations

FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)30 Test (org.testng.annotations.Test)21 Response (com.jayway.restassured.response.Response)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 Factory (org.eclipse.che.api.core.model.factory.Factory)10 IdeActionDto (org.eclipse.che.api.factory.shared.dto.IdeActionDto)8 IdeDto (org.eclipse.che.api.factory.shared.dto.IdeDto)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)5 BadRequestException (org.eclipse.che.api.core.BadRequestException)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Produces (javax.ws.rs.Produces)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 List (java.util.List)2