Search in sources :

Example 1 with PutResourceParams

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

the class DockerConnectorTest method shouldProduceErrorWhenPutsResourcesIntoContainerIfResponseCodeIsNotSuccess.

@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldProduceErrorWhenPutsResourcesIntoContainerIfResponseCodeIsNotSuccess() throws IOException {
    InputStream source = new CloseConnectionInputStream(new ByteArrayInputStream(ERROR_MESSAGE.getBytes()), dockerConnection);
    PutResourceParams putResourceParams = PutResourceParams.create(CONTAINER, PATH_TO_FILE, source);
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
    when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(ERROR_MESSAGE.getBytes()));
    dockerConnector.putResource(putResourceParams);
    verify(dockerResponse).getStatus();
}
Also used : CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) PutResourceParams(org.eclipse.che.plugin.docker.client.params.PutResourceParams) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) InputStream(java.io.InputStream) Test(org.testng.annotations.Test)

Example 2 with PutResourceParams

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

the class DockerConnectorTest method shouldBeAbleToPutResourcesIntoContainer.

@Test
public void shouldBeAbleToPutResourcesIntoContainer() throws IOException {
    InputStream source = new CloseConnectionInputStream(new ByteArrayInputStream(STREAM_DATA_BYTES), dockerConnection);
    PutResourceParams putResourceParams = PutResourceParams.create(CONTAINER, PATH_TO_FILE, source);
    dockerConnector.putResource(putResourceParams);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_PUT);
    verify(dockerConnection).path("/containers/" + putResourceParams.getContainer() + "/archive");
    verify(dockerConnection).query(eq("path"), eq(PATH_TO_FILE));
    verify(dockerConnection).header("Content-Type", ExtMediaType.APPLICATION_X_TAR);
    verify(dockerConnection).header(eq("Content-Length"), anyInt());
    verify(dockerConnection).entity(any(InputStream.class));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
}
Also used : CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) PutResourceParams(org.eclipse.che.plugin.docker.client.params.PutResourceParams) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) InputStream(java.io.InputStream) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)2 PutResourceParams (org.eclipse.che.plugin.docker.client.params.PutResourceParams)2 Test (org.testng.annotations.Test)2 URI (java.net.URI)1