This is an automated email from the ASF dual-hosted git repository.

angela pushed a commit to branch SLING-9692
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/SLING-9692 by this push:
     new aa36197  SLING-9692 : Add support for principal-based access control 
entries (test cleanup)
aa36197 is described below

commit aa36197afce45d2e4e8a8dc2e1dc4f92713f9a0f
Author: angela <[email protected]>
AuthorDate: Fri Jan 15 12:21:43 2021 +0100

    SLING-9692 : Add support for principal-based access control entries (test 
cleanup)
---
 .../feature/cpconverter/handlers/ParseResult.java     | 16 +++++++++++++---
 .../handlers/RepPolicyEntryHandlerTest.java           | 19 +++----------------
 .../handlers/RepPrincipalPolicyEntryHandlerTest.java  | 12 ------------
 .../handlers/RepRepoPolicyEntryHandlerTest.java       |  9 ++++-----
 4 files changed, 20 insertions(+), 36 deletions(-)

diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
index 2a8c75b..7f82909 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ParseResult.java
@@ -17,22 +17,32 @@
 package org.apache.sling.feature.cpconverter.handlers;
 
 import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 final class ParseResult {
 
     private final Extension repoinitExtension;
     private final String excludedAcls;
 
-    public ParseResult(Extension repoinitExtension, String excludedAcls) {
+    ParseResult(@Nullable Extension repoinitExtension, @NotNull String 
excludedAcls) {
+        assertNotNull(repoinitExtension);
+        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
         this.repoinitExtension = repoinitExtension;
         this.excludedAcls = excludedAcls;
     }
 
-    public Extension getRepoinitExtension() {
+    @NotNull
+    Extension getRepoinitExtension() {
         return repoinitExtension;
     }
 
-    public String getExcludedAcls() {
+    @NotNull
+    String getExcludedAcls() {
         return excludedAcls;
     }
 }
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
index d72adb6..e1c4b48 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPolicyEntryHandlerTest.java
@@ -82,8 +82,6 @@ public final class RepPolicyEntryHandlerTest {
                                                           
"acs-commons-ensure-service-user-service",
                                                           
"acs-commons-automatic-package-replicator-service",
                                                           
"acs-commons-on-deploy-scripts-service").getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
 
         // commented ACLs are due SLING-8561
         String expected =
@@ -130,9 +128,6 @@ public final class RepPolicyEntryHandlerTest {
                                                  
"acs-commons-on-deploy-scripts-service");
         Extension repoinitExtension = result.getRepoinitExtension();
 
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user 
acs-commons-package-replication-status-event-service with path 
/home/users/system" + System.lineSeparator() +
                 "create service user acs-commons-ensure-service-user-service 
with path /home/users/system" + System.lineSeparator() +
@@ -176,9 +171,6 @@ public final class RepPolicyEntryHandlerTest {
         ParseResult result = parseAndSetRepoinit(new 
SystemUser("acs-commons-package-replication-status-event-service",
                 new RepoPath("/this/is/a/completely/different/path/foo"), new 
RepoPath("/this/is/a/completely/different/path")));
         Extension repoinitExtension = result.getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user 
acs-commons-package-replication-status-event-service with path 
/this/is/a/completely/different/path" + System.lineSeparator() +
                 "set ACL for 
acs-commons-package-replication-status-event-service" + System.lineSeparator() +
@@ -210,8 +202,8 @@ public final class RepPolicyEntryHandlerTest {
 
     @Test
     public void parseEmptyAcl() throws Exception {
-        Extension repoinitExtension = parseAndSetRepoinit(new String[] 
{}).getRepoinitExtension();
-        assertNull(repoinitExtension);
+        Extension extension = TestUtils.createRepoInitExtension(handler, new 
DefaultAclManager(), "/jcr_root/home/users/system/asd/_rep_policy.xml", 
getClass().getResourceAsStream("/jcr_root/home/users/system/asd/_rep_policy.xml".substring(1)),
 new ByteArrayOutputStream());
+        assertNull(extension);
     }
 
     @Test
@@ -223,8 +215,6 @@ public final class RepPolicyEntryHandlerTest {
 
         ParseResult result = 
parseAndSetRepoInit("/jcr_root/home/groups/g/_rep_policy.xml", aclManager);
         Extension repoinitExtension = result.getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
 
         String expected =
                 "create service user service1 with path 
/home/users/system/services" + System.lineSeparator() +
@@ -246,8 +236,6 @@ public final class RepPolicyEntryHandlerTest {
 
         ParseResult result = 
parseAndSetRepoInit("/jcr_root/home/groups/g/HjDnfdMCjekaF4jhhUvO/_rep_policy.xml",
 aclManager);
         Extension repoinitExtension = result.getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
 
         String expected =
                 "create service user service1 with path 
/home/users/system/services" + System.lineSeparator() +
@@ -305,8 +293,7 @@ public final class RepPolicyEntryHandlerTest {
         for (SystemUser systemUser : systemUsers) {
             aclManager.addSystemUser(systemUser);
         }
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        return new ParseResult(TestUtils.createRepoInitExtension(handler, 
aclManager, path, getClass().getResourceAsStream(path.substring(1)), baos), new 
String(baos.toByteArray()));
+        return parseAndSetRepoInit(path, aclManager);
     }
 
     @NotNull
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
index 46ebd97..9849b4f 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepPrincipalPolicyEntryHandlerTest.java
@@ -69,9 +69,6 @@ public final class RepPrincipalPolicyEntryHandlerTest {
     @Test
     public void parseSimplePolicy() throws Exception {
         Extension repoinitExtension = parseAndSetRepoinit("service1", 
"random1").getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user service1 with path 
/home/users/system/services" + System.lineSeparator() +
                 "set principal ACL for service1\n" +
@@ -89,9 +86,6 @@ public final class RepPrincipalPolicyEntryHandlerTest {
     @Test
     public void parseMvRestrictions() throws Exception {
         Extension repoinitExtension = parseAndSetRepoinit("service2", 
"random2").getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user service2 with path 
/home/users/system/services" + System.lineSeparator() +
                         "set principal ACL for service2\n" +
@@ -116,9 +110,6 @@ public final class RepPrincipalPolicyEntryHandlerTest {
         SystemUser systemUser4 = createSystemUser("service4", "random4");
 
         Extension repoinitExtension = 
parseAndSetRepoinit(getPolicyPath(systemUser4), 
systemUser4).getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user service4 with path 
/home/users/system/services" + System.lineSeparator() +
                 "set principal ACL for service4" + System.lineSeparator() +
@@ -140,9 +131,6 @@ public final class RepPrincipalPolicyEntryHandlerTest {
         SystemUser systemUser4 = createSystemUser("service4", "random4");
 
         Extension repoinitExtension = 
parseAndSetRepoinit(getPolicyPath(systemUser4), systemUser4, 
systemUser3).getRepoinitExtension();
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-
         String expected =
                 "create service user service4 with path 
/home/users/system/services" + System.lineSeparator() +
                 "create service user service3 with path 
/home/users/system/services" + System.lineSeparator() +
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
index f70c6f4..cf65878 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/RepRepoPolicyEntryHandlerTest.java
@@ -29,6 +29,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
 import java.io.StringReader;
 import java.util.List;
 
@@ -67,11 +69,8 @@ public class RepRepoPolicyEntryHandlerTest {
         String path = "/jcr_root/_rep_repoPolicy.xml";
         AclManager aclManager = new DefaultAclManager();
         aclManager.addSystemUser(new SystemUser("repolevel-service", new 
RepoPath("/home/users/system/test"), new RepoPath("/home/users/system")));
-        Extension repoinitExtension = 
TestUtils.createRepoInitExtension(handler, aclManager, path, 
getClass().getResourceAsStream(path.substring(1)));
-
-        assertNotNull(repoinitExtension);
-        assertEquals(ExtensionType.TEXT, repoinitExtension.getType());
-        assertTrue(repoinitExtension.isRequired());
+        OutputStream out = new ByteArrayOutputStream();
+        Extension repoinitExtension = new 
ParseResult(TestUtils.createRepoInitExtension(handler, aclManager, path, 
getClass().getResourceAsStream(path.substring(1)), out), 
out.toString()).getRepoinitExtension();
 
         String expectedEnd =
                 "set ACL for repolevel-service" + System.lineSeparator() +

Reply via email to