Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EFA8B11649 for ; Tue, 1 Jul 2014 16:31:28 +0000 (UTC) Received: (qmail 4997 invoked by uid 500); 1 Jul 2014 16:31:28 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 4931 invoked by uid 500); 1 Jul 2014 16:31:28 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 4922 invoked by uid 99); 1 Jul 2014 16:31:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jul 2014 16:31:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jul 2014 16:31:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2369523888D2; Tue, 1 Jul 2014 16:31:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1607132 - /sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Date: Tue, 01 Jul 2014 16:31:07 -0000 To: commits@sling.apache.org From: asanso@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140701163107.2369523888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: asanso Date: Tue Jul 1 16:31:06 2014 New Revision: 1607132 URL: http://svn.apache.org/r1607132 Log: SLING-3712 - Increase code coverage for MapEntries Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1607132&r1=1607131&r2=1607132&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java (original) +++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java Tue Jul 1 16:31:06 2014 @@ -356,9 +356,9 @@ public class MapEntriesTest { method.invoke(mapEntries, "/justVanityPath"); entries = mapEntries.getResolveMaps(); - assertEquals(2, entries.size()); + //bad vanity Resource badVanityPath = mock(Resource.class, "badVanityPath"); when(resourceResolver.getResource("/badVanityPath")).thenReturn(badVanityPath); when(badVanityPath.getPath()).thenReturn("/badVanityPath"); @@ -373,6 +373,7 @@ public class MapEntriesTest { vanityTargets = (Map>) field.get(mapEntries); assertEquals(1, vanityTargets.size()); + //vanity under jcr:content Resource vanityPathOnJcrContentParent = mock(Resource.class, "vanityPathOnJcrContentParent"); when(vanityPathOnJcrContentParent.getPath()).thenReturn("/vanityPathOnJcrContent"); when(vanityPathOnJcrContentParent.getName()).thenReturn("vanityPathOnJcrContent"); @@ -423,18 +424,122 @@ public class MapEntriesTest { method.invoke(mapEntries, "/justVanityPath"); assertEquals(2, resolveMapsMap.size()); - + assertEquals(1, vanityTargets.size()); assertNotNull(resolveMapsMap.get("/target/justVanityPath")); assertNull(resolveMapsMap.get("/target/justVanityPathUpdated")); assertEquals(1, vanityTargets.get("/justVanityPath").size()); assertEquals("/target/justVanityPath", vanityTargets.get("/justVanityPath").get(0)); + //update vanity path when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPathUpdated")); method1.invoke(mapEntries, "/justVanityPath"); + assertEquals(2, resolveMapsMap.size()); + assertEquals(1, vanityTargets.size()); assertNull(resolveMapsMap.get("/target/justVanityPath")); assertNotNull(resolveMapsMap.get("/target/justVanityPathUpdated")); assertEquals(1, vanityTargets.get("/justVanityPath").size()); assertEquals("/target/justVanityPathUpdated", vanityTargets.get("/justVanityPath").get(0)); + + //vanity under jcr:content + Resource vanityPathOnJcrContentParent = mock(Resource.class, "vanityPathOnJcrContentParent"); + when(vanityPathOnJcrContentParent.getPath()).thenReturn("/vanityPathOnJcrContent"); + when(vanityPathOnJcrContentParent.getName()).thenReturn("vanityPathOnJcrContent"); + + Resource vanityPathOnJcrContent = mock(Resource.class, "vanityPathOnJcrContent"); + when(resourceResolver.getResource("/vanityPathOnJcrContent/jcr:content")).thenReturn(vanityPathOnJcrContent); + when(vanityPathOnJcrContent.getPath()).thenReturn("/vanityPathOnJcrContent/jcr:content"); + when(vanityPathOnJcrContent.getName()).thenReturn("jcr:content"); + when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent); + when(vanityPathOnJcrContent.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/vanityPathOnJcrContent")); + + method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content"); + + assertEquals(3, resolveMapsMap.size()); + assertEquals(2, vanityTargets.size()); + assertNotNull(resolveMapsMap.get("/target/vanityPathOnJcrContent")); + assertNull(resolveMapsMap.get("/target/vanityPathOnJcrContentUpdated")); + assertEquals(1, vanityTargets.get("/vanityPathOnJcrContent").size()); + assertEquals("/target/vanityPathOnJcrContent", vanityTargets.get("/vanityPathOnJcrContent").get(0)); + + //update vanity path + when(vanityPathOnJcrContent.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/vanityPathOnJcrContentUpdated")); + method1.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content"); + + assertEquals(3, resolveMapsMap.size()); + assertEquals(2, vanityTargets.size()); + assertNull(resolveMapsMap.get("/target/vanityPathOnJcrContent")); + assertNotNull(resolveMapsMap.get("/target/vanityPathOnJcrContentUpdated")); + assertEquals(1, vanityTargets.get("/vanityPathOnJcrContent").size()); + assertEquals("/target/vanityPathOnJcrContentUpdated", vanityTargets.get("/vanityPathOnJcrContent").get(0)); } + + @Test + public void test_doRemoveVanity() throws Exception { + Field field0 = MapEntries.class.getDeclaredField("resolveMapsMap"); + field0.setAccessible(true); + Map> resolveMapsMap = (Map>) field0.get(mapEntries); + assertEquals(1, resolveMapsMap.size()); + + Field field = MapEntries.class.getDeclaredField("vanityTargets"); + field.setAccessible(true); + Map> vanityTargets = (Map>) field.get(mapEntries); + assertEquals(0, vanityTargets.size()); + + Method method = MapEntries.class.getDeclaredMethod("doAddVanity", String.class); + method.setAccessible(true); + + Method method1 = MapEntries.class.getDeclaredMethod("doRemoveVanity", String.class); + method1.setAccessible(true); + + Resource justVanityPath = mock(Resource.class, "justVanityPath"); + when(resourceResolver.getResource("/justVanityPath")).thenReturn(justVanityPath); + when(justVanityPath.getPath()).thenReturn("/justVanityPath"); + when(justVanityPath.getName()).thenReturn("justVanityPath"); + when(justVanityPath.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPath")); + + method.invoke(mapEntries, "/justVanityPath"); + + assertEquals(2, resolveMapsMap.size()); + assertEquals(1, vanityTargets.size()); + assertNotNull(resolveMapsMap.get("/target/justVanityPath")); + assertEquals(1, vanityTargets.get("/justVanityPath").size()); + assertEquals("/target/justVanityPath", vanityTargets.get("/justVanityPath").get(0)); + + //remove vanity path + method1.invoke(mapEntries, "/justVanityPath"); + + assertEquals(1, resolveMapsMap.size()); + assertEquals(0, vanityTargets.size()); + assertNull(resolveMapsMap.get("/target/justVanityPath")); + + //vanity under jcr:content + Resource vanityPathOnJcrContentParent = mock(Resource.class, "vanityPathOnJcrContentParent"); + when(vanityPathOnJcrContentParent.getPath()).thenReturn("/vanityPathOnJcrContent"); + when(vanityPathOnJcrContentParent.getName()).thenReturn("vanityPathOnJcrContent"); + + Resource vanityPathOnJcrContent = mock(Resource.class, "vanityPathOnJcrContent"); + when(resourceResolver.getResource("/vanityPathOnJcrContent/jcr:content")).thenReturn(vanityPathOnJcrContent); + when(vanityPathOnJcrContent.getPath()).thenReturn("/vanityPathOnJcrContent/jcr:content"); + when(vanityPathOnJcrContent.getName()).thenReturn("jcr:content"); + when(vanityPathOnJcrContent.getParent()).thenReturn(vanityPathOnJcrContentParent); + when(vanityPathOnJcrContent.adaptTo(ValueMap.class)).thenReturn(buildValueMap("sling:vanityPath", "/target/vanityPathOnJcrContent")); + + method.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content"); + + assertEquals(2, resolveMapsMap.size()); + assertEquals(1, vanityTargets.size()); + assertNotNull(resolveMapsMap.get("/target/vanityPathOnJcrContent")); + assertEquals(1,vanityTargets.get("/vanityPathOnJcrContent").size()); + assertEquals("/target/vanityPathOnJcrContent", vanityTargets.get("/vanityPathOnJcrContent").get(0)); + + //remove vanity path + method1.invoke(mapEntries, "/vanityPathOnJcrContent/jcr:content"); + + assertEquals(1, resolveMapsMap.size()); + assertEquals(0, vanityTargets.size()); + assertNull(resolveMapsMap.get("/target/vanityPathOnJcrContent")); + + } + }