Class JaxrsExceptionTestHelper


  • public class JaxrsExceptionTestHelper
    extends Object
    Test utility methods for testing JaxrsException objects.
    • 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 an ErrorMessage 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 given ErrorMessage.
      static void assertHasErrors​(javax.ws.rs.core.Response response, List<org.kiwiproject.jaxrs.exception.ErrorMessage> errorMessages)
      Asserts that the response contains all the given ErrorMessage objects.
      static List<org.kiwiproject.jaxrs.exception.ErrorMessage> getErrorMessages​(javax.ws.rs.core.Response response)
      Returns a list of the ErrorMessage objects in the given response.
      static org.kiwiproject.jaxrs.exception.ErrorMessage getFirstErrorMessage​(javax.ws.rs.core.Response response)
      Returns the first ErrorMessage in the given response.
      static org.kiwiproject.jaxrs.exception.JaxrsException toJaxrsException​(javax.ws.rs.core.Response response)
      Converts an error Response to the JaxrsException or an appropriate subclass.
    • Constructor Detail

      • JaxrsExceptionTestHelper

        public JaxrsExceptionTestHelper()
    • Method Detail

      • toJaxrsException

        public static org.kiwiproject.jaxrs.exception.JaxrsException toJaxrsException​(javax.ws.rs.core.Response response)
        Converts an error Response to the JaxrsException or an appropriate subclass.
        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (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 first ErrorMessage in the given response.

        The response is expected to conform to the structure of a JaxrsException, i.e. it has a list of ErrorMessage under the "errors" key in the JSON response entity.

        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (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 the ErrorMessage objects in the given response.

        The response is expected to conform to the structure of a JaxrsException, i.e. it has a list of ErrorMessage under the "errors" key in the JSON response entity.

        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (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 given ErrorMessage.
        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (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 given ErrorMessage objects.
        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (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 an ErrorMessage with the given status code and having a message that contains the given substring.
        Parameters:
        response - a JAX-RS OutboundJaxrsResponse or InboundJaxrsResponse (not public)
        statusCode - the status code expected to be in the ErrorMessage
        substring - the substring expected to be in ErrorMessage.getMessage()
        Returns:
        the ErrorMessage matching the given status code and substring