You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/06/16 16:54:11 UTC
[sling-org-apache-sling-jcr-contentloader] 01/02: style
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit e64ec79d0160038e9811d82f72e31597218e4e04
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Jun 16 18:41:39 2019 +0200
style
---
.../contentloader/it/BasicInitialContentIT.java | 38 +--
.../contentloader/it/ContentloaderTestSupport.java | 26 +-
.../jcr/contentloader/it/I18nInitialContentIT.java | 20 +-
.../contentloader/it/OrderedInitialContentIT.java | 17 +-
.../it/SLING7268InitialContentIT.java | 202 +++++++--------
.../it/SLING8118InitialContentIT.java | 272 ++++++++++-----------
6 files changed, 292 insertions(+), 283 deletions(-)
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/BasicInitialContentIT.java b/src/test/java/org/apache/sling/jcr/contentloader/it/BasicInitialContentIT.java
index 5dbd02c..03cea41 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/BasicInitialContentIT.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/BasicInitialContentIT.java
@@ -34,7 +34,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/** Basic test of a bundle that provides initial content */
+/**
+ * Basic test of a bundle that provides initial content
+ */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class BasicInitialContentIT extends ContentloaderTestSupport {
@@ -47,41 +49,41 @@ public class BasicInitialContentIT extends ContentloaderTestSupport {
addContent(b, DEFAULT_PATH_IN_BUNDLE, "folder-with-descriptor/test2.txt");
return b;
}
-
+
@Test
public void bundleStarted() {
final Bundle b = findBundle(bundleSymbolicName);
assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
}
-
+
@Test
public void initialContentInstalled() throws RepositoryException {
- final String testNodePath = contentRootPath + "/basic-content/test-node";
- assertTrue("Expecting initial content to be installed", session.itemExists(testNodePath));
- assertEquals("Expecting foo=bar", "bar", session.getNode(testNodePath).getProperty("foo").getString());
+ final String testNodePath = contentRootPath + "/basic-content/test-node";
+ assertTrue("Expecting initial content to be installed", session.itemExists(testNodePath));
+ assertEquals("Expecting foo=bar", "bar", session.getNode(testNodePath).getProperty("foo").getString());
}
@Test
public void folderWithoutDescriptor() throws RepositoryException {
- final String folderPath = contentRootPath + "/simple-folder";
- assertTrue("folder node " + folderPath + " exists", session.itemExists(folderPath));
- assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
+ final String folderPath = contentRootPath + "/simple-folder";
+ assertTrue("folder node " + folderPath + " exists", session.itemExists(folderPath));
+ assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
- final String filePath = contentRootPath + "/simple-folder/test1.txt";
- assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
- assertEquals("file has node type 'nt:file'", "nt:file", session.getNode(filePath).getPrimaryNodeType().getName());
+ final String filePath = contentRootPath + "/simple-folder/test1.txt";
+ assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
+ assertEquals("file has node type 'nt:file'", "nt:file", session.getNode(filePath).getPrimaryNodeType().getName());
}
@Test
public void folderWithDescriptor() throws RepositoryException {
- final String folderPath = contentRootPath + "/folder-with-descriptor";
- assertTrue("folder node " + folderPath + " exists", session.itemExists(folderPath));
- assertEquals("folder has node type 'sling:OrderedFolder'", "sling:OrderedFolder", session.getNode(folderPath).getPrimaryNodeType().getName());
+ final String folderPath = contentRootPath + "/folder-with-descriptor";
+ assertTrue("folder node " + folderPath + " exists", session.itemExists(folderPath));
+ assertEquals("folder has node type 'sling:OrderedFolder'", "sling:OrderedFolder", session.getNode(folderPath).getPrimaryNodeType().getName());
- final String filePath = contentRootPath + "/folder-with-descriptor/test2.txt";
- assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
- assertEquals("file has node type 'nt:file'", "nt:file", session.getNode(filePath).getPrimaryNodeType().getName());
+ final String filePath = contentRootPath + "/folder-with-descriptor/test2.txt";
+ assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
+ assertEquals("file has node type 'nt:file'", "nt:file", session.getNode(filePath).getPrimaryNodeType().getName());
}
}
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java b/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
index 5ae7659..830aef6 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/ContentloaderTestSupport.java
@@ -87,28 +87,28 @@ public abstract class ContentloaderTestSupport extends TestSupport {
final Bundle bundle = bundleContext.installBundle(bundleSymbolicName, is);
bundle.start();
}
-
- // stabilize the downstream assertions by waiting a moment for the background content loading
+
+ // stabilize the downstream assertions by waiting a moment for the background content loading
// to be processed. Retry the checking a few times (if necessary) since the timing is tricky.
String contentLoadedPath = String.format("/var/sling/bundle-content/%s", bundleSymbolicName);
long timeoutSeconds = 30;
long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutSeconds);
boolean retry = true;
do {
- if (session.itemExists(contentLoadedPath)) {
- //stop looping
- retry = false;
- } else {
- if (System.currentTimeMillis() > timeout) {
- fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: "
- + "A content loaded node expected at " + contentLoadedPath);
- } else {
+ if (session.itemExists(contentLoadedPath)) {
+ //stop looping
+ retry = false;
+ } else {
+ if (System.currentTimeMillis() > timeout) {
+ fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: "
+ + "A content loaded node expected at " + contentLoadedPath);
+ } else {
logger.warn("Bundle content not loaded yet, retrying after a short delay, path={}", contentLoadedPath);
Thread.sleep(200);
session.refresh(false);
- }
- }
- } while (retry);
+ }
+ }
+ } while (retry);
}
@After
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/I18nInitialContentIT.java b/src/test/java/org/apache/sling/jcr/contentloader/it/I18nInitialContentIT.java
index 2d8238c..2470f3f 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/I18nInitialContentIT.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/I18nInitialContentIT.java
@@ -37,7 +37,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/** Basic test of a bundle that provides initial content */
+/**
+ * Basic test of a bundle that provides initial content
+ */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class I18nInitialContentIT extends ContentloaderTestSupport {
@@ -48,32 +50,32 @@ public class I18nInitialContentIT extends ContentloaderTestSupport {
addContent(b, DEFAULT_PATH_IN_BUNDLE, "i18n/en.json.xml");
return b;
}
-
+
@Test
public void bundleStarted() {
final Bundle b = findBundle(bundleSymbolicName);
assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
}
-
+
@Test
public void i18nJsonFile() throws RepositoryException {
- final String filePath = contentRootPath + "/i18n/en.json";
- assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
+ final String filePath = contentRootPath + "/i18n/en.json";
+ assertTrue("file node " + filePath + " exists", session.itemExists(filePath));
Node node = session.getNode(filePath);
assertEquals("file has node type 'nt:file'", "nt:file", node.getPrimaryNodeType().getName());
-
+
boolean mixLanguageFound = false;
for (NodeType mixin : node.getMixinNodeTypes()) {
if ("mix:language".equals(mixin.getName())) {
mixLanguageFound = true;
}
}
- assertTrue("file has mixin 'mix:language'", mixLanguageFound);
+ assertTrue("file has mixin 'mix:language'", mixLanguageFound);
assertEquals("file has property 'en'", "en", node.getProperty("jcr:language").getString());
- final String descriptorPath = contentRootPath + "/i18n/en.json.xml";
- assertFalse("descriptor " + descriptorPath + " does not exists", session.itemExists(descriptorPath));
+ final String descriptorPath = contentRootPath + "/i18n/en.json.xml";
+ assertFalse("descriptor " + descriptorPath + " does not exists", session.itemExists(descriptorPath));
}
}
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/OrderedInitialContentIT.java b/src/test/java/org/apache/sling/jcr/contentloader/it/OrderedInitialContentIT.java
index 268fc74..d310f4c 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/OrderedInitialContentIT.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/OrderedInitialContentIT.java
@@ -35,7 +35,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/** Test the SLING-5682 ordered content loading */
+/**
+ * Test the SLING-5682 ordered content loading
+ */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class OrderedInitialContentIT extends ContentloaderTestSupport {
@@ -45,23 +47,24 @@ public class OrderedInitialContentIT extends ContentloaderTestSupport {
addContent(b, DEFAULT_PATH_IN_BUNDLE, "ordered-content.ordered-json");
return b;
}
-
+
@Test
public void bundleStarted() {
final Bundle b = findBundle(bundleSymbolicName);
assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
}
-
+
private void assertProperty(Session session, String path, String expected) throws RepositoryException {
assertTrue("Expecting property " + path, session.itemExists(path));
final String actual = session.getProperty(path).getString();
assertEquals("Expecting correct value at " + path, expected, actual);
}
-
+
@Test
public void initialContentInstalled() throws RepositoryException {
- assertProperty(session, contentRootPath + "/ordered-content/first/title", "This comes first");
- assertProperty(session, contentRootPath + "/ordered-content/second/title", "This comes second");
+ assertProperty(session, contentRootPath + "/ordered-content/first/title", "This comes first");
+ assertProperty(session, contentRootPath + "/ordered-content/second/title", "This comes second");
}
-}
\ No newline at end of file
+
+}
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/SLING7268InitialContentIT.java b/src/test/java/org/apache/sling/jcr/contentloader/it/SLING7268InitialContentIT.java
index 164c3af..fab11f2 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/SLING7268InitialContentIT.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/SLING7268InitialContentIT.java
@@ -50,109 +50,111 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-/** test of a bundle that provides initial content that creates a user/group and defines an ace
- * for those principals within the same transaction
+/**
+ * test of a bundle that provides initial content that creates a user/group and defines an ace
+ * for those principals within the same transaction
*/
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class SLING7268InitialContentIT extends ContentloaderTestSupport {
- protected TinyBundle setupTestBundle(TinyBundle b) throws IOException {
- b.set(SLING_INITIAL_CONTENT_HEADER, DEFAULT_PATH_IN_BUNDLE + ";path:=" + contentRootPath);
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "SLING-7268.json");
- return b;
- }
-
- @Test
- public void bundleStarted() {
- final Bundle b = findBundle(bundleSymbolicName);
- assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
- assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
- }
-
- @Test
- public void initialContentInstalled() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-7268";
- assertTrue("Expecting initial content to be installed", session.itemExists(folderPath));
- assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
- }
-
- @Test
- public void userCreated() throws RepositoryException {
- UserManager userManager = AccessControlUtil.getUserManager(session);
- Authorizable authorizable = userManager.getAuthorizable("sling7268_user");
- assertNotNull("Expecting test user to exist", authorizable);
- }
-
- @Test
- public void groupCreated() throws RepositoryException {
- UserManager userManager = AccessControlUtil.getUserManager(session);
- Authorizable authorizable = userManager.getAuthorizable("sling7268_group");
- assertNotNull("Expecting test group to exist", authorizable);
- assertTrue(authorizable instanceof Group);
- Iterator<Authorizable> members = ((Group)authorizable).getMembers();
- assertTrue(members.hasNext());
- Authorizable firstMember = members.next();
- assertEquals("sling7268_user", firstMember.getID());
- }
-
- @Test
- public void aceCreated() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-7268";
- assertTrue("Expecting test folder to exist", session.itemExists(folderPath));
-
- AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
- AccessControlPolicy[] policies = accessControlManager.getPolicies(folderPath);
- List<AccessControlEntry> allEntries = new ArrayList<AccessControlEntry>();
- for (AccessControlPolicy accessControlPolicy : policies) {
- if (accessControlPolicy instanceof AccessControlList) {
- AccessControlEntry[] accessControlEntries = ((AccessControlList)accessControlPolicy).getAccessControlEntries();
- for (AccessControlEntry accessControlEntry : accessControlEntries) {
- allEntries.add(accessControlEntry);
- }
- }
- }
- assertEquals(3, allEntries.size());
- Map<String, AccessControlEntry> aceMap = new HashMap<>();
- for (AccessControlEntry accessControlEntry : allEntries) {
- aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
- }
-
- //check ACE for sling7268_user
- AccessControlEntry testUserAce = aceMap.get("sling7268_user");
- assertNotNull("Expected ACE for test user", testUserAce);
- assertEquals("sling7268_user", testUserAce.getPrincipal().getName());
- Privilege[] privileges = testUserAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(2, privileges.length);
- Set<String> privilegeNames = new HashSet<>();
- for (Privilege privilege : privileges) {
- privilegeNames.add(privilege.getName());
- }
- assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
- assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
-
- //check ACE for sling7268_group
- AccessControlEntry testGroupAce = aceMap.get("sling7268_group");
- assertNotNull("Expected ACE for test user", testGroupAce);
- assertEquals("sling7268_group", testGroupAce.getPrincipal().getName());
- privileges = testGroupAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(1, privileges.length);
- privilegeNames = new HashSet<>();
- for (Privilege privilege : privileges) {
- privilegeNames.add(privilege.getName());
- }
- assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
-
- //check ACE for everyone group
- AccessControlEntry everyoneAce = aceMap.get("everyone");
- assertNotNull("Expected ACE for everyone", everyoneAce);
- assertEquals("everyone", everyoneAce.getPrincipal().getName());
- privileges = everyoneAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(1, privileges.length);
-
- assertEquals("Expecting granted read privilege", "jcr:read", privileges[0].getName());
- }
+ protected TinyBundle setupTestBundle(TinyBundle b) throws IOException {
+ b.set(SLING_INITIAL_CONTENT_HEADER, DEFAULT_PATH_IN_BUNDLE + ";path:=" + contentRootPath);
+ addContent(b, DEFAULT_PATH_IN_BUNDLE, "SLING-7268.json");
+ return b;
+ }
+
+ @Test
+ public void bundleStarted() {
+ final Bundle b = findBundle(bundleSymbolicName);
+ assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
+ assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
+ }
+
+ @Test
+ public void initialContentInstalled() throws RepositoryException {
+ final String folderPath = contentRootPath + "/SLING-7268";
+ assertTrue("Expecting initial content to be installed", session.itemExists(folderPath));
+ assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
+ }
+
+ @Test
+ public void userCreated() throws RepositoryException {
+ UserManager userManager = AccessControlUtil.getUserManager(session);
+ Authorizable authorizable = userManager.getAuthorizable("sling7268_user");
+ assertNotNull("Expecting test user to exist", authorizable);
+ }
+
+ @Test
+ public void groupCreated() throws RepositoryException {
+ UserManager userManager = AccessControlUtil.getUserManager(session);
+ Authorizable authorizable = userManager.getAuthorizable("sling7268_group");
+ assertNotNull("Expecting test group to exist", authorizable);
+ assertTrue(authorizable instanceof Group);
+ Iterator<Authorizable> members = ((Group) authorizable).getMembers();
+ assertTrue(members.hasNext());
+ Authorizable firstMember = members.next();
+ assertEquals("sling7268_user", firstMember.getID());
+ }
+
+ @Test
+ public void aceCreated() throws RepositoryException {
+ final String folderPath = contentRootPath + "/SLING-7268";
+ assertTrue("Expecting test folder to exist", session.itemExists(folderPath));
+
+ AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
+ AccessControlPolicy[] policies = accessControlManager.getPolicies(folderPath);
+ List<AccessControlEntry> allEntries = new ArrayList<AccessControlEntry>();
+ for (AccessControlPolicy accessControlPolicy : policies) {
+ if (accessControlPolicy instanceof AccessControlList) {
+ AccessControlEntry[] accessControlEntries = ((AccessControlList) accessControlPolicy).getAccessControlEntries();
+ for (AccessControlEntry accessControlEntry : accessControlEntries) {
+ allEntries.add(accessControlEntry);
+ }
+ }
+ }
+ assertEquals(3, allEntries.size());
+ Map<String, AccessControlEntry> aceMap = new HashMap<>();
+ for (AccessControlEntry accessControlEntry : allEntries) {
+ aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
+ }
+
+ //check ACE for sling7268_user
+ AccessControlEntry testUserAce = aceMap.get("sling7268_user");
+ assertNotNull("Expected ACE for test user", testUserAce);
+ assertEquals("sling7268_user", testUserAce.getPrincipal().getName());
+ Privilege[] privileges = testUserAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(2, privileges.length);
+ Set<String> privilegeNames = new HashSet<>();
+ for (Privilege privilege : privileges) {
+ privilegeNames.add(privilege.getName());
+ }
+ assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
+ assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
+
+ //check ACE for sling7268_group
+ AccessControlEntry testGroupAce = aceMap.get("sling7268_group");
+ assertNotNull("Expected ACE for test user", testGroupAce);
+ assertEquals("sling7268_group", testGroupAce.getPrincipal().getName());
+ privileges = testGroupAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(1, privileges.length);
+ privilegeNames = new HashSet<>();
+ for (Privilege privilege : privileges) {
+ privilegeNames.add(privilege.getName());
+ }
+ assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
+
+ //check ACE for everyone group
+ AccessControlEntry everyoneAce = aceMap.get("everyone");
+ assertNotNull("Expected ACE for everyone", everyoneAce);
+ assertEquals("everyone", everyoneAce.getPrincipal().getName());
+ privileges = everyoneAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(1, privileges.length);
+
+ assertEquals("Expecting granted read privilege", "jcr:read", privileges[0].getName());
+ }
+
}
diff --git a/src/test/java/org/apache/sling/jcr/contentloader/it/SLING8118InitialContentIT.java b/src/test/java/org/apache/sling/jcr/contentloader/it/SLING8118InitialContentIT.java
index dd08ec4..1fe5f4f 100644
--- a/src/test/java/org/apache/sling/jcr/contentloader/it/SLING8118InitialContentIT.java
+++ b/src/test/java/org/apache/sling/jcr/contentloader/it/SLING8118InitialContentIT.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.jcr.contentloader.it;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -52,142 +48,146 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.osgi.framework.Bundle;
-/**
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
* test of a bundle that provides initial content that defines an ace with restrictions
*/
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class SLING8118InitialContentIT extends ContentloaderTestSupport {
- protected TinyBundle setupTestBundle(TinyBundle b) throws IOException {
- b.set(SLING_INITIAL_CONTENT_HEADER, DEFAULT_PATH_IN_BUNDLE + ";path:=" + contentRootPath);
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "SLING-8118.json");
- return b;
- }
-
- @Test
- public void bundleStarted() {
- final Bundle b = findBundle(bundleSymbolicName);
- assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
- assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
- }
-
- @Test
- public void initialContentInstalled() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-8118";
- assertTrue("Expecting initial content to be installed", session.itemExists(folderPath));
- assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
- }
-
- @Test
- public void userCreated() throws RepositoryException {
- UserManager userManager = AccessControlUtil.getUserManager(session);
- Authorizable authorizable = userManager.getAuthorizable("sling8118_user");
- assertNotNull("Expecting test user to exist", authorizable);
- }
-
- @Test
- public void groupCreated() throws RepositoryException {
- UserManager userManager = AccessControlUtil.getUserManager(session);
- Authorizable authorizable = userManager.getAuthorizable("sling8118_group");
- assertNotNull("Expecting test group to exist", authorizable);
- assertTrue(authorizable instanceof Group);
- Iterator<Authorizable> members = ((Group)authorizable).getMembers();
- assertTrue(members.hasNext());
- Authorizable firstMember = members.next();
- assertEquals("sling8118_user", firstMember.getID());
- }
-
- @Test
- public void aceWithRestrictionsCreated() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-8118";
- assertTrue("Expecting test folder to exist", session.itemExists(folderPath));
-
- AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
- AccessControlPolicy[] policies = accessControlManager.getPolicies(folderPath);
- List<AccessControlEntry> allEntries = new ArrayList<AccessControlEntry>();
- for (AccessControlPolicy accessControlPolicy : policies) {
- if (accessControlPolicy instanceof AccessControlList) {
- AccessControlEntry[] accessControlEntries = ((AccessControlList)accessControlPolicy).getAccessControlEntries();
- for (AccessControlEntry accessControlEntry : accessControlEntries) {
- allEntries.add(accessControlEntry);
- }
- }
- }
- assertEquals(3, allEntries.size());
- Map<String, AccessControlEntry> aceMap = new HashMap<>();
- for (AccessControlEntry accessControlEntry : allEntries) {
- aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
- }
-
- //check ACE for sling8118_user
- AccessControlEntry testUserAce = aceMap.get("sling8118_user");
- assertNotNull("Expected ACE for test user", testUserAce);
- assertEquals("sling8118_user", testUserAce.getPrincipal().getName());
- Privilege[] privileges = testUserAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(2, privileges.length);
- Set<String> privilegeNames = new HashSet<>();
- for (Privilege privilege : privileges) {
- privilegeNames.add(privilege.getName());
- }
- assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
- assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
-
- //check restrictions
- assertTrue(testUserAce instanceof JackrabbitAccessControlEntry);
- JackrabbitAccessControlEntry testUserJAce = (JackrabbitAccessControlEntry)testUserAce;
- String[] testUserRestrictionNames = testUserJAce.getRestrictionNames();
- assertNotNull(testUserRestrictionNames);
- assertEquals(1, testUserRestrictionNames.length);
- assertEquals("rep:glob", testUserRestrictionNames[0]);
- Value globRestriction = testUserJAce.getRestriction("rep:glob");
- assertNotNull(globRestriction);
- assertEquals("glob1", globRestriction.getString());
-
- //check ACE for sling8118_group
- AccessControlEntry testGroupAce = aceMap.get("sling8118_group");
- assertNotNull("Expected ACE for test user", testGroupAce);
- assertEquals("sling8118_group", testGroupAce.getPrincipal().getName());
- privileges = testGroupAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(1, privileges.length);
- privilegeNames = new HashSet<>();
- for (Privilege privilege : privileges) {
- privilegeNames.add(privilege.getName());
- }
- assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
-
- //check restrictions
- assertTrue(testGroupAce instanceof JackrabbitAccessControlEntry);
- JackrabbitAccessControlEntry testGroupJAce = (JackrabbitAccessControlEntry)testGroupAce;
- String[] testGroupRestrictionNames = testGroupJAce.getRestrictionNames();
- assertNotNull(testGroupRestrictionNames);
- assertEquals(1, testGroupRestrictionNames.length);
- assertEquals("rep:itemNames", testGroupRestrictionNames[0]);
- Value[] restrictions = testGroupJAce.getRestrictions("rep:itemNames");
- assertNotNull(restrictions);
- assertEquals(2, restrictions.length);
- assertEquals("name1", restrictions[0].getString());
- assertEquals("name2", restrictions[1].getString());
-
-
-
- //check ACE for everyone group
- AccessControlEntry everyoneAce = aceMap.get("everyone");
- assertNotNull("Expected ACE for everyone", everyoneAce);
- assertEquals("everyone", everyoneAce.getPrincipal().getName());
- privileges = everyoneAce.getPrivileges();
- assertNotNull(privileges);
- assertEquals(1, privileges.length);
-
- assertEquals("Expecting granted read privilege", "jcr:read", privileges[0].getName());
-
- //check restrictions
- assertTrue(everyoneAce instanceof JackrabbitAccessControlEntry);
- JackrabbitAccessControlEntry everyoneJAce = (JackrabbitAccessControlEntry)everyoneAce;
- String[] everyoneRestrictionNames = everyoneJAce.getRestrictionNames();
- assertNotNull(everyoneRestrictionNames);
- assertEquals(0, everyoneRestrictionNames.length);
- }
+ protected TinyBundle setupTestBundle(TinyBundle b) throws IOException {
+ b.set(SLING_INITIAL_CONTENT_HEADER, DEFAULT_PATH_IN_BUNDLE + ";path:=" + contentRootPath);
+ addContent(b, DEFAULT_PATH_IN_BUNDLE, "SLING-8118.json");
+ return b;
+ }
+
+ @Test
+ public void bundleStarted() {
+ final Bundle b = findBundle(bundleSymbolicName);
+ assertNotNull("Expecting bundle to be found:" + bundleSymbolicName, b);
+ assertEquals("Expecting bundle to be active:" + bundleSymbolicName, Bundle.ACTIVE, b.getState());
+ }
+
+ @Test
+ public void initialContentInstalled() throws RepositoryException {
+ final String folderPath = contentRootPath + "/SLING-8118";
+ assertTrue("Expecting initial content to be installed", session.itemExists(folderPath));
+ assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
+ }
+
+ @Test
+ public void userCreated() throws RepositoryException {
+ UserManager userManager = AccessControlUtil.getUserManager(session);
+ Authorizable authorizable = userManager.getAuthorizable("sling8118_user");
+ assertNotNull("Expecting test user to exist", authorizable);
+ }
+
+ @Test
+ public void groupCreated() throws RepositoryException {
+ UserManager userManager = AccessControlUtil.getUserManager(session);
+ Authorizable authorizable = userManager.getAuthorizable("sling8118_group");
+ assertNotNull("Expecting test group to exist", authorizable);
+ assertTrue(authorizable instanceof Group);
+ Iterator<Authorizable> members = ((Group) authorizable).getMembers();
+ assertTrue(members.hasNext());
+ Authorizable firstMember = members.next();
+ assertEquals("sling8118_user", firstMember.getID());
+ }
+
+ @Test
+ public void aceWithRestrictionsCreated() throws RepositoryException {
+ final String folderPath = contentRootPath + "/SLING-8118";
+ assertTrue("Expecting test folder to exist", session.itemExists(folderPath));
+
+ AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
+ AccessControlPolicy[] policies = accessControlManager.getPolicies(folderPath);
+ List<AccessControlEntry> allEntries = new ArrayList<AccessControlEntry>();
+ for (AccessControlPolicy accessControlPolicy : policies) {
+ if (accessControlPolicy instanceof AccessControlList) {
+ AccessControlEntry[] accessControlEntries = ((AccessControlList) accessControlPolicy).getAccessControlEntries();
+ for (AccessControlEntry accessControlEntry : accessControlEntries) {
+ allEntries.add(accessControlEntry);
+ }
+ }
+ }
+ assertEquals(3, allEntries.size());
+ Map<String, AccessControlEntry> aceMap = new HashMap<>();
+ for (AccessControlEntry accessControlEntry : allEntries) {
+ aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
+ }
+
+ //check ACE for sling8118_user
+ AccessControlEntry testUserAce = aceMap.get("sling8118_user");
+ assertNotNull("Expected ACE for test user", testUserAce);
+ assertEquals("sling8118_user", testUserAce.getPrincipal().getName());
+ Privilege[] privileges = testUserAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(2, privileges.length);
+ Set<String> privilegeNames = new HashSet<>();
+ for (Privilege privilege : privileges) {
+ privilegeNames.add(privilege.getName());
+ }
+ assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
+ assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
+
+ //check restrictions
+ assertTrue(testUserAce instanceof JackrabbitAccessControlEntry);
+ JackrabbitAccessControlEntry testUserJAce = (JackrabbitAccessControlEntry) testUserAce;
+ String[] testUserRestrictionNames = testUserJAce.getRestrictionNames();
+ assertNotNull(testUserRestrictionNames);
+ assertEquals(1, testUserRestrictionNames.length);
+ assertEquals("rep:glob", testUserRestrictionNames[0]);
+ Value globRestriction = testUserJAce.getRestriction("rep:glob");
+ assertNotNull(globRestriction);
+ assertEquals("glob1", globRestriction.getString());
+
+ //check ACE for sling8118_group
+ AccessControlEntry testGroupAce = aceMap.get("sling8118_group");
+ assertNotNull("Expected ACE for test user", testGroupAce);
+ assertEquals("sling8118_group", testGroupAce.getPrincipal().getName());
+ privileges = testGroupAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(1, privileges.length);
+ privilegeNames = new HashSet<>();
+ for (Privilege privilege : privileges) {
+ privilegeNames.add(privilege.getName());
+ }
+ assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
+
+ //check restrictions
+ assertTrue(testGroupAce instanceof JackrabbitAccessControlEntry);
+ JackrabbitAccessControlEntry testGroupJAce = (JackrabbitAccessControlEntry) testGroupAce;
+ String[] testGroupRestrictionNames = testGroupJAce.getRestrictionNames();
+ assertNotNull(testGroupRestrictionNames);
+ assertEquals(1, testGroupRestrictionNames.length);
+ assertEquals("rep:itemNames", testGroupRestrictionNames[0]);
+ Value[] restrictions = testGroupJAce.getRestrictions("rep:itemNames");
+ assertNotNull(restrictions);
+ assertEquals(2, restrictions.length);
+ assertEquals("name1", restrictions[0].getString());
+ assertEquals("name2", restrictions[1].getString());
+
+
+ //check ACE for everyone group
+ AccessControlEntry everyoneAce = aceMap.get("everyone");
+ assertNotNull("Expected ACE for everyone", everyoneAce);
+ assertEquals("everyone", everyoneAce.getPrincipal().getName());
+ privileges = everyoneAce.getPrivileges();
+ assertNotNull(privileges);
+ assertEquals(1, privileges.length);
+
+ assertEquals("Expecting granted read privilege", "jcr:read", privileges[0].getName());
+
+ //check restrictions
+ assertTrue(everyoneAce instanceof JackrabbitAccessControlEntry);
+ JackrabbitAccessControlEntry everyoneJAce = (JackrabbitAccessControlEntry) everyoneAce;
+ String[] everyoneRestrictionNames = everyoneJAce.getRestrictionNames();
+ assertNotNull(everyoneRestrictionNames);
+ assertEquals(0, everyoneRestrictionNames.length);
+ }
+
}