Search in sources :

Example 1 with NetworkCreated

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

the class DockerConnectorTest method shouldBeAbleToCreateNetwork.

@Test
public void shouldBeAbleToCreateNetwork() throws Exception {
    // given
    CreateNetworkParams createNetworkParams = CreateNetworkParams.create(createNewNetwork());
    NetworkCreated originNetworkCreated = new NetworkCreated().withId("some_id").withWarning("some_warning");
    ByteArrayInputStream inputStream = new ByteArrayInputStream(GSON.toJson(originNetworkCreated).getBytes());
    doReturn(inputStream).when(dockerResponse).getInputStream();
    // when
    NetworkCreated networkCreated = dockerConnector.createNetwork(createNetworkParams);
    // then
    assertEquals(networkCreated, originNetworkCreated);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/networks/create");
    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(createNetworkParams.getNetwork()).getBytes());
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
}
Also used : CreateNetworkParams(org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams) NetworkCreated(org.eclipse.che.plugin.docker.client.json.NetworkCreated) ByteArrayInputStream(java.io.ByteArrayInputStream) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 URI (java.net.URI)1 NetworkCreated (org.eclipse.che.plugin.docker.client.json.NetworkCreated)1 CreateNetworkParams (org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams)1 Test (org.testng.annotations.Test)1