use of com.ibm.watson.developer_cloud.service.exception.UnauthorizedException 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."));
}
}
use of com.ibm.watson.developer_cloud.service.exception.UnauthorizedException in project java-sdk by watson-developer-cloud.
the class CustomizationsIT method testDeleteVoiceModel.
/**
* Test delete voice model.
*/
@Test
public void testDeleteVoiceModel() {
model = createVoiceModel();
DeleteVoiceModelOptions deleteOptions = new DeleteVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).build();
service.deleteVoiceModel(deleteOptions).execute();
try {
GetVoiceModelOptions getOptions = new GetVoiceModelOptions.Builder().customizationId(model.getCustomizationId()).build();
service.getVoiceModel(getOptions).execute();
fail("deleting customization failed");
} catch (UnauthorizedException e) {
// success!
}
}
Aggregations