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

2018-10-05 Thread Konrad Windszus (JIRA)


[ 
https://issues.apache.org/jira/browse/SLING-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16639596#comment-16639596
 ] 

Konrad Windszus commented on SLING-7978:


Merged with 
https://github.com/apache/sling-site/commit/9c7262ba0c35c6e9779f38a425daa406ceb1e7c2.

> Sling Mocks: Allow easy access to the ModelFactory
> --
>
> Key: SLING-7978
> URL: https://issues.apache.org/jira/browse/SLING-7978
> Project: Sling
>  Issue Type: Improvement
>  Components: Testing
>Affects Versions: Testing Sling Mock 2.3.4
>Reporter: Konrad Windszus
>Priority: Major
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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(, "/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
> {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)


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

2018-10-05 Thread Konrad Windszus (JIRA)


[ 
https://issues.apache.org/jira/browse/SLING-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16639631#comment-16639631
 ] 

Konrad Windszus commented on SLING-7978:


I published the updated site to 
https://sling.apache.org/documentation/development/sling-mock.html#sling-models.
 

> Sling Mocks: Allow easy access to the ModelFactory
> --
>
> Key: SLING-7978
> URL: https://issues.apache.org/jira/browse/SLING-7978
> Project: Sling
>  Issue Type: Improvement
>  Components: Site, Testing
>Reporter: Konrad Windszus
>Priority: Major
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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(, "/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
> {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)


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

2018-10-05 Thread Stefan Seifert (JIRA)


[ 
https://issues.apache.org/jira/browse/SLING-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16639528#comment-16639528
 ] 

Stefan Seifert commented on SLING-7978:
---

lgtm

> Sling Mocks: Allow easy access to the ModelFactory
> --
>
> Key: SLING-7978
> URL: https://issues.apache.org/jira/browse/SLING-7978
> Project: Sling
>  Issue Type: Improvement
>  Components: Testing
>Affects Versions: Testing Sling Mock 2.3.4
>Reporter: Konrad Windszus
>Priority: Major
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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(, "/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
> {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)


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

2018-10-04 Thread Konrad Windszus (JIRA)


[ 
https://issues.apache.org/jira/browse/SLING-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16638535#comment-16638535
 ] 

Konrad Windszus commented on SLING-7978:


I was not too sure that this service is already provided by Sling Mocks by 
default. But of course this is easy enough. I hope I can come up with a little 
PR for documentation (I think it is worth documenting it and enforcing this as 
best practice :-))

> 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
>Priority: Major
>
> 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(, "/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
> {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)


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

2018-10-04 Thread Stefan Seifert (JIRA)


[ 
https://issues.apache.org/jira/browse/SLING-7978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16638523#comment-16638523
 ] 

Stefan Seifert commented on SLING-7978:
---

it's just one code line away:
{code:java}
MyModel model = 
context.getService(ModelFactory.class).createModel(context.resourceResolver().getResource("/page1"),
 MyModel.class)
{code}

not sure if it's worth adding a convenience method to the context object itself 
for this.
(and it's definitely not a bug ...)

> 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
>Priority: Major
>
> 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(, "/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
> {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)