[Sling Testing] Mocking a Resource Resolver w/ URL Mappings

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Sling Testing] Mocking a Resource Resolver w/ URL Mappings

David G.
Hi all,

I would like to mock a Resource Resolver but provide various URL Mappings
for my unit testing (ie. what is set via Apache Sling Resource Resolver
Factory > URL Mapping)

Is there a way to achieve this with the new (and great) Sling Mocks?

Thanks
Reply | Threaded
Open this post in threaded view
|

RE: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings

Stefan Seifert
yes, you can set a different value for the resource.resolver.mapping property.

when you create the SlingContext object for the junit rule using the SlingContextBuilder, you have method resourceResolverFactoryActivatorProps.
pass in a hashmap for this method with property resource.resolver.mapping set to your mapping string array.

stefan

>-----Original Message-----
>From: David G. [mailto:[hidden email]]
>Sent: Thursday, June 22, 2017 3:40 PM
>To: [hidden email]
>Subject: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings
>
>Hi all,
>
>I would like to mock a Resource Resolver but provide various URL Mappings
>for my unit testing (ie. what is set via Apache Sling Resource Resolver
>Factory > URL Mapping)
>
>Is there a way to achieve this with the new (and great) Sling Mocks?
>
>Thanks
Reply | Threaded
Open this post in threaded view
|

Re: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings

David G.
Thanks Stefan,

I tried it out to no avail; here is a quick harness [1]
I poke around the code, and dont see where these properties are used in the
code? Am I missing something?

Im on the latest sling mock bundle (2.2.12) and also played around w the
param format; String[] vs "[/:/,/content/,<]", as well as the order, but it
didnt work,

[1] https://gist.github.com/davidjgonzalez/38550e36e66be3c234c6944fabf67d8f
[2]
https://github.com/apache/sling/blob/trunk/testing/mocks/resourceresolver-mock/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java#L118


On Fri, Jun 23, 2017 at 9:41 AM, Stefan Seifert <[hidden email]>
wrote:

> yes, you can set a different value for the resource.resolver.mapping
> property.
>
> when you create the SlingContext object for the junit rule using the
> SlingContextBuilder, you have method resourceResolverFactoryActivat
> orProps.
> pass in a hashmap for this method with property resource.resolver.mapping
> set to your mapping string array.
>
> stefan
>
> >-----Original Message-----
> >From: David G. [mailto:[hidden email]]
> >Sent: Thursday, June 22, 2017 3:40 PM
> >To: [hidden email]
> >Subject: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings
> >
> >Hi all,
> >
> >I would like to mock a Resource Resolver but provide various URL Mappings
> >for my unit testing (ie. what is set via Apache Sling Resource Resolver
> >Factory > URL Mapping)
> >
> >Is there a way to achieve this with the new (and great) Sling Mocks?
> >
> >Thanks
>
Reply | Threaded
Open this post in threaded view
|

RE: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings

Stefan Seifert
i've added a test case for your use case, seems to work:
https://github.com/apache/sling/commit/9cfb76c717abdab409af4db552f245a8a63a9e72

the problem in your test harness ist he usage of RESOURCERESOLVER_MOCK - this is only a very simplified of resource resolver implementation and has nothing to do with the real impl or any properties you provide for the activator - the map implementation is also simplified [1].

if you switch to ResourceResolverType.JCR_MOCK you have the real resource resolver implementation.

stefan


[1] https://github.com/apache/sling/blob/trunk/testing/mocks/resourceresolver-mock/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceResolver.java#L113


>-----Original Message-----
>From: David G. [mailto:[hidden email]]
>Sent: Friday, June 23, 2017 11:06 PM
>To: [hidden email]
>Subject: Re: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings
>
>Thanks Stefan,
>
>I tried it out to no avail; here is a quick harness [1]
>I poke around the code, and dont see where these properties are used in the
>code? Am I missing something?
>
>Im on the latest sling mock bundle (2.2.12) and also played around w the
>param format; String[] vs "[/:/,/content/,<]", as well as the order, but it
>didnt work,
>
>[1] https://gist.github.com/davidjgonzalez/38550e36e66be3c234c6944fabf67d8f
>[2]
>https://github.com/apache/sling/blob/trunk/testing/mocks/resourceresolver-
>mock/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceRe
>solver.java#L118
>
>
>On Fri, Jun 23, 2017 at 9:41 AM, Stefan Seifert <[hidden email]>
>wrote:
>
>> yes, you can set a different value for the resource.resolver.mapping
>> property.
>>
>> when you create the SlingContext object for the junit rule using the
>> SlingContextBuilder, you have method resourceResolverFactoryActivat
>> orProps.
>> pass in a hashmap for this method with property resource.resolver.mapping
>> set to your mapping string array.
>>
>> stefan
>>
>> >-----Original Message-----
>> >From: David G. [mailto:[hidden email]]
>> >Sent: Thursday, June 22, 2017 3:40 PM
>> >To: [hidden email]
>> >Subject: [Sling Testing] Mocking a Resource Resolver w/ URL Mappings
>> >
>> >Hi all,
>> >
>> >I would like to mock a Resource Resolver but provide various URL
>Mappings
>> >for my unit testing (ie. what is set via Apache Sling Resource Resolver
>> >Factory > URL Mapping)
>> >
>> >Is there a way to achieve this with the new (and great) Sling Mocks?
>> >
>> >Thanks
>>