Skip to content

Commit

Permalink
added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ry99 committed Apr 2, 2020
1 parent 8591519 commit 5a6b1cc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/docker/Container.java
Expand Up @@ -161,7 +161,7 @@ void remove(final boolean volumes, final boolean force, final boolean link)
* Wait Container</a>.
* @throws IOException If something goes wrong.
* the expected one (200).
* @return the exit code of the container
* @return The exit code of the container
*/
int waitOn(String state) throws IOException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/docker/RtContainer.java
Expand Up @@ -237,7 +237,7 @@ public int waitOn(final String state) throws IOException {
UncheckedUriBuilder urib = new UncheckedUriBuilder(
this.baseUri.toString().concat("/wait")
);
if(null == state || state.isEmpty()){
if(!(null == state || state.isEmpty())){
urib.addParameter("condition", state);
}

Expand Down
79 changes: 79 additions & 0 deletions src/test/java/com/amihaiemil/docker/RtContainerTestCase.java
Expand Up @@ -37,6 +37,7 @@
import javax.json.Json;
import javax.json.JsonObject;
import java.net.URI;
import static org.junit.Assert.assertEquals;

/**
* Unit tests for RtContainer.
Expand Down Expand Up @@ -627,4 +628,82 @@ public void getsLogs() {
Matchers.notNullValue()
);
}

/**
* RtContainer can wait with no problem.
* @throws Exception If something goes wrong.
*/
@Test
public void waitsOk() throws Exception {
int retval = new RtContainer(
Json.createObjectBuilder().add("Id", "123").build(),
new AssertRequest(
new Response(
HttpStatus.SC_OK,
Json.createObjectBuilder()
.add("StatusCode", 0)
.build().toString()
),
new Condition(
"Method should be a POST",
req -> req.getRequestLine().getMethod().equals("POST")
),
new Condition(
"Resource path must be /123/wait",
req -> req.getRequestLine().getUri().endsWith("/wait")
)
),
URI.create("http://localhost:80/1.30/containers/123"),
Mockito.mock(Docker.class)
).waitOn(null);
assertEquals(0, retval);
}

/**
* RtContainer can wait with a condition.
* @throws Exception If something goes wrong.
*/
@Test
public void waitsOkWithCondition() throws Exception {
int retval = new RtContainer(
Json.createObjectBuilder().add("Id", "123").build(),
new AssertRequest(
new Response(
HttpStatus.SC_OK,
Json.createObjectBuilder()
.add("StatusCode", 0)
.build().toString()
),
new Condition(
"Method should be a POST",
req -> req.getRequestLine().getMethod().equals("POST")
),
new Condition(
"Resource path must be /123/wait",
req -> req.getRequestLine().getUri().endsWith("ition=next-exit")
)
),
URI.create("http://localhost:80/1.30/containers/123"),
Mockito.mock(Docker.class)
).waitOn("next-exit");
assertEquals(0, retval);
}

/**
* RtContainer throws URE if it receives a server error on remove.
* @throws Exception If something goes wrong.
*/
@Test(expected = UnexpectedResponseException.class)
public void waitWithServerError() throws Exception {
new RtContainer(
Json.createObjectBuilder().build(),
new AssertRequest(
new Response(
HttpStatus.SC_INTERNAL_SERVER_ERROR
)
),
URI.create("http://localhost:80/1.30/containers/123"),
Mockito.mock(Docker.class)
).waitOn(null);
}
}

0 comments on commit 5a6b1cc

Please sign in to comment.