You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/07/06 13:27:48 UTC

svn commit: r1751679 - /sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java

Author: bdelacretaz
Date: Wed Jul  6 13:27:48 2016
New Revision: 1751679

URL: http://svn.apache.org/viewvc?rev=1751679&view=rev
Log:
SLING-5682 - add tests for createPrincipal* methods, contributed by Nicolas Peltier, thanks!

Modified:
    sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java

Modified: sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java?rev=1751679&r1=1751678&r2=1751679&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java Wed Jul  6 13:27:48 2016
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.LinkedHashMap;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -259,6 +260,49 @@ public class JsonReaderTest {
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
+    }
+
+    @org.junit.Test public void testCreateOnePrincipal() throws Exception {
+        String json = "{\"security:principals\":{ " +
+                "    \"name\" : \"username2\"," +
+                "    \"password\" : \"pwd2\"" +
+                "  }}";
+        final LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+        map.put("foo","bar");
+        this.mockery.checking(new Expectations() {{
+            allowing(creator).createNode(null, null, null);
+            allowing(creator).createUser("username2", "pwd2",new LinkedHashMap<String, Object>());
+            allowing(creator).finishNode(); inSequence(mySequence);
+        }});
+        this.parse(json);
+    }
+
+    @org.junit.Test public void testCreatePrincipals() throws Exception {
+        String json = "{\"security:principals\":[ " +
+                "  { " +
+                "    \"name\" : \"username1\"," +
+                "    \"password\" : \"pwd1\"," +
+                "    \"foo\" : \"bar\"" +
+                "  }," +
+                "  { " +
+                "    \"name\" : \"username2\"," +
+                "    \"password\" : \"pwd2\"" +
+                "  }," +
+                "  { " +
+                "    \"name\" : \"group1\"," +
+                "    \"isgroup\" : true," +
+                "    \"members\" : [\"username1\",\"username2\"]" +
+                "  }]}";
+        final LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+        map.put("foo","bar");
+        this.mockery.checking(new Expectations() {{
+            allowing(creator).createNode(null, null, null);
+            allowing(creator).createUser("username1", "pwd1", map);
+            allowing(creator).createUser("username2", "pwd2",new LinkedHashMap<String, Object>());
+            allowing(creator).createGroup("group1", new String[]{"username1","username2"}, new LinkedHashMap<String, Object>());
+            allowing(creator).finishNode(); inSequence(mySequence);
+        }});
+        this.parse(json);
     }