Search in sources :

Example 6 with GenericModel

use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.

the class ErrorResponseTest method testRequestTooLarge.

/**
 * Test HTTP status code 413 (RequestTooLarge) error response.
 */
@Test
public void testRequestTooLarge() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(413).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof RequestTooLargeException);
        RequestTooLargeException ex = (RequestTooLargeException) e;
        assertEquals(413, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 7 with GenericModel

use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.

the class ErrorResponseTest method testTooManyRequests.

/**
 * Test HTTP status code 429 (TooManyRequests) error response.
 */
@Test
public void testTooManyRequests() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(429).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof TooManyRequestsException);
        TooManyRequestsException ex = (TooManyRequestsException) e;
        assertEquals(429, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 8 with GenericModel

use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.

the class ErrorResponseTest method testForbidden.

/**
 * Test HTTP status code 403 (Forbidden) error response.
 */
@Test
public void testForbidden() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(403).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof ForbiddenException);
        ForbiddenException ex = (ForbiddenException) e;
        assertEquals(403, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 9 with GenericModel

use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.

the class ErrorResponseTest method testNotFound.

/**
 * Test HTTP status code 404 (NotFound) error response.
 */
@Test
public void testNotFound() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(404).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof NotFoundException);
        NotFoundException ex = (NotFoundException) e;
        assertEquals(404, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 10 with GenericModel

use of com.ibm.watson.developer_cloud.service.model.GenericModel in project java-sdk by watson-developer-cloud.

the class ErrorResponseTest method testConflict.

/**
 * Test HTTP status code 409 (Conflict) error response.
 */
@Test
public void testConflict() {
    String message = "The request failed because the moon is full.";
    server.enqueue(new MockResponse().setResponseCode(409).addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{\"error\": \"" + message + "\"}"));
    try {
        GenericModel response = service.testMethod().execute();
    } catch (Exception e) {
        assertTrue(e instanceof ConflictException);
        ConflictException ex = (ConflictException) e;
        assertEquals(409, ex.getStatusCode());
        assertEquals(message, ex.getMessage());
    }
}
Also used : GenericModel(com.ibm.watson.developer_cloud.service.model.GenericModel) MockResponse(okhttp3.mockwebserver.MockResponse) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) ForbiddenException(com.ibm.watson.developer_cloud.service.exception.ForbiddenException) BadRequestException(com.ibm.watson.developer_cloud.service.exception.BadRequestException) TooManyRequestsException(com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ConflictException(com.ibm.watson.developer_cloud.service.exception.ConflictException) UnsupportedException(com.ibm.watson.developer_cloud.service.exception.UnsupportedException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) RequestTooLargeException(com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException) InternalServerErrorException(com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException) ServiceUnavailableException(com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Aggregations

WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)10 BadRequestException (com.ibm.watson.developer_cloud.service.exception.BadRequestException)10 ConflictException (com.ibm.watson.developer_cloud.service.exception.ConflictException)10 ForbiddenException (com.ibm.watson.developer_cloud.service.exception.ForbiddenException)10 InternalServerErrorException (com.ibm.watson.developer_cloud.service.exception.InternalServerErrorException)10 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)10 RequestTooLargeException (com.ibm.watson.developer_cloud.service.exception.RequestTooLargeException)10 ServiceUnavailableException (com.ibm.watson.developer_cloud.service.exception.ServiceUnavailableException)10 TooManyRequestsException (com.ibm.watson.developer_cloud.service.exception.TooManyRequestsException)10 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)10 UnsupportedException (com.ibm.watson.developer_cloud.service.exception.UnsupportedException)10 GenericModel (com.ibm.watson.developer_cloud.service.model.GenericModel)10 MockResponse (okhttp3.mockwebserver.MockResponse)10 Test (org.junit.Test)10