Search in sources :

Example 1 with FactoryDto

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

the class FactoryServiceTest method shouldGenerateFactoryJsonIncludeGivenProjects.

@Test
public void shouldGenerateFactoryJsonIncludeGivenProjects() throws Exception {
    // given
    final String wsId = "workspace123234";
    WorkspaceImpl.WorkspaceImplBuilder ws = WorkspaceImpl.builder();
    WorkspaceConfigImpl.WorkspaceConfigImplBuilder wsConfig = WorkspaceConfigImpl.builder();
    ws.setId(wsId);
    wsConfig.setProjects(Arrays.asList(DTO.createDto(ProjectConfigDto.class).withPath("/proj1").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location")), DTO.createDto(ProjectConfigDto.class).withPath("/proj2").withSource(DTO.createDto(SourceStorageDto.class).withType("git").withLocation("location"))));
    wsConfig.setName("wsname");
    wsConfig.setEnvironments(singletonMap("env1", DTO.createDto(EnvironmentDto.class)));
    wsConfig.setDefaultEnv("env1");
    ws.setStatus(WorkspaceStatus.RUNNING);
    wsConfig.setCommands(singletonList(DTO.createDto(CommandDto.class).withName("MCI").withType("mvn").withCommandLine("clean install")));
    ws.setConfig(wsConfig.build());
    WorkspaceImpl usersWorkspace = ws.build();
    when(workspaceManager.getWorkspace(eq(wsId))).thenReturn(usersWorkspace);
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get("/private" + SERVICE_PATH + "/workspace/" + wsId);
    // then
    assertEquals(response.getStatusCode(), 200);
    FactoryDto result = DTO.createDtoFromJson(response.getBody().asString(), FactoryDto.class);
    assertEquals(result.getWorkspace().getProjects().size(), 2);
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 2 with FactoryDto

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

the class FactoryServiceTest method shouldBeAbleToUpdateFactory.

@Test
public void shouldBeAbleToUpdateFactory() throws Exception {
    final Factory existed = createFactory();
    final Factory update = createFactoryWithStorage(null, "git", "https://github.com/codenvy/platform-api1.git");
    when(factoryManager.getById(FACTORY_ID)).thenReturn(existed);
    when(factoryManager.updateFactory(any())).thenReturn(update);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(asDto(existed, user))).when().expect().statusCode(200).put(SERVICE_PATH + "/" + FACTORY_ID);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    verify(factoryManager, times(1)).updateFactory(any());
    assertEquals(result.withLinks(emptyList()), asDto(update, user));
}
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 3 with FactoryDto

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

the class FactoryBuilderTest method notValidParamsProvider.

@DataProvider(name = "notValidParamsProvider")
public static Object[][] notValidParamsProvider() throws URISyntaxException, IOException, NoSuchMethodException {
    FactoryDto factory = prepareFactory();
    EnvironmentDto environmentDto = factory.getWorkspace().getEnvironments().values().iterator().next();
    environmentDto.getRecipe().withType(null);
    return new Object[][] { { requireNonNull(dto.clone(factory)).withWorkspace(factory.getWorkspace().withDefaultEnv(null)) }, { requireNonNull(dto.clone(factory)).withWorkspace(factory.getWorkspace().withEnvironments(singletonMap("test", environmentDto))) } };
}
Also used : EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DataProvider(org.testng.annotations.DataProvider)

Example 4 with FactoryDto

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

the class FactoryBuilderTest method shouldBeAbleToValidateV4_0WithTrackedParamsWithoutAccountIdIfOnPremisesIsEnabled.

@Test
public void shouldBeAbleToValidateV4_0WithTrackedParamsWithoutAccountIdIfOnPremisesIsEnabled() throws Exception {
    factoryBuilder = new FactoryBuilder(sourceProjectParametersValidator);
    FactoryDto factory = prepareFactory().withPolicies(dto.createDto(PoliciesDto.class).withReferer("referrer").withSince(123L).withUntil(123L));
    factoryBuilder.checkValid(factory);
}
Also used : FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Test(org.testng.annotations.Test)

Example 5 with FactoryDto

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

the class FactoryBaseValidatorTest method invalidParametersFactoryUrlProvider.

@DataProvider(name = "badAdvancedFactoryUrlProvider")
public Object[][] invalidParametersFactoryUrlProvider() throws UnsupportedEncodingException {
    FactoryDto adv1 = prepareFactoryWithGivenStorage("notagit", VALID_REPOSITORY_URL, VALID_PROJECT_PATH);
    FactoryDto adv2 = prepareFactoryWithGivenStorage("git", null, VALID_PROJECT_PATH);
    FactoryDto adv3 = prepareFactoryWithGivenStorage("git", "", VALID_PROJECT_PATH);
    return new Object[][] { // invalid vcs
    { adv1 }, // invalid vcsurl
    { adv2 }, // invalid vcsurl
    { adv3 } };
}
Also used : FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DataProvider(org.testng.annotations.DataProvider)

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