Search in sources :

Example 1 with ConnectContainerToNetworkParams

use of org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams in project che by eclipse.

the class DockerConnectorTest method shouldThrowExceptionOnConnectToNetworkIfResponseCodeIsNot20x.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = "Error response from docker API, status: 404, message: exc_message")
public void shouldThrowExceptionOnConnectToNetworkIfResponseCodeIsNot20x() throws Exception {
    // given
    doReturn(404).when(dockerResponse).getStatus();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("exc_message".getBytes());
    doReturn(inputStream).when(dockerResponse).getInputStream();
    ConnectContainerToNetworkParams connectToNetworkParams = ConnectContainerToNetworkParams.create("net_id", createConnectContainer());
    // when
    dockerConnector.connectContainerToNetwork(connectToNetworkParams);
}
Also used : ConnectContainerToNetworkParams(org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.testng.annotations.Test)

Example 2 with ConnectContainerToNetworkParams

use of org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToConnectContainerToNetworkWithParams.

@Test
public void shouldBeAbleToConnectContainerToNetworkWithParams() throws Exception {
    // given
    String netId = "net_id";
    ConnectContainerToNetworkParams connectToNetworkParams = ConnectContainerToNetworkParams.create(netId, createConnectContainer());
    // when
    dockerConnector.connectContainerToNetwork(connectToNetworkParams);
    // then
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/networks/" + netId + "/connect");
    verify(dockerConnection).header("Content-Type", MediaType.APPLICATION_JSON);
    verify(dockerConnection).header(eq("Content-Length"), anyInt());
    ArgumentCaptor<byte[]> argumentCaptor = ArgumentCaptor.forClass(byte[].class);
    verify(dockerConnection).entity(argumentCaptor.capture());
    assertEquals(argumentCaptor.getValue(), GSON.toJson(connectToNetworkParams.getConnectContainer()).getBytes());
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
}
Also used : ConnectContainerToNetworkParams(org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

ConnectContainerToNetworkParams (org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams)2 Test (org.testng.annotations.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 Matchers.anyString (org.mockito.Matchers.anyString)1