Search in sources :

Example 1 with GetResourceParams

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

the class DockerConnectorTest method shouldProduceErrorWhenGetsResourcesFromContainerIfResponseCodeIsNotSuccess.

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

Example 2 with GetResourceParams

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

the class DockerConnectorTest method shouldBeAbleToGetResourcesFromContainer.

@Test
public void shouldBeAbleToGetResourcesFromContainer() throws IOException {
    GetResourceParams getResourceParams = GetResourceParams.create(CONTAINER, PATH_TO_FILE);
    when(dockerResponse.getInputStream()).thenReturn(new CloseConnectionInputStream(new ByteArrayInputStream(STREAM_DATA_BYTES), dockerConnection));
    String response = CharStreams.toString(new InputStreamReader(dockerConnector.getResource(getResourceParams)));
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_GET);
    verify(dockerConnection).path("/containers/" + getResourceParams.getContainer() + "/archive");
    verify(dockerConnection).query(eq("path"), eq(PATH_TO_FILE));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
    assertEquals(response, STREAM_DATA);
}
Also used : CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) GetResourceParams(org.eclipse.che.plugin.docker.client.params.GetResourceParams) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)2 GetResourceParams (org.eclipse.che.plugin.docker.client.params.GetResourceParams)2 Test (org.testng.annotations.Test)2 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 Matchers.anyString (org.mockito.Matchers.anyString)1