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

Sling Mocks: Allow easy access to the ModelFactory

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • None
    • Site, Testing
    • None

    Description

      Currently you would instantiate a Sling Model in a unit test leveraging Sling Mocks via

      @Rule
        public SlingContext context = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
      
       @Test
        public void testModel() {
          context.load()
                 .json(<some json resource from the classpath>, "/page1");
          context.addModelsForClasses(MyModel.class);
      
          MyModel model = context.resourceResolver().getResource("/page1").adaptTo(MyModel.class)
      
        // model is now null for some reason, hard to debug why
      

      In case for some reason the model cannot be instantiated it is hard to debug why (because by default the reason is only emitted in the log with level DEBUG). To ease debugging it would be nice if ModelFactory (SLING-3709) could be used, as that throws an explicit exception in case of instantiation errrors. It would be nice to give direct access to that service directly from the SlingContext.
       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kwin Konrad Windszus
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m