use of org.apache.sling.resourceresolver.impl.SimpleValueMapImpl in project sling by apache.
the class ResourceResolverControlTest method prepare.
@Before
public void prepare() throws Exception {
BundleContext bc = MockOsgi.newBundleContext();
Fixture fixture = new Fixture(bc);
// sub-provider
subProvider = Mockito.mock(ResourceProvider.class);
ResourceProviderInfo info = fixture.registerResourceProvider(subProvider, "/some/path", AuthType.required);
ResourceProviderHandler handler = new ResourceProviderHandler(bc, info);
when(subProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_MOCK, QL_ANOTHER_MOCK) {
@Override
public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
SimpleValueMapImpl valueMap = new SimpleValueMapImpl();
valueMap.put("key", "value");
return Collections.<ValueMap>singletonList(valueMap).iterator();
}
throw new UnsupportedOperationException();
}
@Override
public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
return Collections.<Resource>singletonList(newMockResource("/some/path/object")).iterator();
}
throw new UnsupportedOperationException();
}
});
handler.activate();
rootProvider = mock(ResourceProvider.class);
ResourceProviderInfo rootInfo = fixture.registerResourceProvider(rootProvider, "/", AuthType.required);
ResourceProviderHandler rootHandler = new ResourceProviderHandler(bc, rootInfo);
when(rootProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_NOOP));
rootHandler.activate();
// configure mock resources
Resource root = configureResourceAt(rootProvider, "/");
somethingResource = configureResourceAt(rootProvider, "/something");
subProviderResource = configureResourceAt(subProvider, "/some/path/object");
// configure query at '/'
when(rootProvider.listChildren((ResolveContext<Object>) Mockito.anyObject(), Mockito.eq(root))).thenReturn(Collections.singleton(somethingResource).iterator());
ResourceResolver rr = mock(ResourceResolver.class);
ResourceAccessSecurityTracker securityTracker = Mockito.mock(ResourceAccessSecurityTracker.class);
authInfo = getAuthInfo();
handlers = Arrays.asList(rootHandler, handler);
final ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
crp = new ResourceResolverControl(false, authInfo, new ResourceProviderStorageProvider() {
@Override
public ResourceProviderStorage getResourceProviderStorage() {
return storage;
}
});
context = new ResourceResolverContext(rr, securityTracker);
}
Aggregations