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

Georg Koester commented on SLING-4607:
--------------------------------------

Hi [~rombert],

you're right - it's reproducing the SlingHttpServletRequest just fine. I work 
with Sling Models and had problems in the tests:

{code}
@Model(adaptables = SlingHttpServletRequest.class)
public class SomeList {

  @Inject // works in live but fails in test (using io.wcm AemContext [1] and 
MockSlingHttpServletRequest)
  private Resource resource;
  
  @Self
  private SlingHttpServletRequest request;

  // workaround:
  @PostConstruct
  protected void init() {
    resource = request.getResource();
  }
}
{code}

So I thought that the missing {code}adaptTo(Resource.class){code} case might be 
a reason. But now looking at the Sling Models implementation I see that it is 
using {code}request.getResource(){code} . Weird that it should work for my 
workaround but not for Sling Models. This needs more debugging.

[1] 
http://adapt.to/content/dam/adaptto/production/presentations/2014/adaptTo2014-Lightning-Mock-AEM&Co-for-Unit-Tests-Stefan-Seifert.pdf

> Implement MockSlingHttpServletRequest.adaptTo(Resource.class)
> -------------------------------------------------------------
>
>                 Key: SLING-4607
>                 URL: https://issues.apache.org/jira/browse/SLING-4607
>             Project: Sling
>          Issue Type: Improvement
>          Components: Testing
>    Affects Versions: Commons Testing 2.0.16
>            Reporter: Georg Koester
>            Assignee: Robert Munteanu
>            Priority: Minor
>
> {code}
>     request = new MockSlingHttpServletRequest(...);
>     request.setResource(resource);
>     assertSame(resource, request.getResource());
>     assertSame(resource, request.adaptTo(Resource.class));
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to