Class LogTracerRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class LogTracerRule
    extends org.junit.rules.ExternalResource
    • Constructor Summary

      Constructors 
      Constructor Description
      LogTracerRule​(org.apache.sling.testing.junit.rules.instance.Instance quickstartRule)  
      LogTracerRule​(org.apache.sling.testing.junit.rules.instance.Instance quickstartRule, int recordingCacheSizeInMB, int recordingCacheDurationInSecs)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void after()
      Restore the original configuration state of the log tracer.
      protected void before()
      Store the state of the log tracer configuration and enable it.
      com.fasterxml.jackson.databind.JsonNode getLogs​(org.apache.sling.testing.clients.SlingHttpResponse response)
      Parse the tracer request id from the given response object and return the corresponding logs from the tracer servlet as JSON array.
      List<org.apache.http.Header> getTracerHeaders()  
      com.fasterxml.jackson.databind.JsonNode getTracerReport​(org.apache.sling.testing.clients.SlingHttpResponse response)
      Parse the tracer request id from the given response object and return the corresponding tracer report from the tracer servlet as JSON object.
      void setTracerHeaders​(List<org.apache.http.Header> headers)  
      void verifyLog​(org.apache.sling.testing.clients.SlingHttpResponse response)
      Parse the tracer request id from the given response object and check if there are any entries in the corresponding log.
      • Methods inherited from class org.junit.rules.ExternalResource

        apply
    • Constructor Detail

      • LogTracerRule

        public LogTracerRule​(org.apache.sling.testing.junit.rules.instance.Instance quickstartRule)
      • LogTracerRule

        public LogTracerRule​(org.apache.sling.testing.junit.rules.instance.Instance quickstartRule,
                             int recordingCacheSizeInMB,
                             int recordingCacheDurationInSecs)
    • Method Detail

      • getTracerHeaders

        public List<org.apache.http.Header> getTracerHeaders()
      • setTracerHeaders

        public void setTracerHeaders​(List<org.apache.http.Header> headers)
      • before

        protected void before()
                       throws org.apache.sling.testing.clients.ClientException,
                              org.apache.sling.testing.clients.util.config.InstanceConfigException,
                              InterruptedException
        Store the state of the log tracer configuration and enable it.
        Overrides:
        before in class org.junit.rules.ExternalResource
        Throws:
        org.apache.sling.testing.clients.ClientException
        org.apache.sling.testing.clients.util.config.InstanceConfigException
        InterruptedException
      • after

        protected void after()
        Restore the original configuration state of the log tracer.
        Overrides:
        after in class org.junit.rules.ExternalResource
      • getTracerReport

        public com.fasterxml.jackson.databind.JsonNode getTracerReport​(org.apache.sling.testing.clients.SlingHttpResponse response)
                                                                throws org.apache.sling.testing.clients.ClientException,
                                                                       InterruptedException
        Parse the tracer request id from the given response object and return the corresponding tracer report from the tracer servlet as JSON object.
        Parameters:
        response - SlingHttpResponse object
        Returns:
        Request report as JSONObject
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • getLogs

        public com.fasterxml.jackson.databind.JsonNode getLogs​(org.apache.sling.testing.clients.SlingHttpResponse response)
                                                        throws org.apache.sling.testing.clients.ClientException,
                                                               InterruptedException
        Parse the tracer request id from the given response object and return the corresponding logs from the tracer servlet as JSON array.
        Parameters:
        response - SlingHttpResponse object
        Returns:
        Request logs as JSONArray
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • verifyLog

        public void verifyLog​(org.apache.sling.testing.clients.SlingHttpResponse response)
                       throws org.apache.sling.testing.clients.ClientException,
                              InterruptedException
        Parse the tracer request id from the given response object and check if there are any entries in the corresponding log. Marks the test case from which this method was called as failed if there are any log entries.
        Parameters:
        response - SlingHttpResponse object
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting