use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo in project sling by apache.
the class FactoryPreconditionsTest method getResourceProviderHandlersWithNames.
private List<ResourceProviderHandler> getResourceProviderHandlersWithNames(String[] names) {
final List<ResourceProviderHandler> result = new ArrayList<ResourceProviderHandler>();
for (final String n : names) {
final ResourceProviderHandler handler = Mockito.mock(ResourceProviderHandler.class);
final ResourceProviderInfo info = Mockito.mock(ResourceProviderInfo.class);
Mockito.when(info.getName()).thenReturn(n);
final ServiceReference ref = Mockito.mock(ServiceReference.class);
Mockito.when(handler.getInfo()).thenReturn(info);
Mockito.when(info.getServiceReference()).thenReturn(ref);
result.add(handler);
}
return result;
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo in project sling by apache.
the class Fixture method registerResourceProvider.
public ResourceProviderInfo registerResourceProvider(ResourceProvider<?> rp, String root, AuthType authType) throws InvalidSyntaxException {
Dictionary<String, String> props = new Hashtable<String, String>();
props.put(ResourceProvider.PROPERTY_ROOT, root);
props.put(ResourceProvider.PROPERTY_AUTHENTICATE, authType.name());
props.put(ResourceProvider.PROPERTY_MODIFIABLE, Boolean.TRUE.toString());
ServiceRegistration registration = bc.registerService(ResourceProvider.class.getName(), rp, props);
ServiceReference sr = bc.getServiceReferences(ResourceProvider.class.getName(), "(" + ResourceProvider.PROPERTY_ROOT + "=" + root + ")")[0];
ResourceProviderInfo providerInfo = new ResourceProviderInfo(sr);
providerRegistrations.put(providerInfo, registration);
return providerInfo;
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo in project sling by apache.
the class FactoryPreconditionsTest method getResourceProviderHandlers.
private List<ResourceProviderHandler> getResourceProviderHandlers(String[] pids) {
final List<ResourceProviderHandler> result = new ArrayList<ResourceProviderHandler>();
for (final String p : pids) {
final ResourceProviderHandler handler = Mockito.mock(ResourceProviderHandler.class);
final ResourceProviderInfo info = Mockito.mock(ResourceProviderInfo.class);
final ServiceReference ref = Mockito.mock(ServiceReference.class);
Mockito.when(handler.getInfo()).thenReturn(info);
Mockito.when(info.getServiceReference()).thenReturn(ref);
Mockito.when(ref.getProperty(Constants.SERVICE_PID)).thenReturn(p);
result.add(handler);
}
return result;
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo in project sling by apache.
the class MockedResourceResolverImplTest method createRPHandler.
public static ResourceProviderHandler createRPHandler(ResourceProvider<?> rp, String pid, long ranking, String path) {
ServiceReference ref = Mockito.mock(ServiceReference.class);
BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(bc.getService(Mockito.eq(ref))).thenReturn(rp);
Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_ID))).thenReturn(new Random().nextLong());
Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_PID))).thenReturn(pid);
Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_RANKING))).thenReturn(ranking);
Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ROOT))).thenReturn(path);
Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_MODIFIABLE))).thenReturn(true);
Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ATTRIBUTABLE))).thenReturn(true);
Mockito.when(ref.getProperty(Mockito.eq(ResourceProvider.PROPERTY_ADAPTABLE))).thenReturn(true);
ResourceProviderInfo info = new ResourceProviderInfo(ref);
final ResourceProviderHandler handler = new ResourceProviderHandler(bc, info);
handler.activate();
return handler;
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo 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