use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ScriptCacheImpl method activate.
@Activate
protected void activate(ScriptCacheImplConfiguration configuration, BundleContext bundleCtx) {
threadPool = threadPoolManager.get("Script Cache Thread Pool");
bundleContext = bundleCtx;
additionalExtensions = configuration.org_apache_sling_scripting_cache_additional__extensions();
int newMaxCacheSize = configuration.org_apache_sling_scripting_cache_size();
if (newMaxCacheSize != DEFAULT_CACHE_SIZE) {
// change the map only if there's a configuration change regarding the cache's max size
CachingMap<CachedScript> newMap = new CachingMap<>(newMaxCacheSize);
newMap.putAll(internalMap);
internalMap = newMap;
}
ResourceResolver resolver = null;
try {
resolver = rrf.getServiceResourceResolver(null);
searchPaths = resolver.getSearchPath();
} catch (LoginException e) {
LOGGER.error("Unable to retrieve a ResourceResolver for determining the search paths.", e);
} finally {
if (resolver != null) {
resolver.close();
}
}
configureCache();
active = true;
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceProviderEntryTest method testAdd3ProvidersReverse.
@Test
public void testAdd3ProvidersReverse() throws LoginException {
String firstPath = "/rootel";
String secondPath = firstPath + "/child";
String thirdPath = "/apps/sling/sample";
final ResourceResolver firstResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> first = Mockito.mock(ResourceProvider.class);
Mockito.when(first.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(firstPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(firstResolver));
final ResourceResolver secondResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> second = Mockito.mock(ResourceProvider.class);
Mockito.when(second.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(secondPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(secondResolver));
final ResourceResolver thirdResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> third = Mockito.mock(ResourceProvider.class);
Mockito.when(third.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(thirdPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(thirdResolver));
providers.add(createRPHandler(first, "rp1", 1, firstPath));
providers.add(createRPHandler(second, "rp2", 2, secondPath));
providers.add(createRPHandler(third, "rp3", 3, thirdPath));
this.providersBasedResolver = null;
assertEqualsResolver(this.mockedRootResolver, getResource("/"));
assertEqualsResolver(firstResolver, getResource("/rootel"));
assertEqualsResolver(firstResolver, getResource("/rootel/html.js"));
assertEqualsResolver(secondResolver, getResource("/rootel/child"));
assertEqualsResolver(secondResolver, getResource("/rootel/child/html.js"));
assertEqualsResolver(thirdResolver, getResource("/apps/sling/sample/html.js"));
assertEqualsResolver(this.mockedRootResolver, getResource("/apps/sling/microsling/html.js"));
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceProviderEntryTest method testRemoveTheOnlyProvider.
@Test
public void testRemoveTheOnlyProvider() throws LoginException {
long counter = 1;
providers.clear();
for (String path : new String[] { "/foo", "/", "/foo/bar" }) {
final ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> p = Mockito.mock(ResourceProvider.class);
Mockito.when(p.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(path), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(resolver));
++counter;
ResourceProviderHandler h = createRPHandler(p, "rp" + counter, counter, path);
providers.add(h);
this.providersBasedResolver = null;
{
final Resource r = getResource(path);
assertEqualsResolver(resolver, r);
assertFalse(r instanceof SyntheticResource);
}
providers.remove(h);
this.providersBasedResolver = null;
{
final Resource r = getResource(path);
// If our provider is indeed gone, we should get one of the following conditions
if (r == null) {
//fine
} else if (!p.equals(r.getResourceResolver())) {
//fine
} else {
fail("Expecting inactive provider after removing it for " + path);
}
}
}
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceProviderEntryTest method testRemoveProviders.
@Test
public void testRemoveProviders() throws LoginException {
String firstPath = "/rootel";
String thirdPath = "/apps/sling/sample";
String secondPath = firstPath + "/child";
final ResourceResolver firstResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> first = Mockito.mock(ResourceProvider.class);
Mockito.when(first.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(firstPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(firstResolver));
final ResourceResolver secondResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> second = Mockito.mock(ResourceProvider.class);
Mockito.when(second.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(secondPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(secondResolver));
final ResourceResolver thirdResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> third = Mockito.mock(ResourceProvider.class);
Mockito.when(third.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(thirdPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(thirdResolver));
final Map<String, Object> firstProps = new HashMap<String, Object>();
firstProps.put(Constants.SERVICE_ID, (long) 1);
final Map<String, Object> secondProps = new HashMap<String, Object>();
secondProps.put(Constants.SERVICE_ID, (long) 2);
final Map<String, Object> thirdProps = new HashMap<String, Object>();
thirdProps.put(Constants.SERVICE_ID, (long) 3);
ResourceProviderHandler firstH = createRPHandler(first, "rp1", 1, firstPath);
providers.add(firstH);
providers.add(createRPHandler(second, "rp2", 2, secondPath));
providers.add(createRPHandler(third, "rp3", 3, thirdPath));
this.providersBasedResolver = null;
assertEqualsResolver(this.mockedRootResolver, getResource("/"));
assertEqualsResolver(firstResolver, getResource("/rootel/html.js"));
assertEqualsResolver(secondResolver, getResource("/rootel/child/html.js"));
providers.remove(firstH);
this.providersBasedResolver = null;
assertEqualsResolver(this.mockedRootResolver, getResource("/"));
assertEqualsResolver(this.mockedRootResolver, getResource("/rootel/sddsf/sdfsdf/html.js"));
assertEqualsResolver(this.mockedRootResolver, getResource("/rootel/html.js"));
assertEqualsResolver(secondResolver, getResource("/rootel/child/html.js"));
providers.add(firstH);
this.providersBasedResolver = null;
assertEqualsResolver(this.mockedRootResolver, getResource("/"));
assertEqualsResolver(firstResolver, getResource("/rootel/html.js"));
assertEqualsResolver(secondResolver, getResource("/rootel/child/html.js"));
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceProviderEntryTest method testAdd3Providers.
@Test
public void testAdd3Providers() throws LoginException {
String firstPath = "/rootel";
String secondPath = firstPath + "/child";
String thirdPath = "/apps/sling/sample";
final ResourceResolver firstResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> first = Mockito.mock(ResourceProvider.class);
Mockito.when(first.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(firstPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(firstResolver));
final ResourceResolver secondResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> second = Mockito.mock(ResourceProvider.class);
Mockito.when(second.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(secondPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(secondResolver));
final ResourceResolver thirdResolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider<?> third = Mockito.mock(ResourceProvider.class);
Mockito.when(third.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(thirdPath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(thirdResolver));
providers.add(createRPHandler(first, "rp1", 1, firstPath));
providers.add(createRPHandler(second, "rp2", 2, secondPath));
providers.add(createRPHandler(third, "rp3", 3, thirdPath));
this.providersBasedResolver = null;
assertEqualsResolver(this.mockedRootResolver, getResource("/"));
assertEqualsResolver(firstResolver, getResource("/rootel"));
assertEqualsResolver(firstResolver, getResource("/rootel/html.js"));
assertEqualsResolver(secondResolver, getResource("/rootel/child"));
assertEqualsResolver(secondResolver, getResource("/rootel/child/html.js"));
assertEqualsResolver(thirdResolver, getResource("/apps/sling/sample/html.js"));
assertEqualsResolver(this.mockedRootResolver, getResource("/apps/sling/microsling/html.js"));
}
Aggregations