use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testServiceUnavailable.
/**
* Test HTTP status code 503 (ServiceUnavailable) error response.
*/
@Test
public void testServiceUnavailable() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(503).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof ServiceUnavailableException);
ServiceUnavailableException ex = (ServiceUnavailableException) e;
assertEquals(503, ex.getStatusCode());
assertEquals(message, ex.getMessage());
}
}
use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testInternalServerError.
/**
* Test HTTP status code 500 (InternalServerError) error response.
*/
@Test
public void testInternalServerError() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(500).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof InternalServerErrorException);
InternalServerErrorException ex = (InternalServerErrorException) e;
assertEquals(500, ex.getStatusCode());
assertEquals(message, ex.getMessage());
}
}
use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testUnsupported.
/**
* Test HTTP status code 415 (Unsupported Media Type) error response.
*/
@Test
public void testUnsupported() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(415).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof UnsupportedException);
UnsupportedException ex = (UnsupportedException) e;
assertEquals(415, ex.getStatusCode());
assertEquals(message, ex.getMessage());
}
}
use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testBadRequest.
/**
* Test HTTP status code 400 (Bad Request) error response.
*/
@Test
public void testBadRequest() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(400).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof BadRequestException);
BadRequestException ex = (BadRequestException) e;
assertEquals(400, ex.getStatusCode());
assertEquals(message, ex.getMessage());
}
}
use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.
the class ErrorResponseTest method testUnauthorized.
/**
* Test HTTP status code 401 (Unauthorized) error response.
*/
@Test
public void testUnauthorized() {
String message = "The request failed because the moon is full.";
server.enqueue(new MockResponse().setResponseCode(401).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
try {
GenericModel response = service.testMethod().execute();
} catch (Exception e) {
assertTrue(e instanceof UnauthorizedException);
UnauthorizedException ex = (UnauthorizedException) e;
assertEquals(401, ex.getStatusCode());
assertTrue(ex.getMessage().startsWith("Unauthorized: Access is denied due to invalid credentials."));
}
}
Aggregations