Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-10062

Provide a way to allow mocking of findResources or query manager for resource resolvers / sessions obtained inside production code

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Testing
    • None

    Description

      At this moment it is not possible to do a mock for query results of resource resolvers / sessions that are obtained inside the code instead of passed as method parameter from the SlingContext / JcrContext.

      Example:

      @Component
      public class MyClass {
         @Reference
         private ResourceResolverFactory resourceResolverFactory;
      
         public void methodToTest() {
           try(ResourceResolver resourceResolver: resourceResolverFactory.getServiceResourceResolver(AUTH_INFO)) {
            // something to test
           }
         }
      
      }

      Currently I solve this by just making a second method that gets the resource resolver as parameter and making it public so that it can be tested, but that breaks my private / public stuff

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              royteeuwen Roy Teeuwen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: