Class HttpResponseAssertionBuilder


  • public class HttpResponseAssertionBuilder
    extends Object
    A utility class to build and perform assertions on HTTP response headers and status codes This class is used in test cases to assert that responses have the expected headers and status
    • Constructor Detail

      • HttpResponseAssertionBuilder

        public HttpResponseAssertionBuilder​(org.springframework.mock.web.MockHttpServletResponse response)
        Constructs a HeaderAssertionBuilder for the specified response
        Parameters:
        response - the HTTP response to perform assertions on
    • Method Detail

      • statusIs

        public HttpResponseAssertionBuilder statusIs​(int status)
        Specifies the expected HTTP status code for the response
        Parameters:
        status - the expected status code
        Returns:
        the current instance of HeaderAssertionBuilder
      • nullHeaders

        public HttpResponseAssertionBuilder nullHeaders​(String... headers)
        Specifies the headers that are expected to be absent (null) in the response
        Parameters:
        headers - the names of the headers expected to be null
        Returns:
        the current instance of HeaderAssertionBuilder
      • headerEquals

        public HttpResponseAssertionBuilder headerEquals​(String header,
                                                         String value)
        Specifies a header and its expected value in the response
        Parameters:
        header - the name of the header
        value - the expected value of the header
        Returns:
        the current instance of HeaderAssertionBuilder
      • isCompressed

        public HttpResponseAssertionBuilder isCompressed​(boolean expectedCompressed,
                                                         long expectedDecompressedLength)
        Specifies whether the response content is expected to be compressed
        Parameters:
        expectedCompressed - true if the content is expected to be compressed, false otherwise
        expectedDecompressedLength - the expected length of the decompressed content
        Returns:
        the current instance of HeaderAssertionBuilder
      • contentDisposition

        public HttpResponseAssertionBuilder contentDisposition​(HttpResponseAssertionBuilder.DispositionType dispositionType,
                                                               String filename)
        Specifies the expected content disposition header
        Parameters:
        dispositionType - the expected disposition type (ATTACHMENT or INLINE)
        filename - the expected filename in the content disposition
        Returns:
        the current instance of HeaderAssertionBuilder
      • verify

        public void verify()
        Executes the assertions based on the specified expectations Verifies that the response has the expected status code, null headers, and header values