Search in sources :

Example 1 with CommitParams

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

the class DockerConnectorTest method shouldBeAbleToCommitImage.

@Test
public void shouldBeAbleToCommitImage() throws IOException, JsonParseException {
    CommitParams commitParams = CommitParams.create(CONTAINER).withRepository(REPOSITORY);
    ContainerCommitted containerCommitted = mock(ContainerCommitted.class);
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_CREATED_CODE);
    when(containerCommitted.getId()).thenReturn(IMAGE);
    doReturn(containerCommitted).when(dockerConnector).parseResponseStreamAndClose(inputStream, ContainerCommitted.class);
    String returnedImage = dockerConnector.commit(commitParams);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/commit");
    verify(dockerConnection).query("container", commitParams.getContainer());
    verify(dockerConnection).query("repo", commitParams.getRepository());
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
    assertEquals(returnedImage, IMAGE);
}
Also used : ContainerCommitted(org.eclipse.che.plugin.docker.client.json.ContainerCommitted) CommitParams(org.eclipse.che.plugin.docker.client.params.CommitParams) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with CommitParams

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

the class DockerConnectorTest method shouldThrowDockerExceptionWhileCommittingImageIfResponseCodeIsNotSuccess.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhileCommittingImageIfResponseCodeIsNotSuccess() throws IOException {
    CommitParams commitParams = CommitParams.create(CONTAINER).withRepository(REPOSITORY);
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
    dockerConnector.commit(commitParams);
    verify(dockerResponse).getStatus();
}
Also used : CommitParams(org.eclipse.che.plugin.docker.client.params.CommitParams) Test(org.testng.annotations.Test)

Aggregations

CommitParams (org.eclipse.che.plugin.docker.client.params.CommitParams)2 Test (org.testng.annotations.Test)2 URI (java.net.URI)1 ContainerCommitted (org.eclipse.che.plugin.docker.client.json.ContainerCommitted)1 Matchers.anyString (org.mockito.Matchers.anyString)1