Skip to content

Commit 91e4e75

Browse files
authored
Merge pull request #249 from paulodamaso/170
For #170: Added tests to Images.import
2 parents 9197cdb + df37ace commit 91e4e75

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/main/java/com/amihaiemil/docker/Images.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
* @version $Id$
3737
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Image">Docker Images API</a>
3838
* @since 0.0.1
39-
* @todo #98:30min Continue implementing the rest of the operations for the
40-
* Images interface. See the docs referenced above for more details.
39+
* @todo #170:30min Continue implementing the rest of the operations for the
40+
* Images interface. Already made the tests for import an image in
41+
* RtImagesTestCase. See the docs referenced above for more details.
4142
* @todo #152:30min Add Fake implementations of Images and Image, in order to
4243
* unit test method save() and other future methods which may require more
4344
* than 1 HTTP request. Currently, the unit testing infrastructure does

src/test/java/com/amihaiemil/docker/RtImagesTestCase.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@
2828
import com.amihaiemil.docker.mock.AssertRequest;
2929
import com.amihaiemil.docker.mock.Condition;
3030
import com.amihaiemil.docker.mock.Response;
31+
import org.apache.http.HttpEntityEnclosingRequest;
3132
import org.apache.http.HttpStatus;
33+
import org.apache.http.util.EntityUtils;
3234
import org.hamcrest.MatcherAssert;
3335
import org.hamcrest.Matchers;
36+
import org.junit.Ignore;
3437
import org.junit.Test;
3538
import org.mockito.Mockito;
3639

3740
import javax.json.Json;
41+
import java.io.IOException;
3842
import java.net.URI;
43+
import java.net.URL;
3944
import java.util.concurrent.atomic.AtomicInteger;
4045

4146
/**
@@ -240,4 +245,45 @@ public void returnsDocker() {
240245
Matchers.is(DOCKER)
241246
);
242247
}
248+
249+
/**
250+
* RtImages can import images successfully.
251+
* @throws Exception If something goes wrong
252+
*/
253+
@Test
254+
@Ignore
255+
public void importImage() throws Exception{
256+
new ListedImages(
257+
new AssertRequest(
258+
new Response(HttpStatus.SC_OK),
259+
new Condition(
260+
"import() must send a POST request",
261+
req -> "POST".equals(req.getRequestLine().getMethod())
262+
),
263+
new Condition(
264+
"import() resource URL must be '/images/load'",
265+
req -> req.getRequestLine()
266+
.getUri().endsWith("/images/load")
267+
),
268+
new Condition(
269+
"import() body must contain a tar archive containing image",
270+
req -> {
271+
boolean condition = false;
272+
try{
273+
condition =
274+
EntityUtils.toByteArray(
275+
((HttpEntityEnclosingRequest) req)
276+
.getEntity()
277+
).length > 0;
278+
} catch (final IOException error){
279+
condition = false;
280+
}
281+
return condition;
282+
}
283+
)
284+
),
285+
URI.create("http://localhost"),
286+
DOCKER
287+
).importImage(new URL("http://localhost/images"), "docker-java-api");
288+
}
243289
}

0 commit comments

Comments
 (0)