You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2018/10/04 15:55:00 UTC

[jira] [Created] (SLING-7978) Sling Mocks: Allow easy access to the ModelFactory

Konrad Windszus created SLING-7978:
--------------------------------------

             Summary: Sling Mocks: Allow easy access to the ModelFactory
                 Key: SLING-7978
                 URL: https://issues.apache.org/jira/browse/SLING-7978
             Project: Sling
          Issue Type: Bug
          Components: Testing
    Affects Versions: Testing Sling Mock 2.3.4
            Reporter: Konrad Windszus


Currently you would instantiate a Sling Model in a unit test leveraging Sling Mocks via
{code}
@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);

    context.resourceResolver().getResource("/page1").adaptTo(MyModel.class)
{code}

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}}.
 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)