Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dropped any troubleshooting help for the sake of assertThat

As requested
(+ 1 fixed log)
  • Loading branch information...
commit 6bf34d5305b229a50a65d58aed80d7326b886df9 1 parent 79433fc
@jakubholynet jakubholynet authored
View
3  restapp-bootstrap/src/main/java/org/cloudname/example/restapp/server/WebServer.java
@@ -118,8 +118,7 @@ public void start() {
try {
log.log(Level.INFO,
- "Starting " + serviceName + " server on port " + port + " ( http://0.0.0.0:" + port + " )",
- new Object[] { serviceName, port, port });
+ "Starting " + serviceName + " server on port " + port + " ( http://0.0.0.0:" + port + " )");
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
View
24 restapp-bootstrap/src/test/java/org/cloudname/example/restapp/rs/AbstractResourceTester.java
@@ -1,7 +1,5 @@
package org.cloudname.example.restapp.rs;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
@@ -16,7 +14,6 @@
import org.junit.Before;
import org.junit.BeforeClass;
-import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
@@ -99,25 +96,4 @@ public static void setupJerseyLog() throws Exception {
public final void setUp() throws Exception {
super.setUp();
}
-
- /**
- * Verify that the response's status is as expected, provide useful error message if not,
- * including the response body (that might carry some details of the failure).
- *
- * @param expectedStatus
- * (required) What status you expected; example: {@link Status#OK}
- * (Use JAX-RS' Response.Status, not the Jersey-specific ClientResponse.Status.)
- * @param actualResponse
- * (required) The response, from st. like
- * <code>{@code resource().path("exampleResource").get(ClientResponse.class);}</code>
- */
- public static void assertHttpStatus(final Status expectedStatus, final ClientResponse actualResponse) {
- int actualStatus = actualResponse.getStatus();
- if (actualStatus != expectedStatus.getStatusCode()) {
- String responseBody = actualResponse.getEntity(String.class);
- fail("Expected status " + expectedStatus.getStatusCode() + " but got " + actualStatus
- + "; response body: '" + responseBody + "'" + "\nheaders:" + actualResponse.getHeaders());
- }
-
- }
}
View
7 restapp-bootstrap/src/test/java/org/cloudname/example/restapp/rs/ExampleCollectionResourceIT.java
@@ -1,10 +1,11 @@
package org.cloudname.example.restapp.rs;
-import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import org.junit.Test;
-import javax.ws.rs.core.Response.Status;
import com.sun.jersey.api.client.ClientResponse;
/**
@@ -23,7 +24,7 @@ public void getWorks() throws Exception {
final ClientResponse response =
resource().path("/").get(ClientResponse.class);
- assertHttpStatus(Status.OK, response);
+ assertThat(response.getClientResponseStatus(), is(ClientResponse.Status.OK));
String responseBody = response.getEntity(String.class);
// Note: getEntity returns null in subsequent calls
View
12 restapp-bootstrap/src/test/java/org/cloudname/example/restapp/rs/ExampleSecuredResourceIT.java
@@ -1,11 +1,11 @@
package org.cloudname.example.restapp.rs;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
import java.io.IOException;
-import javax.ws.rs.core.Response.Status;
-
import org.cloudname.example.restapp.server.security.A3ClientInitializer;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -34,7 +34,7 @@ public void unahtorizedIfNoCredentials() throws Exception {
final ClientResponse response =
resource().path("/secure-resource").get(ClientResponse.class);
- assertHttpStatus(Status.UNAUTHORIZED, response);
+ assertThat(response.getClientResponseStatus(), is(ClientResponse.Status.UNAUTHORIZED));
}
@Test
@@ -45,7 +45,7 @@ public void unahtorizedIfWrongPassword() throws Exception {
final ClientResponse response =
resource().path("/secure-resource").get(ClientResponse.class);
- assertHttpStatus(Status.UNAUTHORIZED, response);
+ assertThat(response.getClientResponseStatus(), is(ClientResponse.Status.UNAUTHORIZED));
}
@Test
@@ -56,7 +56,7 @@ public void unahtorizedIfWrongRole() throws Exception {
final ClientResponse response =
resource().path("/secure-resource").get(ClientResponse.class);
- assertHttpStatus(Status.FORBIDDEN, response);
+ assertThat(response.getClientResponseStatus(), is(ClientResponse.Status.FORBIDDEN));
}
@Test
@@ -67,7 +67,7 @@ public void okIfGoodCredentials() throws Exception {
final ClientResponse response =
resource().path("/secure-resource").get(ClientResponse.class);
- assertHttpStatus(Status.OK, response);
+ assertThat(response.getClientResponseStatus(), is(ClientResponse.Status.OK));
String responseBody = response.getEntity(String.class);
Please sign in to comment.
Something went wrong with that request. Please try again.