Skip to content
Browse files

Use global HTTP status code when no specific code is defined on a method

  • Loading branch information...
1 parent ee89322 commit 8f14c2d0ecdd9bdb8c75897f00d37a1ae5af27b6 @dadoonet dadoonet committed
View
4 src/main/java/net/linkfluence/jspore/Spore.java
@@ -105,7 +105,9 @@ private Method getMethod(String methodName) throws SporeException {
// response checking
int statusCode = res.getStatusCode();
if(!context.expectedStatus.isEmpty() && !context.expectedStatus.contains(statusCode)){
- throw new SporeException("Receive unexpected response status: " + statusCode);
+ String errorContent = res.getResponseBody();
+ throw new SporeException("Receive unexpected response status: " + statusCode
+ + ", message: " + errorContent);
}
if(this.responseMiddleware != null){
View
34 src/test/java/net/linkfluence/jspore/GitHubPrivateTest.java
@@ -30,33 +30,37 @@
private static Logger logger = LoggerFactory.getLogger(GitHubPrivateTest.class);
private static final String USERNAME = "nicoo";
- private static final String PASS = "xxxxxx";
+ private static final String PASS = "YOUHAVETOCHANGETHISPASSWORD";
- private final Spore<JsonNode> spore;
-
- public GitHubPrivateTest() throws FileNotFoundException, IOException, InvalidSporeSpecException {
+ private Spore<JsonNode> buildSpore(String login, String password) throws IOException, InvalidSporeSpecException {
URL url = this.getClass().getResource("/github.json");
File spec = new File(url.getFile());
- spore = new Spore.Builder<JsonNode>()
+ return new Spore.Builder<JsonNode>()
.addMiddleware(Spore.JSON)
- .addMiddleware(new Basic(USERNAME, PASS))
+ .addMiddleware(new Basic(login, password))
.addSpecContent(spec)
.setDebug(true)
.build();
}
@Test
- public void test_get_profile() throws SporeException {
- SporeResult<JsonNode> result = spore.call("get_profile",
- new ImmutableMap.Builder<String, String>()
- .build());
- JsonNode message = result.body.get("message");
- if (message != null) {
- assertEquals("Bad credentials", message.asText());
- logger.warn("You did not set USERNAME and PASS in GitHubPrivateTest class. So Github answers 'Bad credentials'.");
- } else {
+ public void test_get_profile() throws Exception {
+ SporeResult<JsonNode> result = null;
+ try {
+ result = buildSpore(USERNAME, PASS).call("get_profile",
+ new ImmutableMap.Builder<String, String>()
+ .build());
assertEquals("User", result.body.get("type").asText());
+ } catch (SporeException e) {
+ logger.warn("You did not set USERNAME and PASS in GitHubPrivateTest class. So Github answers 'Bad credentials'.", e);
}
}
+
+ @Test(expected = SporeException.class)
+ public void test_bad_credentials() throws Exception {
+ buildSpore(USERNAME, "BADPASSWORD").call("get_profile",
+ new ImmutableMap.Builder<String, String>()
+ .build());
+ }
}

0 comments on commit 8f14c2d

Please sign in to comment.
Something went wrong with that request. Please try again.