|
28 | 28 | import com.amihaiemil.docker.mock.AssertRequest; |
29 | 29 | import com.amihaiemil.docker.mock.Condition; |
30 | 30 | import com.amihaiemil.docker.mock.Response; |
| 31 | +import org.apache.http.HttpEntityEnclosingRequest; |
31 | 32 | import org.apache.http.HttpStatus; |
| 33 | +import org.apache.http.util.EntityUtils; |
32 | 34 | import org.hamcrest.MatcherAssert; |
33 | 35 | import org.hamcrest.Matchers; |
| 36 | +import org.junit.Ignore; |
34 | 37 | import org.junit.Test; |
35 | 38 | import org.mockito.Mockito; |
36 | 39 |
|
37 | 40 | import javax.json.Json; |
| 41 | +import java.io.IOException; |
38 | 42 | import java.net.URI; |
| 43 | +import java.net.URL; |
39 | 44 | import java.util.concurrent.atomic.AtomicInteger; |
40 | 45 |
|
41 | 46 | /** |
@@ -240,4 +245,45 @@ public void returnsDocker() { |
240 | 245 | Matchers.is(DOCKER) |
241 | 246 | ); |
242 | 247 | } |
| 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 | + } |
243 | 289 | } |
0 commit comments