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