Search in sources :

Example 1 with DisconnectContainerFromNetworkParams

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

the class DockerConnectorTest method shouldThrowExceptionOnDisconnectFromNetworkIfResponseCodeIsNot20x.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = "Error response from docker API, status: 404, message: exc_message")
public void shouldThrowExceptionOnDisconnectFromNetworkIfResponseCodeIsNot20x() throws Exception {
    // given
    doReturn(404).when(dockerResponse).getStatus();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("exc_message".getBytes());
    doReturn(inputStream).when(dockerResponse).getInputStream();
    DisconnectContainerFromNetworkParams disconnectFromNetworkParams = DisconnectContainerFromNetworkParams.create("net_id", new DisconnectContainer().withContainer("container_id").withForce(true));
    // when
    dockerConnector.disconnectContainerFromNetwork(disconnectFromNetworkParams);
}
Also used : DisconnectContainerFromNetworkParams(org.eclipse.che.plugin.docker.client.params.network.DisconnectContainerFromNetworkParams) ByteArrayInputStream(java.io.ByteArrayInputStream) DisconnectContainer(org.eclipse.che.plugin.docker.client.json.network.DisconnectContainer) Test(org.testng.annotations.Test)

Example 2 with DisconnectContainerFromNetworkParams

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

the class DockerConnectorTest method shouldBeAbleToDisconnectContainerFromNetworkWithParams.

@Test
public void shouldBeAbleToDisconnectContainerFromNetworkWithParams() throws Exception {
    // given
    String netId = "net_id";
    DisconnectContainerFromNetworkParams disconnectFromNetworkParams = DisconnectContainerFromNetworkParams.create(netId, new DisconnectContainer().withContainer("container_id").withForce(true));
    // when
    dockerConnector.disconnectContainerFromNetwork(disconnectFromNetworkParams);
    // then
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/networks/" + netId + "/disconnect");
    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(disconnectFromNetworkParams.getDisconnectContainer()).getBytes());
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
}
Also used : DisconnectContainerFromNetworkParams(org.eclipse.che.plugin.docker.client.params.network.DisconnectContainerFromNetworkParams) DisconnectContainer(org.eclipse.che.plugin.docker.client.json.network.DisconnectContainer) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

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