Search in sources :

Example 1 with DisconnectContainer

use of org.eclipse.che.plugin.docker.client.json.network.DisconnectContainer 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 DisconnectContainer

use of org.eclipse.che.plugin.docker.client.json.network.DisconnectContainer in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToDisconnectContainerFromNetwork.

@Test
public void shouldBeAbleToDisconnectContainerFromNetwork() throws Exception {
    // given
    String netId = "net_id";
    String containerId = "container_id";
    doNothing().when(dockerConnector).disconnectContainerFromNetwork(any(DisconnectContainerFromNetworkParams.class));
    // when
    dockerConnector.disconnectContainerFromNetwork(netId, containerId);
    // then
    verify(dockerConnector).disconnectContainerFromNetwork(DisconnectContainerFromNetworkParams.create(netId, new DisconnectContainer().withContainer(containerId)));
}
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) Test(org.testng.annotations.Test)

Example 3 with DisconnectContainer

use of org.eclipse.che.plugin.docker.client.json.network.DisconnectContainer 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)3 DisconnectContainerFromNetworkParams (org.eclipse.che.plugin.docker.client.params.network.DisconnectContainerFromNetworkParams)3 Test (org.testng.annotations.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1