Search in sources :

Example 1 with ScriptingResourceResolverProvider

use of org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider in project sling by apache.

the class SightlyJavaCompilerServiceTest method testObsoleteMemoryCachedUseObject.

@Test
public void testObsoleteMemoryCachedUseObject() 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);
    when(resourceBackedPojoChangeMonitor.getLastModifiedDateForJavaUseObject(pojoPath)).thenReturn(2l);
    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) Test(org.junit.Test)

Example 2 with ScriptingResourceResolverProvider

use of org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider 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 ScriptingResourceResolverProvider

use of org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider in project sling by apache.

the class SightlyJavaCompilerServiceTest method testMemoryCachedUseObject.

@Test
public void testMemoryCachedUseObject() 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);
    when(resourceBackedPojoChangeMonitor.getLastModifiedDateForJavaUseObject(pojoPath)).thenReturn(1l);
    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());
}
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) Test(org.junit.Test)

Example 4 with ScriptingResourceResolverProvider

use of org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider 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());
}
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)

Aggregations

Resource (org.apache.sling.api.resource.Resource)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 ScriptingResourceResolverProvider (org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider)4 SourceIdentifier (org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier)4 Test (org.junit.Test)4 ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)2