Class CustomUserAgentRule

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

    public class CustomUserAgentRule
    extends Object
    implements org.junit.rules.TestRule
    Junit rule to overwrite or append the user-agent of all SlingClient http requests with a custom String.
    May be used on a per class or per test basis.
    (In case the user-agent of the HttpClient is tampered with manually changes will not be applied.)
    • Constructor Detail

      • CustomUserAgentRule

        public CustomUserAgentRule​(String userAgent)
        Overwrite the user-agent with a custom String.
        Parameters:
        userAgent - the new user-agent
      • CustomUserAgentRule

        public CustomUserAgentRule​(String userAgent,
                                   boolean append)
        Modify or overwrite the user-agent.
        Parameters:
        userAgent - the desired user-agent
        append - whether it should just be appended to the current one
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • starting

        protected void starting()
      • finished

        protected void finished()