Skip to content

Commit 27995f0

Browse files
committed
Merge branch '__rultor'
2 parents 6e97d29 + 3d242eb commit 27995f0

File tree

2 files changed

+62
-7
lines changed

2 files changed

+62
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.io.IOException;
3737
import java.net.URI;
3838
import java.util.Iterator;
39+
import javax.json.JsonObjectBuilder;
3940

4041
/**
4142
* Containers API.
@@ -117,8 +118,11 @@ public Container create(
117118
new MatchStatus(post.getURI(), HttpStatus.SC_CREATED)
118119
)
119120
);
121+
final JsonObjectBuilder contr = Json.createObjectBuilder();
122+
container.forEach(contr::add);
123+
json.forEach(contr::add);
120124
return new RtContainer(
121-
json,
125+
contr.build(),
122126
this.client,
123127
URI.create(
124128
this.baseUri.toString() + "/" + json.getString("Id")

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

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public void createsContainerOk()
136136
new RtContainers(
137137
new AssertRequest(
138138
new Response(
139-
HttpStatus.SC_CREATED, "{ \"Id\": \"df2419f4\" }"
139+
HttpStatus.SC_CREATED,
140+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
140141
),
141142
new Condition(
142143
"The 'Content-Type' header must be set.",
@@ -172,7 +173,7 @@ public void returnsCreatedContainer() throws Exception {
172173
new AssertRequest(
173174
new Response(
174175
HttpStatus.SC_CREATED,
175-
"{ \"Id\": \"df2419f4\" }"
176+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
176177
)
177178
), URI.create("http://localhost/test")
178179
).create("some_image"),
@@ -266,7 +267,8 @@ public void createsWithImageName() throws Exception {
266267
new RtContainers(
267268
new AssertRequest(
268269
new Response(
269-
HttpStatus.SC_CREATED, "{ \"Id\": \"df2419f4\" }"
270+
HttpStatus.SC_CREATED,
271+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
270272
),
271273
new Condition(
272274
"Resource path must be /create?name=some_name",
@@ -292,7 +294,8 @@ public void createsWithPayloadForCreateJson() throws Exception {
292294
new RtContainers(
293295
new AssertRequest(
294296
new Response(
295-
HttpStatus.SC_CREATED, "{ \"Id\": \"df2419f4\" }"
297+
HttpStatus.SC_CREATED,
298+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
296299
),
297300
new Condition(
298301
"Resource path must be /create",
@@ -327,7 +330,8 @@ public void createsWithPayloadForCreateNameAndJson() throws Exception {
327330
new RtContainers(
328331
new AssertRequest(
329332
new Response(
330-
HttpStatus.SC_CREATED, "{ \"Id\": \"df2419f4\" }"
333+
HttpStatus.SC_CREATED,
334+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
331335
),
332336
new Condition(
333337
"Resource path must be /create?name=image_name",
@@ -356,7 +360,10 @@ public void createsWithPayloadForCreateNameAndJson() throws Exception {
356360
public void createEscapesNameParameter() throws Exception {
357361
new RtContainers(
358362
new AssertRequest(
359-
new Response(HttpStatus.SC_CREATED, "{ \"Id\": \"df2419f4\" }"),
363+
new Response(
364+
HttpStatus.SC_CREATED,
365+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
366+
),
360367
new Condition(
361368
"RtContainers.create() must encode URL parameter",
362369
req -> req.getRequestLine()
@@ -366,4 +373,48 @@ public void createEscapesNameParameter() throws Exception {
366373
URI.create("http://localhost/docker")
367374
).create("Adrian Toomes", "some/image");
368375
}
376+
377+
/**
378+
* RtContainers.create() returns an RtContainer with the given parameter.
379+
* @throws Exception If something goes wrong.
380+
*/
381+
@Test
382+
public void createsContainerWithGivenParameters() throws Exception {
383+
MatcherAssert.assertThat(
384+
new RtContainers(
385+
new AssertRequest(
386+
new Response(
387+
HttpStatus.SC_CREATED,
388+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ]}"
389+
)
390+
), URI.create("http://localhost/test")
391+
).create(
392+
Json.createObjectBuilder()
393+
.add("Image", "ubuntu").build()
394+
).getString("Image"),
395+
Matchers.is("ubuntu")
396+
);
397+
}
398+
399+
/**
400+
* RtContainers.create() returns an RtContainer with the docker id.
401+
* @throws Exception If something goes wrong.
402+
*/
403+
@Test
404+
public void createsContainerWithId() throws Exception {
405+
MatcherAssert.assertThat(
406+
new RtContainers(
407+
new AssertRequest(
408+
new Response(
409+
HttpStatus.SC_CREATED,
410+
"{ \"Id\": \"df2419f4\", \"Warnings\": [ ] }"
411+
)
412+
), URI.create("http://localhost/test")
413+
).create(
414+
Json.createObjectBuilder()
415+
.add("Image", "ubuntu").build()
416+
).getString("Id"),
417+
Matchers.is("df2419f4")
418+
);
419+
}
369420
}

0 commit comments

Comments
 (0)