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);
}
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();
}
Aggregations