use of org.apache.sling.api.resource.ResourceMetadata 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.api.resource.ResourceMetadata in project sling by apache.
the class StarResourceTest method assertSplit.
private void assertSplit(String requestPath, String path, String pathInfo) {
final ResourceMetadata rm = StarResource.getResourceMetadata(requestPath);
assertEquals("For requestPath=" + requestPath + ", path matches", path, rm.getResolutionPath());
assertEquals("For requestPath=" + requestPath + ", pathInfo matches", pathInfo, rm.getResolutionPathInfo());
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class SightlyJavaCompilerServiceTest method testDiskCachedUseObject.
@Test
public void testDiskCachedUseObject() throws Exception {
String pojoPath = "/apps/myproject/testcomponents/a/Pojo.java";
String className = "apps.myproject.testcomponents.a.Pojo";
scriptingResourceResolverProvider = Mockito.mock(ScriptingResourceResolverProvider.class);
ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
when(scriptingResourceResolverProvider.getRequestScopedResourceResolver()).thenReturn(resolver);
Resource pojoResource = Mockito.mock(Resource.class);
when(pojoResource.getPath()).thenReturn(pojoPath);
ResourceMetadata mockMetadata = Mockito.mock(ResourceMetadata.class);
when(mockMetadata.getModificationTime()).thenReturn(1l);
when(pojoResource.getResourceMetadata()).thenReturn(mockMetadata);
when(pojoResource.adaptTo(InputStream.class)).thenReturn(IOUtils.toInputStream("DUMMY", "UTF-8"));
when(resolver.getResource(pojoPath)).thenReturn(pojoResource);
when(classLoaderWriter.getLastModified("/apps/myproject/testcomponents/a/Pojo.class")).thenReturn(2l);
getInstancePojoTest(className);
/*
* assuming the compiled class has a last modified date greater than the source, then the compiler should not recompile the Use
* object
*/
verify(compiler, never()).compileSource(any(SourceIdentifier.class), anyString());
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class SlingIOProvider method lastModified.
/**
* Returns the value of the last modified meta data field of the resource
* found at file name or zero if the meta data field is not set. If the
* resource does not exist or an error occurrs finding the resource, -1 is
* returned.
*/
public long lastModified(final String path) {
if (path.startsWith(":")) {
return this.classLoaderWriter.getLastModified(path.substring(1));
}
ResourceResolver resolver = requestResourceResolver.get();
if (resolver != null) {
try {
final Resource resource = resolver.getResource(cleanPath(path, true));
if (resource != null) {
ResourceMetadata meta = resource.getResourceMetadata();
long modTime = meta.getModificationTime();
return (modTime > 0) ? modTime : 0;
}
} catch (final SlingException se) {
log.error("Cannot get last modification time for " + path, se);
}
}
// fallback to "non-existant" in case of problems
return -1;
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class ScriptableResourceTest method assertResourceMetaData.
private void assertResourceMetaData(Object metaData) throws Exception {
if (metaData instanceof ResourceMetadata) {
ResourceMetadata rm = (ResourceMetadata) metaData;
rm.getResolutionPath().equals(node.getPath());
} else {
fail("Expected ResourceMetadata, got " + metaData);
}
}
Aggregations