diff --git a/src/main/java/com/amihaiemil/docker/Images.java b/src/main/java/com/amihaiemil/docker/Images.java index d2dae2c3..36398c0d 100644 --- a/src/main/java/com/amihaiemil/docker/Images.java +++ b/src/main/java/com/amihaiemil/docker/Images.java @@ -36,8 +36,9 @@ * @version $Id$ * @see Docker Images API * @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 diff --git a/src/test/java/com/amihaiemil/docker/RtImagesTestCase.java b/src/test/java/com/amihaiemil/docker/RtImagesTestCase.java index 67434c3b..5ca39cab 100644 --- a/src/test/java/com/amihaiemil/docker/RtImagesTestCase.java +++ b/src/test/java/com/amihaiemil/docker/RtImagesTestCase.java @@ -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; /** @@ -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"); + } }