You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Shurmer, Jordan" <js...@scrippsnetworks.com> on 2016/10/20 15:37:51 UTC
x SCR Annotations and sling-mock to get resourceResolverFactory
Hello,
I've got an OSGi component that I'm writing unit tests for using sling-mock. The component uses the @Reference annotation to inject a resourceResolverFactory which it then uses to call getServiceResourceResolver(). I'm wondering if there's a way to set up the mock SlingContext so that this factory is properly injected when running the unit tests.
Right now I am defining my own bindResolverFactory method and passing in a mock factory, but I am hoping that sling-mock or osgi-mock provides a way for this to work ootb.
Any suggestions?
Thanks,
Jordan Shurmer | Software Engineer | Scripps Lifestyle Studios
9721 Sherrill Blvd, Knoxville TN 37932
Office: 865-560-4887
jshurmer@scrippsnetworks.com<ma...@scrippsnetworks.com>
SCRIPPS NETWORKS INTERACTIVE | the Leader in Lifestyle Media | scrippsnetworksinteractive.com
HGTV | Food Network | Travel Channel | DIY Network | Cooking Channel | Great American Country | TVN | Fine Living | Asian Food Channel
RE: x SCR Annotations and sling-mock to get resourceResolverFactory
Posted by "Shurmer, Jordan" <js...@scrippsnetworks.com>.
Hello,
Thank you! I just ran across this in the docs as well - not sure how I missed it.
-----Original Message-----
From: Guillaume Lucazeau [mailto:glucazeau@gmail.com]
Sent: Thursday, October 20, 2016 11:56 AM
To: users@sling.apache.org
Subject: Re: x SCR Annotations and sling-mock to get resourceResolverFactory
Hello Jordan,
You can register services in the mocked Sling context:
@Rule
public final SlingContext slingContext = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
[...]
slingContext.registerService(ResourceResolverFactory.class, new MockResourceResolverFactory());
Thus they will be injected when your tests run.
Regards,
Guillaume
On Thu, Oct 20, 2016 at 5:37 PM, Shurmer, Jordan < jshurmer@scrippsnetworks.com> wrote:
> Hello,
>
> I've got an OSGi component that I'm writing unit tests for using
> sling-mock. The component uses the @Reference annotation to inject a
> resourceResolverFactory which it then uses to call
> getServiceResourceResolver(). I'm wondering if there's a way to set up
> the mock SlingContext so that this factory is properly injected when
> running the unit tests.
>
> Right now I am defining my own bindResolverFactory method and passing
> in a mock factory, but I am hoping that sling-mock or osgi-mock
> provides a way for this to work ootb.
>
> Any suggestions?
>
> Thanks,
>
> Jordan Shurmer | Software Engineer | Scripps Lifestyle Studios
>
> 9721 Sherrill Blvd, Knoxville TN 37932
> Office: 865-560-4887
> jshurmer@scrippsnetworks.com<ma...@scrippsnetworks.com>
>
> SCRIPPS NETWORKS INTERACTIVE | the Leader in Lifestyle Media |
> scrippsnetworksinteractive.com HGTV | Food Network | Travel Channel |
> DIY Network | Cooking Channel | Great American Country | TVN | Fine
> Living | Asian Food Channel
>
>
Re: x SCR Annotations and sling-mock to get resourceResolverFactory
Posted by Guillaume Lucazeau <gl...@gmail.com>.
Hello Jordan,
You can register services in the mocked Sling context:
@Rule
public final SlingContext slingContext = new
SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
[...]
slingContext.registerService(ResourceResolverFactory.class, new
MockResourceResolverFactory());
Thus they will be injected when your tests run.
Regards,
Guillaume
On Thu, Oct 20, 2016 at 5:37 PM, Shurmer, Jordan <
jshurmer@scrippsnetworks.com> wrote:
> Hello,
>
> I've got an OSGi component that I'm writing unit tests for using
> sling-mock. The component uses the @Reference annotation to inject a
> resourceResolverFactory which it then uses to call
> getServiceResourceResolver(). I'm wondering if there's a way to set up the
> mock SlingContext so that this factory is properly injected when running
> the unit tests.
>
> Right now I am defining my own bindResolverFactory method and passing in a
> mock factory, but I am hoping that sling-mock or osgi-mock provides a way
> for this to work ootb.
>
> Any suggestions?
>
> Thanks,
>
> Jordan Shurmer | Software Engineer | Scripps Lifestyle Studios
>
> 9721 Sherrill Blvd, Knoxville TN 37932
> Office: 865-560-4887
> jshurmer@scrippsnetworks.com<ma...@scrippsnetworks.com>
>
> SCRIPPS NETWORKS INTERACTIVE | the Leader in Lifestyle Media |
> scrippsnetworksinteractive.com
> HGTV | Food Network | Travel Channel | DIY Network | Cooking Channel |
> Great American Country | TVN | Fine Living | Asian Food Channel
>
>