Search in sources :

Example 1 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class WorkspaceEventsHandlerTest method onWsAgentOutputEventReceivedTest.

@Test
public void onWsAgentOutputEventReceivedTest() throws Exception {
    WorkspaceRuntimeDto runtime = mock(WorkspaceRuntimeDto.class);
    WorkspaceConfigDto workspaceConfig = mock(WorkspaceConfigDto.class);
    when(workspace.getRuntime()).thenReturn(runtime);
    MachineDto devMachine = mock(MachineDto.class);
    when(devMachine.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(devMachine.getId()).thenReturn(MACHINE_NAME);
    when(runtime.getDevMachine()).thenReturn(devMachine);
    when(runtime.getActiveEnv()).thenReturn(ACTIVE_ENV);
    when(workspace.getConfig()).thenReturn(workspaceConfig);
    Map<String, EnvironmentDto> environments = new HashMap<>(3);
    EnvironmentDto environment = mock(EnvironmentDto.class);
    environments.put(ACTIVE_ENV, environment);
    when(workspaceConfig.getEnvironments()).thenReturn(environments);
    MachineConfigDto devMachineConfig = mock(MachineConfigDto.class);
    when(devMachineConfig.getName()).thenReturn(MACHINE_NAME);
    workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
    workspaceEventsHandler.wsAgentLogSubscriptionHandler.onMessageReceived("");
    verify(eventBus).fireEvent(Matchers.<EnvironmentOutputEvent>anyObject());
}
Also used : WorkspaceRuntimeDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) HashMap(java.util.HashMap) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class FactoryBuilderTest method prepareFactory.

private static FactoryDto prepareFactory() {
    ProjectConfigDto project = dto.createDto(ProjectConfigDto.class).withSource(dto.createDto(SourceStorageDto.class).withType("git").withLocation("location")).withType("type").withAttributes(singletonMap("key", singletonList("value"))).withDescription("description").withName("name").withPath("/path");
    EnvironmentDto environment = dto.createDto(EnvironmentDto.class).withRecipe(newDto(EnvironmentRecipeDto.class).withType("compose").withContentType("application/x-yaml").withContent("some content")).withMachines(singletonMap("devmachine", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L))));
    WorkspaceConfigDto workspaceConfig = dto.createDto(WorkspaceConfigDto.class).withProjects(singletonList(project)).withCommands(singletonList(dto.createDto(CommandDto.class).withName("command1").withType("maven").withCommandLine("mvn test"))).withDefaultEnv("env1").withEnvironments(singletonMap("test", environment));
    IdeDto ide = dto.createDto(IdeDto.class).withOnAppClosed(dto.createDto(OnAppClosedDto.class).withActions(singletonList(dto.createDto(IdeActionDto.class).withId("warnOnClose")))).withOnAppLoaded(dto.createDto(OnAppLoadedDto.class).withActions(asList(dto.createDto(IdeActionDto.class).withId("newProject"), dto.createDto(IdeActionDto.class).withId("openWelcomePage").withProperties(ImmutableMap.of("authenticatedTitle", "Greeting title for authenticated users", "authenticatedContentUrl", "http://example.com/content.url"))))).withOnProjectsLoaded(dto.createDto(OnProjectsLoadedDto.class).withActions(asList(dto.createDto(IdeActionDto.class).withId("openFile").withProperties(singletonMap("file", "pom.xml")), dto.createDto(IdeActionDto.class).withId("run"), dto.createDto(IdeActionDto.class).withId("findReplace").withProperties(ImmutableMap.of("in", "src/main/resources/consts2.properties", "find", "OLD_VALUE_2", "replace", "NEW_VALUE_2", "replaceMode", "mode")))));
    return dto.createDto(FactoryDto.class).withV("4.0").withWorkspace(workspaceConfig).withCreator(dto.createDto(AuthorDto.class).withEmail("email").withName("name")).withPolicies(dto.createDto(PoliciesDto.class).withReferer("referrer").withSince(123L).withUntil(123L)).withButton(dto.createDto(ButtonDto.class).withType(Button.Type.LOGO).withAttributes(dto.createDto(ButtonAttributesDto.class).withColor("color").withCounter(true).withLogo("logo").withStyle("style"))).withIde(ide);
}
Also used : ButtonAttributesDto(org.eclipse.che.api.factory.shared.dto.ButtonAttributesDto) OnAppLoadedDto(org.eclipse.che.api.factory.shared.dto.OnAppLoadedDto) IdeDto(org.eclipse.che.api.factory.shared.dto.IdeDto) IdeActionDto(org.eclipse.che.api.factory.shared.dto.IdeActionDto) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)

