Search in sources :

Example 1 with CreateNetworkParams

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

the class DockerConnectorTest method shouldThrowExceptionOnCreateNetworkIfResponseCodeIsNot20x.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = "Error response from docker API, status: 404, message: exc_message")
public void shouldThrowExceptionOnCreateNetworkIfResponseCodeIsNot20x() throws Exception {
    // given
    doReturn(404).when(dockerResponse).getStatus();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("exc_message".getBytes());
    doReturn(inputStream).when(dockerResponse).getInputStream();
    CreateNetworkParams createNetworkParams = CreateNetworkParams.create(createNewNetwork());
    // when
    dockerConnector.createNetwork(createNetworkParams);
}
Also used : CreateNetworkParams(org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.testng.annotations.Test)

Example 2 with CreateNetworkParams

use of org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams 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)2 CreateNetworkParams (org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams)2 Test (org.testng.annotations.Test)2 URI (java.net.URI)1 NetworkCreated (org.eclipse.che.plugin.docker.client.json.NetworkCreated)1