use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class ResourceDecoratorTestBase method mockResource.
protected Resource mockResource(String path) {
final Resource result = Mockito.mock(Resource.class);
Mockito.when(result.getPath()).thenReturn(path);
Mockito.when(result.getName()).thenReturn(ResourceUtil.getName(path));
final ResourceMetadata m = new ResourceMetadata();
Mockito.when(result.getResourceMetadata()).thenReturn(m);
return result;
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class SightlyJavaCompilerServiceTest method testObsoleteDiskCachedUseObject.
@Test
public void testObsoleteDiskCachedUseObject() 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(2l);
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(1l);
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).compileSource(any(SourceIdentifier.class), anyString());
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class ResourceToValidationResultAdapterFactoryTest method testResourceToValidationResultAdaption.
@Test
public void testResourceToValidationResultAdaption() {
final ValidationResult result = mock(ValidationResult.class);
when(result.isValid()).thenReturn(true);
when(result.getFailures()).thenReturn(Collections.emptyList());
final Resource resource = mock(Resource.class);
final ResourceMetadata metadata = mock(ResourceMetadata.class);
when(metadata.get("sling.validation.result")).thenReturn(result);
when(resource.getResourceMetadata()).thenReturn(metadata);
final ResourceToValidationResultAdapterFactory factory = new ResourceToValidationResultAdapterFactory();
final ValidationResult adapter = factory.getAdapter(resource, ValidationResult.class);
assertThat(adapter, is(result));
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class StreamRendererServletTest method test_setHeaders.
@Test
public void test_setHeaders() throws Throwable {
final Resource resource = Mockito.mock(Resource.class);
final SlingHttpServletResponse response = Mockito.mock(SlingHttpServletResponse.class);
final ResourceMetadata meta = Mockito.mock(ResourceMetadata.class);
final ServletContext sc = Mockito.mock(ServletContext.class);
StreamRendererServlet streamRendererServlet = new StreamRendererServlet(true, new String[] { "/" }) {
@Override
public ServletContext getServletContext() {
return sc;
}
};
Mockito.when(resource.getResourceMetadata()).thenReturn(meta);
PrivateAccessor.invoke(streamRendererServlet, "setHeaders", new Class[] { Resource.class, SlingHttpServletResponse.class }, new Object[] { resource, response });
Mockito.verify(response, Mockito.times(1)).setContentType("application/octet-stream");
}
use of org.apache.sling.api.resource.ResourceMetadata in project sling by apache.
the class ResourceTypeResourceWrapper method getResourceMetadata.
@Override
public ResourceMetadata getResourceMetadata() {
ResourceMetadata newResourceMetadata = new ResourceMetadata();
newResourceMetadata.putAll(getResource().getResourceMetadata());
newResourceMetadata.put(ResEditorResourceProvider.RESOURCE_EDITOR_PROVIDER_RESOURCE, null);
return newResourceMetadata;
}
Aggregations