use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class FactoryPreconditionsTest method testDeactivated.
@Test
public void testDeactivated() {
final ResourceProviderTracker tracker = Mockito.mock(ResourceProviderTracker.class);
final ResourceProviderStorage storage = Mockito.mock(ResourceProviderStorage.class);
Mockito.when(tracker.getResourceProviderStorage()).thenReturn(storage);
FactoryPreconditions conditions = new FactoryPreconditions();
conditions.activate(null, null, null, tracker);
assertTrue(conditions.checkPreconditions(null, null));
conditions.deactivate();
assertFalse(conditions.checkPreconditions(null, null));
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class ResourceResolverImplTest method setup.
@Before
public void setup() throws LoginException {
ResourceProvider<?> rp = new ResourceProvider<Object>() {
@Override
public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext rCtx, Resource parent) {
return null;
}
@Override
public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
return null;
}
};
List<ResourceProviderHandler> handlers = asList(createRPHandler(rp, "rp1", 0, "/"));
resourceProviderTracker = mock(ResourceProviderTracker.class);
ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
activator.resourceProviderTracker = resourceProviderTracker;
activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
commonFactory = new CommonResourceResolverFactoryImpl(activator);
final Bundle usingBundle = mock(Bundle.class);
resFac = new ResourceResolverFactoryImpl(commonFactory, usingBundle, null);
resResolver = resFac.getAdministrativeResourceResolver(null);
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class ResourceDecoratorTestBase method setup.
@Before
public void setup() throws LoginException {
final ResourceDecorator d = new ResourceDecorator() {
@Override
public Resource decorate(Resource resource) {
return ResourceDecoratorTestBase.this.wrapResourceForTest(resource);
}
@Override
public Resource decorate(Resource resource, HttpServletRequest request) {
throw new UnsupportedOperationException("Not supposed to be used in these tests");
}
};
final ResourceDecoratorTracker t = new ResourceDecoratorTracker();
t.bindResourceDecorator(d, null);
final ResourceProvider<?> provider = new ResourceProvider<Object>() {
@Override
public QueryLanguageProvider<Object> getQueryLanguageProvider() {
return new QueryLanguageProvider<Object>() {
@Override
public String[] getSupportedLanguages(ResolveContext<Object> ctx) {
return new String[] { QUERY_LANGUAGE };
}
@Override
public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
final List<Resource> found = new ArrayList<Resource>();
found.add(mockResource("/tmp/C"));
found.add(mockResource("/tmp/D"));
found.add(mockResource("/var/one"));
found.add(mockResource("/var/two"));
return found.iterator();
}
@Override
public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
return null;
}
};
}
@Override
public Resource getResource(ResolveContext<Object> ctx, String path, final ResourceContext rCtx, Resource parent) {
if (path.equals("/") || path.startsWith("/tmp") || path.startsWith("/var")) {
return mockResource(path);
}
return null;
}
@Override
public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
final List<Resource> children = new ArrayList<Resource>();
if ("/".equals(parent.getPath())) {
children.add(mockResource("/tmp"));
children.add(mockResource("/var"));
} else if ("/var".equals(parent.getPath())) {
children.add(mockResource("/var/one"));
children.add(mockResource("/var/two"));
children.add(mockResource("/var/three"));
} else if ("/tmp".equals(parent.getPath())) {
children.add(mockResource("/tmp/A"));
children.add(mockResource("/tmp/B"));
children.add(mockResource("/tmp/C"));
children.add(mockResource("/tmp/D"));
}
return children.iterator();
}
};
ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
final CommonResourceResolverFactoryImpl crf = new CommonResourceResolverFactoryImpl(activator) {
@Override
public ResourceDecoratorTracker getResourceDecoratorTracker() {
return t;
}
@Override
public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
return new ResourceAccessSecurityTracker();
}
};
final List<ResourceProviderHandler> list = Arrays.asList(MockedResourceResolverImplTest.createRPHandler(provider, "A-provider", 0L, "/"));
resolver = new ResourceResolverImpl(crf, false, null, new ResourceProviderStorageProvider() {
@Override
public ResourceProviderStorage getResourceProviderStorage() {
return new ResourceProviderStorage(list);
}
});
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage in project sling by apache.
the class ProviderHandlerTest method testServletRegistrationAndSyntheticResources.
@SuppressWarnings("unchecked")
@Test
public void testServletRegistrationAndSyntheticResources() throws LoginException {
final String servletpath = "/libs/a/b/GET.servlet";
final Resource servletResource = Mockito.mock(Resource.class);
Mockito.when(servletResource.getResourceMetadata()).then(new Answer<ResourceMetadata>() {
@Override
public ResourceMetadata answer(InvocationOnMock invocation) throws Throwable {
return new ResourceMetadata();
}
});
final ResourceProvider<?> leaveProvider = Mockito.mock(ResourceProvider.class);
Mockito.when(leaveProvider.getResource(Mockito.any(ResolveContext.class), Mockito.eq(servletpath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(servletResource);
final ResourceProviderHandler h = createRPHandler(leaveProvider, "my-pid", 0, servletpath);
ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
ResourceResolver resolver = new ResourceResolverImpl(new CommonResourceResolverFactoryImpl(activator), false, null, new ResourceProviderStorageProvider() {
@Override
public ResourceProviderStorage getResourceProviderStorage() {
return new ResourceProviderStorage(Arrays.asList(h));
}
});
final Resource parent = resolver.getResource(ResourceUtil.getParent(servletpath));
assertNotNull("Parent must be available", parent);
assertTrue("Resource should be synthetic", ResourceUtil.isSyntheticResource(parent));
final Resource servlet = resolver.getResource(servletpath);
assertNotNull("Servlet resource must not be null", servlet);
assertEquals(servletResource, servlet);
assertNotNull(resolver.getResource("/libs"));
// now check when doing a resolve()
assertTrue(resolver.resolve("/libs") instanceof NonExistingResource);
assertTrue(resolver.resolve(ResourceUtil.getParent(servletpath)) instanceof NonExistingResource);
assertNotNull(resolver.resolve(servletpath));
resolver.close();
}
use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage 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