Class JaxrsExceptionTestHelper
- java.lang.Object
-
- org.kiwiproject.test.jaxrs.exception.JaxrsExceptionTestHelper
-
public class JaxrsExceptionTestHelper extends Object
Test utility methods for testingJaxrsException
objects.
-
-
Constructor Summary
Constructors Constructor Description JaxrsExceptionTestHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.kiwiproject.jaxrs.exception.ErrorMessage
assertContainsError(javax.ws.rs.core.Response response, int statusCode, String substring)
Asserts that the response contains anErrorMessage
with the given status code and having a message that contains the given substring.static void
assertHasError(javax.ws.rs.core.Response response, org.kiwiproject.jaxrs.exception.ErrorMessage errorMessage)
Asserts that the response contains the givenErrorMessage
.static void
assertHasErrors(javax.ws.rs.core.Response response, List<org.kiwiproject.jaxrs.exception.ErrorMessage> errorMessages)
Asserts that the response contains all the givenErrorMessage
objects.static List<org.kiwiproject.jaxrs.exception.ErrorMessage>
getErrorMessages(javax.ws.rs.core.Response response)
Returns a list of theErrorMessage
objects in the given response.static org.kiwiproject.jaxrs.exception.ErrorMessage
getFirstErrorMessage(javax.ws.rs.core.Response response)
Returns the firstErrorMessage
in the given response.static org.kiwiproject.jaxrs.exception.JaxrsException
toJaxrsException(javax.ws.rs.core.Response response)
Converts an errorResponse
to theJaxrsException
or an appropriate subclass.
-
-
-
Method Detail
-
toJaxrsException
public static org.kiwiproject.jaxrs.exception.JaxrsException toJaxrsException(javax.ws.rs.core.Response response)
Converts an errorResponse
to theJaxrsException
or an appropriate subclass.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)- Returns:
- JaxrsException equivalent of error response
-
getFirstErrorMessage
public static org.kiwiproject.jaxrs.exception.ErrorMessage getFirstErrorMessage(javax.ws.rs.core.Response response)
Returns the firstErrorMessage
in the given response.The response is expected to conform to the structure of a
JaxrsException
, i.e. it has a list ofErrorMessage
under the "errors" key in the JSON response entity.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)- Returns:
- first
ErrorMessage
in the response entity - Throws:
IllegalArgumentException
- if there isn't at least one ErrorMessage
-
getErrorMessages
public static List<org.kiwiproject.jaxrs.exception.ErrorMessage> getErrorMessages(javax.ws.rs.core.Response response)
Returns a list of theErrorMessage
objects in the given response.The response is expected to conform to the structure of a
JaxrsException
, i.e. it has a list ofErrorMessage
under the "errors" key in the JSON response entity.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)- Returns:
- List containing all
ErrorMessage
in the response entity
-
assertHasError
public static void assertHasError(javax.ws.rs.core.Response response, org.kiwiproject.jaxrs.exception.ErrorMessage errorMessage)
Asserts that the response contains the givenErrorMessage
.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)errorMessage
- the ErrorMessage that should be in response
-
assertHasErrors
public static void assertHasErrors(javax.ws.rs.core.Response response, List<org.kiwiproject.jaxrs.exception.ErrorMessage> errorMessages)
Asserts that the response contains all the givenErrorMessage
objects.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)errorMessages
- the ErrorMessage objects that should be in response
-
assertContainsError
public static org.kiwiproject.jaxrs.exception.ErrorMessage assertContainsError(javax.ws.rs.core.Response response, int statusCode, String substring)
Asserts that the response contains anErrorMessage
with the given status code and having a message that contains the given substring.- Parameters:
response
- a JAX-RSOutboundJaxrsResponse
orInboundJaxrsResponse
(not public)statusCode
- the status code expected to be in theErrorMessage
substring
- the substring expected to be inErrorMessage.getMessage()
- Returns:
- the
ErrorMessage
matching the given status code and substring
-
-