Search in sources :

Example 1 with URLRewriter

use of org.eclipse.che.api.workspace.server.URLRewriter in project devspaces-images by redhat-developer.

the class InternalRuntimeTest method shouldAddAWarningInsteadOfAServerIfURLRewritingFailed.

@Test
public void shouldAddAWarningInsteadOfAServerIfURLRewritingFailed() throws Exception {
    // given
    URLRewriter urlRewriter = spy(new URLRewriter.NoOpURLRewriter());
    setRunningRuntime(urlRewriter);
    Map<String, MachineImpl> expectedMachines = new HashMap<>();
    Map<String, MachineImpl> internalMachines = new HashMap<>();
    MachineImpl machine1 = createMachine();
    MachineImpl machine2 = createMachine();
    HashMap<String, ServerImpl> expectedServers = new HashMap<>(machine1.getServers());
    String badServerName = "badServer";
    String badServerURL = "ws://failing-rewriting:8000";
    String badServerRewritingExcMessage = "test exc";
    ServerImpl failingRewritingServer = createServer(badServerURL);
    machine1.getServers().put(badServerName, failingRewritingServer);
    internalMachines.put("m1", machine1);
    internalMachines.put("m2", machine2);
    expectedMachines.put("m1", new MachineImpl(machine1.getAttributes(), expectedServers, machine1.getStatus()));
    expectedMachines.put("m2", machine2);
    List<WarningImpl> expectedWarnings = new ArrayList<>();
    expectedWarnings.add(new WarningImpl(InternalRuntime.MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + badServerName + " : " + badServerRewritingExcMessage));
    doReturn(internalMachines).when(internalRuntime).getInternalMachines();
    doThrow(new InfrastructureException(badServerRewritingExcMessage)).when(urlRewriter).rewriteURL(any(RuntimeIdentity.class), any(), anyString(), eq(badServerURL));
    // when
    Map<String, ? extends Machine> actualMachines = internalRuntime.getMachines();
    List<? extends Warning> actualWarnings = internalRuntime.getWarnings();
    // then
    assertEquals(actualMachines, expectedMachines);
    assertEquals(actualWarnings, expectedWarnings);
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) URLRewriter(org.eclipse.che.api.workspace.server.URLRewriter) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Test(org.testng.annotations.Test)

Example 2 with URLRewriter

use of org.eclipse.che.api.workspace.server.URLRewriter in project che-server by eclipse-che.

the class InternalRuntimeTest method shouldAddAWarningInsteadOfAServerIfURLRewritingFailed.

@Test
public void shouldAddAWarningInsteadOfAServerIfURLRewritingFailed() throws Exception {
    // given
    URLRewriter urlRewriter = spy(new URLRewriter.NoOpURLRewriter());
    setRunningRuntime(urlRewriter);
    Map<String, MachineImpl> expectedMachines = new HashMap<>();
    Map<String, MachineImpl> internalMachines = new HashMap<>();
    MachineImpl machine1 = createMachine();
    MachineImpl machine2 = createMachine();
    HashMap<String, ServerImpl> expectedServers = new HashMap<>(machine1.getServers());
    String badServerName = "badServer";
    String badServerURL = "ws://failing-rewriting:8000";
    String badServerRewritingExcMessage = "test exc";
    ServerImpl failingRewritingServer = createServer(badServerURL);
    machine1.getServers().put(badServerName, failingRewritingServer);
    internalMachines.put("m1", machine1);
    internalMachines.put("m2", machine2);
    expectedMachines.put("m1", new MachineImpl(machine1.getAttributes(), expectedServers, machine1.getStatus()));
    expectedMachines.put("m2", machine2);
    List<WarningImpl> expectedWarnings = new ArrayList<>();
    expectedWarnings.add(new WarningImpl(InternalRuntime.MALFORMED_SERVER_URL_FOUND, "Malformed URL for " + badServerName + " : " + badServerRewritingExcMessage));
    doReturn(internalMachines).when(internalRuntime).getInternalMachines();
    doThrow(new InfrastructureException(badServerRewritingExcMessage)).when(urlRewriter).rewriteURL(any(RuntimeIdentity.class), any(), anyString(), eq(badServerURL));
    // when
    Map<String, ? extends Machine> actualMachines = internalRuntime.getMachines();
    List<? extends Warning> actualWarnings = internalRuntime.getWarnings();
    // then
    assertEquals(actualMachines, expectedMachines);
    assertEquals(actualWarnings, expectedWarnings);
}
Also used : MachineImpl(org.eclipse.che.api.workspace.server.model.impl.MachineImpl) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) URLRewriter(org.eclipse.che.api.workspace.server.URLRewriter) ServerImpl(org.eclipse.che.api.workspace.server.model.impl.ServerImpl) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)2 URLRewriter (org.eclipse.che.api.workspace.server.URLRewriter)2 MachineImpl (org.eclipse.che.api.workspace.server.model.impl.MachineImpl)2 ServerImpl (org.eclipse.che.api.workspace.server.model.impl.ServerImpl)2 WarningImpl (org.eclipse.che.api.workspace.server.model.impl.WarningImpl)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Test (org.testng.annotations.Test)2