Hi,
There are 2 options.
You can
use org.apache.sling.testing.resourceresolver.MockResourceResolverFactory
which should allow you to do
this.factory = new MockResourceResolverFactory();
...
ResourceResolver resolver =
this.factory.getAdministrativeResourceResolver(null);
or
you can use Mockito and do
public class ResourceProviderTest {
@Mock
ResourceResolver mockResourceResolver;
public ResourceProviderTest() {
MockitoAnnotation.initMocks(this);
}
@Test
public void testSomething() {
Resource mockResource = Mockito.mock(Resource.class);
Mockito.when(mockResourceResolver.getResource("/test/path")).thenReturn(mockResource);
}
}
I prefer using Mockito as it gives greater control and isolation.
Grep the code base for @Mock to see examples of Mockito usage or read the
Mockito docs.
Does that help ?
Best Regards
Ian
On 16 July 2013 08:58, Dishara Wijewardana <[email protected]> wrote:
> On Tue, Jul 16, 2013 at 1:19 PM, Bertrand Delacretaz <
> [email protected]
> > wrote:
>
> > Hi,
> >
> > On Tue, Jul 16, 2013 at 9:34 AM, Dishara Wijewardana
> > <[email protected]> wrote:
> > > ....I was got stuck where to find the resolver (according to my
> > > understanding). To set the resolver through reflection, I need to get a
> > > real resolver reference instance....
> >
> > Where exactly do you have that problem?
> >
> > If you can give us the URL of that problematic code, it would be much
> > easier for us to suggest solutions.
> >
>
> This is a simple Junit test class[1]. And I cannot figure out what needs to
> be done to obtain a existing resource resolver reference due to above
> mentioned complicatoins.
> And there currently I am using a dummy resolver implementation to pass to
> the provider to obtain a resource. As Ian mentioned we should pass an
> existing reference of a resolver. Here is the code that does this.
>
> private void readData(CassandraResourceProvider
> cassandraResourceProvider, String cf) {
> Resource resource = cassandraResourceProvider.getResource(new
> CassandraResourceResolver(), "/content/cassandra/" + cf + "/foo/bar");
>
> }
>
>
> [1] -
>
> https://cassandra-backend-for-sling.googlecode.com/svn/trunk/main/cassandra/src/test/java/org/apache/sling/cassandra/test/data/populator/CassandraDataPopulatorTest.java
>
>
> > -Bertrand
> >
>
>
>
> --
> Thanks
> /Dishara
>