On Tue, Jul 16, 2013 at 1:58 PM, Ian Boston <[email protected]> wrote: > One further thing. > > For testing, use dummies. > OK. got the point. For testing, currently will keep the dummy resolver impl. And once this is in the sling ogsi environment, will add this.
> > When the Component is started within the Sling OSGi container as a real > bundle the real ResourceResolver will be injected for you. > > Does that clear up my misunderstanding of what you were asking ? > Yes. Thank you very much for the example. > > Ian > > > On 16 July 2013 09:26, Ian Boston <[email protected]> wrote: > > > 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 > >> > > > > > -- Thanks /Dishara
