Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/com/amihaiemil/docker/Images.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
* @version $Id$
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Image">Docker Images API</a>
* @since 0.0.1
* @todo #98:30min Continue implementing the rest of the operations for the
* Images interface. See the docs referenced above for more details.
* @todo #170:30min Continue implementing the rest of the operations for the
* Images interface. Already made the tests for import an image in
* RtImagesTestCase. See the docs referenced above for more details.
* @todo #152:30min Add Fake implementations of Images and Image, in order to
* unit test method save() and other future methods which may require more
* than 1 HTTP request. Currently, the unit testing infrastructure does
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/amihaiemil/docker/RtImagesTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
import com.amihaiemil.docker.mock.AssertRequest;
import com.amihaiemil.docker.mock.Condition;
import com.amihaiemil.docker.mock.Response;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;

import javax.json.Json;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand Down Expand Up @@ -240,4 +245,45 @@ public void returnsDocker() {
Matchers.is(DOCKER)
);
}

/**
* RtImages can import images successfully.
* @throws Exception If something goes wrong
*/
@Test
@Ignore
public void importImage() throws Exception{
new ListedImages(
new AssertRequest(
new Response(HttpStatus.SC_OK),
new Condition(
"import() must send a POST request",
req -> "POST".equals(req.getRequestLine().getMethod())
),
new Condition(
"import() resource URL must be '/images/load'",
req -> req.getRequestLine()
.getUri().endsWith("/images/load")
),
new Condition(
"import() body must contain a tar archive containing image",
req -> {
boolean condition = false;
try{
condition =
EntityUtils.toByteArray(
((HttpEntityEnclosingRequest) req)
.getEntity()
).length > 0;
} catch (final IOException error){
condition = false;
}
return condition;
}
)
),
URI.create("http://localhost"),
DOCKER
).importImage(new URL("http://localhost/images"), "docker-java-api");
}
}