Search in sources :

Example 1 with TERMINAL_REFERENCE

use of org.eclipse.che.api.machine.shared.Constants.TERMINAL_REFERENCE in project che by eclipse.

the class MachineServiceLinksInjectorTest method shouldInjectLinksIntoMachineDto.

@Test
public void shouldInjectLinksIntoMachineDto() {
    when(terminalServerMock.getRef()).thenReturn(TERMINAL_REFERENCE);
    when(terminalServerMock.getUrl()).thenReturn(URI_BASE + "/pty");
    when(execAgentServerMock.getRef()).thenReturn(EXEC_AGENT_REFERENCE);
    when(execAgentServerMock.getUrl()).thenReturn(URI_BASE + "/connect");
    when(machineRuntimeInfoDtoMock.getServers()).thenReturn(ImmutableMap.of(TERMINAL_REFERENCE, terminalServerMock, EXEC_AGENT_REFERENCE, execAgentServerMock));
    final MachineDto machineDto = DtoFactory.newDto(MachineDto.class).withId("id").withWorkspaceId("wsId").withConfig(machineConfigDtoMock).withRuntime(machineRuntimeInfoDtoMock);
    machineLinksInjector.injectLinks(machineDto, serviceContextMock);
    final Set<Pair<String, String>> links = machineDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
    final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", TERMINAL_REFERENCE), Pair.of("GET", EXEC_AGENT_REFERENCE), Pair.of("GET", LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL), Pair.of("GET", ENVIRONMENT_STATUS_CHANNEL_TEMPLATE)));
    assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Also used : Listeners(org.testng.annotations.Listeners) ServiceContext(org.eclipse.che.api.core.rest.ServiceContext) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) EXEC_AGENT_REFERENCE(org.eclipse.che.api.machine.shared.Constants.EXEC_AGENT_REFERENCE) ServerDto(org.eclipse.che.api.machine.shared.dto.ServerDto) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) HashSet(java.util.HashSet) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) Arrays.asList(java.util.Arrays.asList) UriBuilder(javax.ws.rs.core.UriBuilder) DtoFactory(org.eclipse.che.dto.server.DtoFactory) LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL(org.eclipse.che.api.machine.shared.Constants.LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) TERMINAL_REFERENCE(org.eclipse.che.api.machine.shared.Constants.TERMINAL_REFERENCE) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Pair(org.eclipse.che.commons.lang.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MachineRuntimeInfoDto(org.eclipse.che.api.machine.shared.dto.MachineRuntimeInfoDto) ENVIRONMENT_STATUS_CHANNEL_TEMPLATE(org.eclipse.che.api.machine.shared.Constants.ENVIRONMENT_STATUS_CHANNEL_TEMPLATE) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) Pair(org.eclipse.che.commons.lang.Pair) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 ServiceContext (org.eclipse.che.api.core.rest.ServiceContext)1 ENVIRONMENT_STATUS_CHANNEL_TEMPLATE (org.eclipse.che.api.machine.shared.Constants.ENVIRONMENT_STATUS_CHANNEL_TEMPLATE)1 EXEC_AGENT_REFERENCE (org.eclipse.che.api.machine.shared.Constants.EXEC_AGENT_REFERENCE)1 LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL (org.eclipse.che.api.machine.shared.Constants.LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL)1 TERMINAL_REFERENCE (org.eclipse.che.api.machine.shared.Constants.TERMINAL_REFERENCE)1 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)1 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 MachineRuntimeInfoDto (org.eclipse.che.api.machine.shared.dto.MachineRuntimeInfoDto)1 ServerDto (org.eclipse.che.api.machine.shared.dto.ServerDto)1 Pair (org.eclipse.che.commons.lang.Pair)1 DtoFactory (org.eclipse.che.dto.server.DtoFactory)1 UriBuilderImpl (org.everrest.core.impl.uri.UriBuilderImpl)1 Mock (org.mockito.Mock)1