Author: radu Date: Tue Nov 29 17:43:04 2016 New Revision: 1771929 URL: http://svn.apache.org/viewvc?rev=1771929&view=rev Log: SLING-6165 - Expose a service for Sling Scripting that provides request-scoped Resource Resolvers for scripting dependencies
* removed redundant tests covered by the RRW from SLING-6336 * updated imports to accommodate SLING-6336 API Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverTest.java Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java?rev=1771929&r1=1771928&r2=1771929&view=diff ============================================================================== --- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java (original) +++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java Tue Nov 29 17:43:04 2016 @@ -23,7 +23,7 @@ import javax.annotation.Nonnull; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.ResourceResolver; -import org.apache.sling.api.resource.ResourceResolverWrapper; +import org.apache.sling.api.wrappers.ResourceResolverWrapper; import org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Modified: sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverTest.java?rev=1771929&r1=1771928&r2=1771929&view=diff ============================================================================== --- sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverTest.java (original) +++ sling/trunk/bundles/scripting/core/src/test/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverTest.java Tue Nov 29 17:43:04 2016 @@ -16,154 +16,45 @@ ******************************************************************************/ package org.apache.sling.scripting.core.impl; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; import org.apache.sling.api.resource.LoginException; -import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; @SuppressWarnings({"unchecked", "deprecation"}) public class ScriptingResourceResolverTest { - private static final String PATH = "path"; - public static final String QUERY = "query"; - public static final String LANGUAGE = "language"; - private static ScriptingResourceResolver scriptingResourceResolver; - private static ResourceResolver delegate = mock(ResourceResolver.class); - private static ResourceResolver delegateClone = mock(ResourceResolver.class); + private ScriptingResourceResolver scriptingResourceResolver; + private ResourceResolver delegate; + private ResourceResolver delegateClone; private static final String[] searchPaths = {"/apps", "/libs"}; - @BeforeClass - public static void setUpTestSuite() throws LoginException { + @Before + public void setUpTestSuite() throws LoginException { + delegate = mock(ResourceResolver.class); + delegateClone = mock(ResourceResolver.class); when(delegate.clone(null)).thenReturn(delegateClone); when(delegateClone.getSearchPath()).thenReturn(searchPaths); scriptingResourceResolver = new ScriptingResourceResolver(false, delegate); } @Test - public void testResolve() throws Exception { - final HttpServletRequest request = mock(HttpServletRequest.class); - final Resource result = mock(Resource.class); - when(delegate.resolve(request, PATH)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.resolve(request, PATH)); - verify(delegate).resolve(request, PATH); - } - - @Test - public void testResolve1() throws Exception { - final HttpServletRequest request = mock(HttpServletRequest.class); - final Resource result = mock(Resource.class); - when(delegate.resolve(request)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.resolve(request)); - verify(delegate).resolve(request); - } - - @Test - public void testResolve2() throws Exception { - final Resource result = mock(Resource.class); - when(delegate.resolve(PATH)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.resolve(PATH)); - verify(delegate).resolve(PATH); - } - - @Test - public void testMap() throws Exception { - when(delegate.map(PATH)).thenReturn(PATH); - assertEquals(PATH, scriptingResourceResolver.map(PATH)); - verify(delegate).map(PATH); - } - - @Test - public void testMap1() throws Exception { - final HttpServletRequest request = mock(HttpServletRequest.class); - when(delegate.map(request, PATH)).thenReturn(PATH); - assertEquals(PATH, scriptingResourceResolver.map(request, PATH)); - verify(delegate).map(request, PATH); - } - - @Test - public void testGetResource() throws Exception { - final Resource result = mock(Resource.class); - when(delegate.getResource(PATH)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.getResource(PATH)); - verify(delegate).getResource(PATH); - } - - @Test - public void testGetResource1() throws Exception { - final Resource result = mock(Resource.class); - final Resource base = mock(Resource.class); - when(delegate.getResource(base, PATH)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.getResource(base, PATH)); - verify(delegate).getResource(base, PATH); - } - - @Test - public void testGetSearchPath() throws Exception { - when(delegate.getSearchPath()).thenReturn(searchPaths); - assertArrayEquals(searchPaths, scriptingResourceResolver.getSearchPath()); - verify(delegate).getSearchPath(); - } - - @Test - public void testListChildren() throws Exception { - final Iterator<Resource> resourceIterator = mock(Iterator.class); - final Resource base = mock(Resource.class); - when(delegate.listChildren(base)).thenReturn(resourceIterator); - assertEquals(resourceIterator, scriptingResourceResolver.listChildren(base)); - verify(delegate).listChildren(base); - } - - @Test - public void testGetParent() throws Exception { - final Resource parent = mock(Resource.class); - final Resource base = mock(Resource.class); - when(delegate.getParent(base)).thenReturn(parent); - assertEquals(parent, scriptingResourceResolver.getParent(base)); - verify(delegate).getParent(base); - } - - @Test - public void testGetChildren() throws Exception { - final List<Resource> children = mock(List.class); - final Resource base = mock(Resource.class); - when(delegate.getChildren(base)).thenReturn(children); - assertEquals(children, scriptingResourceResolver.getChildren(base)); - verify(delegate).getChildren(base); - } - - @Test - public void testFindResources() throws Exception { - final Iterator<Resource> result = mock(Iterator.class); - when(delegate.findResources(QUERY, LANGUAGE)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.findResources(QUERY, LANGUAGE)); - verify(delegate).findResources(QUERY, LANGUAGE); - } - - @Test - public void testQueryResources() throws Exception { - final Iterator<Map<String, Object>> result = mock(Iterator.class); - when(delegate.queryResources(QUERY, LANGUAGE)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.queryResources(QUERY, LANGUAGE)); - verify(delegate).queryResources(QUERY, LANGUAGE); + public void testClose() throws Exception { + scriptingResourceResolver.close(); + verify(delegate, times(0)).close(); } @Test - public void testHasChildren() throws Exception { - final Resource base = mock(Resource.class); - when(delegate.hasChildren(base)).thenReturn(true); - assertTrue(scriptingResourceResolver.hasChildren(base)); - verify(delegate).hasChildren(base); + public void test_close() throws Exception { + scriptingResourceResolver._close(); + verify(delegate).close(); } @Test @@ -176,142 +67,4 @@ public class ScriptingResourceResolverTe verify(delegateClone).getSearchPath(); } - @Test - public void testIsLive() throws Exception { - when(delegate.isLive()).thenReturn(true); - assertTrue(scriptingResourceResolver.isLive()); - verify(delegate).isLive(); - } - - @Test - public void testClose() throws Exception { - scriptingResourceResolver.close(); - verify(delegate, times(0)).close(); - } - - @Test - public void test_close() throws Exception { - scriptingResourceResolver._close(); - verify(delegate).close(); - } - - @Test - public void testGetUserID() throws Exception { - when(delegate.getUserID()).thenReturn("sling-scripting"); - assertEquals("sling-scripting", scriptingResourceResolver.getUserID()); - verify(delegate).getUserID(); - } - - @Test - public void testGetAttributeNames() throws Exception { - final Iterator<String> result = mock(Iterator.class); - when(delegate.getAttributeNames()).thenReturn(result); - assertEquals(result, scriptingResourceResolver.getAttributeNames()); - verify(delegate).getAttributeNames(); - } - - @Test - public void testGetAttribute() throws Exception { - final String attributeName = "attributeName"; - final String attributeValue = "attributeValue"; - when(delegate.getAttribute(attributeName)).thenReturn(attributeValue); - assertEquals(attributeValue, scriptingResourceResolver.getAttribute(attributeName)); - verify(delegate).getAttribute(attributeName); - } - - @Test - public void testDelete() throws Exception { - final Resource resource = mock(Resource.class); - scriptingResourceResolver.delete(resource); - verify(delegate).delete(resource); - } - - @Test - public void testCreate() throws Exception { - final Resource parent = mock(Resource.class); - final Map<String, Object> properties = mock(Map.class); - final Resource result = mock(Resource.class); - when(delegate.create(parent, PATH, properties)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.create(parent, PATH, properties)); - verify(delegate).create(parent, PATH, properties); - } - - @Test - public void testRevert() throws Exception { - scriptingResourceResolver.revert(); - verify(delegate).revert(); - } - - @Test - public void testCommit() throws Exception { - scriptingResourceResolver.commit(); - verify(delegate).commit(); - } - - @Test - public void testHasChanges() throws Exception { - when(delegate.hasChanges()).thenReturn(true); - assertTrue(scriptingResourceResolver.hasChanges()); - verify(delegate).hasChanges(); - } - - @Test - public void testGetParentResourceType() throws Exception { - final String resourceType = "a/b/c"; - final Resource resource = mock(Resource.class); - when(delegate.getParentResourceType(resource)).thenReturn(resourceType); - assertEquals(resourceType, scriptingResourceResolver.getParentResourceType(resource)); - verify(delegate).getParentResourceType(resource); - } - - @Test - public void testGetParentResourceType1() throws Exception { - final String resourceType = "a/b/c"; - when(delegate.getParentResourceType(PATH)).thenReturn(resourceType); - assertEquals(resourceType, scriptingResourceResolver.getParentResourceType(PATH)); - verify(delegate).getParentResourceType(PATH); - } - - @Test - public void testIsResourceType() throws Exception { - final Resource resource = mock(Resource.class); - final String resourceType = "a/b/c"; - when(delegate.isResourceType(resource, resourceType)).thenReturn(true); - assertTrue(scriptingResourceResolver.isResourceType(resource, resourceType)); - verify(delegate).isResourceType(resource, resourceType); - } - - @Test - public void testRefresh() throws Exception { - scriptingResourceResolver.refresh(); - verify(delegate).refresh(); - } - - @Test - public void testCopy() throws Exception { - final String source = "source"; - final String destination = "destination"; - final Resource result = mock(Resource.class); - when(delegate.copy(source, destination)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.copy(source, destination)); - verify(delegate).copy(source, destination); - } - - @Test - public void testMove() throws Exception { - final String source = "source"; - final String destination = "destination"; - final Resource result = mock(Resource.class); - when(delegate.move(source, destination)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.move(source, destination)); - verify(delegate).move(source, destination); - } - - @Test - public void testAdaptTo() throws Exception { - final String result = "result"; - when(delegate.adaptTo(String.class)).thenReturn(result); - assertEquals(result, scriptingResourceResolver.adaptTo(String.class)); - verify(delegate).adaptTo(String.class); - } }