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