Search in sources :

Example 1 with ResourceMetadata

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;
}
Also used : NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 2 with ResourceMetadata

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());
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) SourceIdentifier(org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier) ScriptingResourceResolverProvider(org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) Test(org.junit.Test)

Example 3 with ResourceMetadata

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));
}
Also used : Resource(org.apache.sling.api.resource.Resource) ValidationResult(org.apache.sling.validation.ValidationResult) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) Test(org.junit.Test)

Example 4 with ResourceMetadata

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");
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Resource(org.apache.sling.api.resource.Resource) ServletContext(javax.servlet.ServletContext) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata) Test(org.junit.Test)

Example 5 with ResourceMetadata

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;
}
Also used : ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Aggregations

ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)32 Resource (org.apache.sling.api.resource.Resource)15 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 Test (org.junit.Test)6 AbstractResourceImpl (com.adobe.acs.commons.mcp.impl.AbstractResourceImpl)5 ValueMap (org.apache.sling.api.resource.ValueMap)5 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)4 InputStream (java.io.InputStream)4 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)4 HashMap (java.util.HashMap)3 BufferedInputStream (java.io.BufferedInputStream)2 ArrayList (java.util.ArrayList)2 Session (javax.jcr.Session)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 Privilege (javax.jcr.security.Privilege)2 SlingException (org.apache.sling.api.SlingException)2 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)2 ScriptingResourceResolverProvider (org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider)2 SourceIdentifier (org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2