Example 3 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto 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 EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class WorkspaceServiceTest method shouldAddEnvironment.

@Test
public void shouldAddEnvironment() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final EnvironmentDto envDto = createEnvDto();
    final int envsSizeBefore = workspace.getConfig().getEnvironments().size();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(envDto).when().queryParam("name", "new-env").post(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT).getConfig().getEnvironments().size(), envsSizeBefore + 1);
    verify(validator).validateConfig(workspace.getConfig());
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Test(org.testng.annotations.Test)

Example 5 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class CheEnvironmentValidatorTest method invalidEnvironmentProvider.

@DataProvider
public static Object[][] invalidEnvironmentProvider() {
    // InvalidEnvironmentObject | ExceptionMessage
    EnvironmentDto env;
    Map.Entry<String, ExtendedMachineDto> machineEntry;
    List<List<Object>> data = new ArrayList<>();
    data.add(asList(createEnv().withRecipe(null), "Environment recipe should not be null"));
    env = createEnv();
    env.getRecipe().setType("docker");
    data.add(asList(env, "Type 'docker' of environment 'env' is not supported. Supported types: compose"));
    env = createEnv();
    env.getRecipe().withLocation(null).withContent(null);
    data.add(asList(env, "Recipe of environment 'env' must contain location or content"));
    env = createEnv();
    env.getRecipe().withLocation("location").withContent("content");
    data.add(asList(env, "Recipe of environment 'env' contains mutually exclusive fields location and content"));
    env = createEnv();
    env.setMachines(null);
    data.add(asList(env, "Environment 'env' doesn't contain machine with 'org.eclipse.che.ws-agent' agent"));
    env = createEnv();
    env.setMachines(emptyMap());
    data.add(asList(env, "Environment 'env' doesn't contain machine with 'org.eclipse.che.ws-agent' agent"));
    env = createEnv();
    env.getMachines().put("missingInEnvMachine", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")));
    data.add(asList(env, "Environment 'env' contains machines that are missing in environment recipe: missingInEnvMachine"));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add("org.eclipse.che.ws-agent"));
    data.add(asList(env, "Environment 'env' should contain exactly 1 machine with agent 'org.eclipse.che.ws-agent', but contains '" + env.getMachines().size() + "'. " + "All machines with this agent: " + Joiner.on(", ").join(env.getMachines().keySet())));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().setAgents(null));
    data.add(asList(env, "Environment 'env' should contain exactly 1 machine with agent 'org.eclipse.che.ws-agent', but contains '0'. All machines with this agent: "));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add(null));
    data.add(asList(env, "Machine 'machine2' in environment 'env' contains invalid agent 'null'"));
    env = createEnv();
    env.getMachines().entrySet().forEach(entry -> entry.getValue().getAgents().add(""));
    data.add(asList(env, "Machine 'machine2' in environment 'env' contains invalid agent ''"));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", "0"));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", "-1"));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    env = createEnv();
    machineEntry = env.getMachines().entrySet().iterator().next();
    machineEntry.getValue().setAttributes(singletonMap("memoryLimitBytes", ""));
    data.add(asList(env, format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment 'env' is illegal", machineEntry.getKey())));
    return data.stream().map(list -> list.toArray(new Object[list.size()])).toArray(value -> new Object[data.size()][]);
}
Also used : Listeners(org.testng.annotations.Listeners) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConfDto(org.eclipse.che.api.machine.shared.dto.ServerConfDto) Mockito.spy(org.mockito.Mockito.spy) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Collections.singletonMap(java.util.Collections.singletonMap) InjectMocks(org.mockito.InjectMocks) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineSourceDto(org.eclipse.che.api.machine.shared.dto.MachineSourceDto) Collections.emptyList(java.util.Collections.emptyList) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Environment(org.eclipse.che.api.core.model.workspace.Environment) ServerException(org.eclipse.che.api.core.ServerException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Joiner(com.google.common.base.Joiner) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) DataProvider(org.testng.annotations.DataProvider)

Aggregations

EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)14 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)8 HashMap (java.util.HashMap)6 Test (org.testng.annotations.Test)6 ExtendedMachineDto (org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)5 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)4 Response (com.jayway.restassured.response.Response)3 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)3 EnvironmentRecipeDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Environment (org.eclipse.che.api.core.model.workspace.Environment)2 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)2 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)2 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)2 WorkspaceRuntimeDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto)2