Merge branch 'SLING-8243' of https://github.com/apache/sling-org-apache-sling-jcr-contentloader.git into SLING-8243
diff --git a/pom.xml b/pom.xml
index fed2ca1..b5172c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,8 +23,8 @@
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>34</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>35</version>
<relativePath />
</parent>
@@ -36,7 +36,7 @@
<properties>
<sling.java.version>8</sling.java.version>
- <org.ops4j.pax.exam.version>4.12.0</org.ops4j.pax.exam.version>
+ <org.ops4j.pax.exam.version>4.13.1</org.ops4j.pax.exam.version>
</properties>
<scm>
@@ -222,7 +222,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
- <version>5.6.10</version>
+ <version>6.0.3</version>
<scope>test</scope>
</dependency>
<!-- Apache Sling -->
@@ -235,7 +235,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>2.0.0</version>
+ <version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- testing -->
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..8e3c281 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
@@ -22,66 +22,78 @@
import javax.jcr.RepositoryException;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Multimap;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
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;
-/** 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 {
- 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, "basic-content.json");
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "simple-folder/test1.txt");
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "folder-with-descriptor.json");
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "folder-with-descriptor/test2.txt");
- return b;
+ @Configuration
+ public Option[] configuration() throws IOException {
+ final String header = DEFAULT_PATH_IN_BUNDLE + ";path:=" + CONTENT_ROOT_PATH;
+ final Multimap<String, String> content = ImmutableListMultimap.of(
+ DEFAULT_PATH_IN_BUNDLE, "basic-content.json",
+ DEFAULT_PATH_IN_BUNDLE, "simple-folder/test1.txt",
+ DEFAULT_PATH_IN_BUNDLE, "folder-with-descriptor.json",
+ DEFAULT_PATH_IN_BUNDLE, "folder-with-descriptor/test2.txt"
+ );
+ final Option bundle = buildInitialContentBundle(header, content);
+ return new Option[]{
+ baseConfiguration(),
+ bundle
+ };
}
-
+
@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());
+ final Bundle b = findBundle(BUNDLE_SYMBOLICNAME);
+ assertNotNull("Expecting bundle to be found:" + BUNDLE_SYMBOLICNAME, b);
+ assertEquals("Expecting bundle to be active:" + BUNDLE_SYMBOLICNAME, 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 = CONTENT_ROOT_PATH + "/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 = CONTENT_ROOT_PATH + "/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 = CONTENT_ROOT_PATH + "/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 = CONTENT_ROOT_PATH + "/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 = CONTENT_ROOT_PATH + "/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 e5e5bca..f8e8196 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
@@ -18,34 +18,24 @@
*/
package org.apache.sling.jcr.contentloader.it;
-import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
-import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
-
import java.io.IOException;
import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
+import java.util.Map;
import javax.inject.Inject;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import com.google.common.collect.Multimap;
import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.resource.presence.ResourcePresence;
import org.apache.sling.testing.paxexam.SlingOptions;
import org.apache.sling.testing.paxexam.TestSupport;
import org.junit.After;
import org.junit.Before;
-import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.options.CompositeOption;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.options.ModifiableCompositeOption;
+import org.ops4j.pax.exam.util.Filter;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.osgi.framework.Bundle;
@@ -54,6 +44,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingResourcePresence;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
public abstract class ContentloaderTestSupport extends TestSupport {
@Inject
@@ -64,54 +67,52 @@
protected Session session;
- protected String bundleSymbolicName;
-
- protected String contentRootPath;
-
protected static final String SLING_INITIAL_CONTENT_HEADER = "Sling-Initial-Content";
+ protected static final String BUNDLE_SYMBOLICNAME = "TEST-CONTENT-BUNDLE";
+
protected static final String DEFAULT_PATH_IN_BUNDLE = "test-initial-content";
+ protected static final String CONTENT_ROOT_PATH = "/test-content/" + BUNDLE_SYMBOLICNAME;
+
private final Logger logger = LoggerFactory.getLogger(ContentloaderTestSupport.class);
ContentloaderTestSupport() {
}
+ @Inject
+ @Filter(value = "(path=" + CONTENT_ROOT_PATH + ")")
+ private ResourcePresence resourcePresence;
+
+ public ModifiableCompositeOption baseConfiguration() {
+ final Option contentloader = mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.jcr.contentloader").version(SlingOptions.versionResolver.getVersion("org.apache.sling", "org.apache.sling.jcr.contentloader"));
+ final ModifiableCompositeOption quickstart = quickstart().remove(contentloader);
+ return composite(
+ super.baseConfiguration(),
+ quickstart,
+ // Sling JCR ContentLoader
+ testBundle("bundle.filename"),
+ factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
+ .put("path", CONTENT_ROOT_PATH)
+ .asOption(),
+ // testing
+ newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
+ .put("whitelist.bundles.regexp", "PAXEXAM-PROBE-.*")
+ .asOption(),
+ slingResourcePresence(),
+ junitBundles()
+ );
+ }
+
+ protected ModifiableCompositeOption quickstart() {
+ final int httpPort = findFreePort();
+ final String workingDirectory = workingDirectory();
+ return slingQuickstartOakTar(workingDirectory, httpPort);
+ }
+
@Before
public void setup() throws Exception {
- bundleSymbolicName = "TEST-" + UUID.randomUUID();
- contentRootPath = "/test-content/" + bundleSymbolicName;
session = repository.loginAdministrative(null);
-
- assertFalse("Expecting no content before test", session.itemExists(contentRootPath));
-
- // Create, install and start a bundle that has initial content
- try (InputStream is = getTestBundleStream()) {
- final Bundle bundle = bundleContext.installBundle(bundleSymbolicName, is);
- bundle.start();
- }
-
- // 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 {
- logger.warn("Bundle content not loaded yet, retrying after a short delay, path={}", contentLoadedPath);
- Thread.sleep(200);
- session.refresh(false);
- }
- }
- } while (retry);
}
@After
@@ -119,57 +120,31 @@
session.logout();
}
- @Configuration
- public Option[] configuration() {
- //workaround to get the required jcr.base bundle into the runtime
- SlingOptions.versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.jcr.base");
-
- CompositeOption quickstart = (CompositeOption) quickstart();
- final Option[] options = Arrays.stream(quickstart.getOptions()).filter(e -> !Objects.deepEquals(e,
- mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.jcr.contentloader").version(SlingOptions.versionResolver.getVersion("org.apache.sling", "org.apache.sling.jcr.contentloader"))
- )).toArray(Option[]::new);
- quickstart = new DefaultCompositeOption(options);
- return new Option[]{
- super.baseConfiguration(),
- quickstart,
- // Sling JCR ContentLoader
- testBundle("bundle.filename"),
- // testing
- newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
- .put("whitelist.bundles.regexp", "PAXEXAM-PROBE-.*")
- .asOption(),
- slingResourcePresence(),
- junitBundles()
- };
- }
-
- protected Option quickstart() {
- final int httpPort = findFreePort();
- final String workingDirectory = workingDirectory();
- return slingQuickstartOakTar(workingDirectory, httpPort);
- }
-
-
- private InputStream getTestBundleStream() throws Exception {
- final TinyBundle bundle = TinyBundles.bundle().set(Constants.BUNDLE_SYMBOLICNAME, bundleSymbolicName);
- return setupTestBundle(bundle).build(TinyBundles.withBnd());
- }
-
- abstract protected TinyBundle setupTestBundle(TinyBundle b) throws Exception;
-
/**
* Add content to our test bundle
*/
- protected void addContent(TinyBundle b, String pathInBundle, String resourcePath) throws IOException {
+ protected void addContent(final TinyBundle bundle, String pathInBundle, String resourcePath) throws IOException {
pathInBundle += "/" + resourcePath;
resourcePath = "/initial-content/" + resourcePath;
try (final InputStream is = getClass().getResourceAsStream(resourcePath)) {
assertNotNull("Expecting resource to be found:" + resourcePath, is);
logger.info("Adding resource to bundle, path={}, resource={}", pathInBundle, resourcePath);
- b.add(pathInBundle, is);
+ bundle.add(pathInBundle, is);
}
}
+ protected Option buildInitialContentBundle(final String header, final Multimap<String, String> content) throws IOException {
+ final TinyBundle bundle = TinyBundles.bundle();
+ bundle.set(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_SYMBOLICNAME);
+ bundle.set(SLING_INITIAL_CONTENT_HEADER, header);
+ for (final Map.Entry<String, String> entry : content.entries()) {
+ addContent(bundle, entry.getKey(), entry.getValue());
+ }
+ return streamBundle(
+ bundle.build(withBnd())
+ ).start();
+ }
+
protected Bundle findBundle(final String symbolicName) {
for (final Bundle bundle : bundleContext.getBundles()) {
if (symbolicName.equals(bundle.getSymbolicName())) {
@@ -179,4 +154,10 @@
return null;
}
+ protected void assertProperty(final Session session, final String path, final 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);
+ }
+
}
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..72a62d2 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
@@ -24,12 +24,15 @@
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Multimap;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
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;
@@ -37,43 +40,52 @@
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 I18N initial content
+ */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class I18nInitialContentIT extends ContentloaderTestSupport {
- protected TinyBundle setupTestBundle(TinyBundle b) throws IOException {
- b.set(SLING_INITIAL_CONTENT_HEADER, DEFAULT_PATH_IN_BUNDLE + ";ignoreImportProviders:=json;path:=" + contentRootPath);
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "i18n/en.json");
- addContent(b, DEFAULT_PATH_IN_BUNDLE, "i18n/en.json.xml");
- return b;
+ @Configuration
+ public Option[] configuration() throws IOException {
+ final String header = DEFAULT_PATH_IN_BUNDLE + ";ignoreImportProviders:=json;path:=" + CONTENT_ROOT_PATH;
+ final Multimap<String, String> content = ImmutableListMultimap.of(
+ DEFAULT_PATH_IN_BUNDLE, "i18n/en.json",
+ DEFAULT_PATH_IN_BUNDLE, "i18n/en.json.xml"
+ );
+ final Option bundle = buildInitialContentBundle(header, content);
+ return new Option[]{
+ baseConfiguration(),
+ bundle
+ };
}
-
+
@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());
+ final Bundle b = findBundle(BUNDLE_SYMBOLICNAME);
+ assertNotNull("Expecting bundle to be found:" + BUNDLE_SYMBOLICNAME, b);
+ assertEquals("Expecting bundle to be active:" + BUNDLE_SYMBOLICNAME, 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 = CONTENT_ROOT_PATH + "/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 = CONTENT_ROOT_PATH + "/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..64e2ae7 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
@@ -21,47 +21,52 @@
import java.io.IOException;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Multimap;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
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 the SLING-5682 ordered content loading */
+/**
+ * Test the SLING-5682 ordered content loading
+ */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class OrderedInitialContentIT 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, "ordered-content.ordered-json");
- return b;
+ @Configuration
+ public Option[] configuration() throws IOException {
+ final String header = DEFAULT_PATH_IN_BUNDLE + ";path:=" + CONTENT_ROOT_PATH;
+ final Multimap<String, String> content = ImmutableListMultimap.of(
+ DEFAULT_PATH_IN_BUNDLE, "ordered-content.ordered-json"
+ );
+ final Option bundle = buildInitialContentBundle(header, content);
+ return new Option[]{
+ baseConfiguration(),
+ bundle
+ };
}
-
+
@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());
+ final Bundle b = findBundle(BUNDLE_SYMBOLICNAME);
+ assertNotNull("Expecting bundle to be found:" + BUNDLE_SYMBOLICNAME, b);
+ assertEquals("Expecting bundle to be active:" + BUNDLE_SYMBOLICNAME, 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, CONTENT_ROOT_PATH + "/ordered-content/first/title", "This comes first");
+ assertProperty(session, CONTENT_ROOT_PATH + "/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 a4f9914..f7e0e57 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
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -34,16 +35,19 @@
import javax.jcr.security.AccessControlPolicy;
import javax.jcr.security.Privilege;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Multimap;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
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;
@@ -51,32 +55,39 @@
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;
+ @Configuration
+ public Option[] configuration() throws IOException {
+ final String header = DEFAULT_PATH_IN_BUNDLE + ";path:=" + CONTENT_ROOT_PATH;
+ final Multimap<String, String> content = ImmutableListMultimap.of(
+ DEFAULT_PATH_IN_BUNDLE, "SLING-7268.json"
+ );
+ final Option bundle = buildInitialContentBundle(header, content);
+ return new Option[]{
+ baseConfiguration(),
+ bundle
+ };
}
@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());
+ final Bundle b = findBundle(BUNDLE_SYMBOLICNAME);
+ assertNotNull("Expecting bundle to be found:" + BUNDLE_SYMBOLICNAME, b);
+ assertEquals("Expecting bundle to be active:" + BUNDLE_SYMBOLICNAME, Bundle.ACTIVE, b.getState());
}
@Test
public void initialContentInstalled() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-7268";
+ final String folderPath = CONTENT_ROOT_PATH + "/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());
+ assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
}
@Test
@@ -98,21 +109,18 @@
assertEquals("sling7268_user", firstMember.getID());
}
-
@Test
public void aceCreated() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-7268";
+ final String folderPath = CONTENT_ROOT_PATH + "/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);
- }
+ AccessControlEntry[] accessControlEntries = ((AccessControlList) accessControlPolicy).getAccessControlEntries();
+ allEntries.addAll(Arrays.asList(accessControlEntries));
}
}
assertEquals(3, allEntries.size());
@@ -121,7 +129,7 @@
aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
}
- // check ACE for sling7268_user
+ //check ACE for sling7268_user
AccessControlEntry testUserAce = aceMap.get("sling7268_user");
assertNotNull("Expected ACE for test user", testUserAce);
assertEquals("sling7268_user", testUserAce.getPrincipal().getName());
@@ -135,7 +143,7 @@
assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
- // check ACE for sling7268_group
+ //check ACE for sling7268_group
AccessControlEntry testGroupAce = aceMap.get("sling7268_group");
assertNotNull("Expected ACE for test user", testGroupAce);
assertEquals("sling7268_group", testGroupAce.getPrincipal().getName());
@@ -146,10 +154,9 @@
for (Privilege privilege : privileges) {
privilegeNames.add(privilege.getName());
}
- assertTrue("Expecting granted modifyAccessControl privilege",
- privilegeNames.contains("jcr:modifyAccessControl"));
+ assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
- // check ACE for everyone group
+ //check ACE for everyone group
AccessControlEntry everyoneAce = aceMap.get("everyone");
assertNotNull("Expected ACE for everyone", everyoneAce);
assertEquals("everyone", everyoneAce.getPrincipal().getName());
@@ -159,4 +166,5 @@
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 21a01d9..12c96db 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,12 +18,9 @@
*/
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.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -39,6 +36,8 @@
import javax.jcr.security.AccessControlPolicy;
import javax.jcr.security.Privilege;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Multimap;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
@@ -46,39 +45,49 @@
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
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
+ * 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;
+ @Configuration
+ public Option[] configuration() throws IOException {
+ final String header = DEFAULT_PATH_IN_BUNDLE + ";path:=" + CONTENT_ROOT_PATH;
+ final Multimap<String, String> content = ImmutableListMultimap.of(
+ DEFAULT_PATH_IN_BUNDLE, "SLING-8118.json"
+ );
+ final Option bundle = buildInitialContentBundle(header, content);
+ return new Option[]{
+ baseConfiguration(),
+ bundle
+ };
}
@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());
+ final Bundle b = findBundle(BUNDLE_SYMBOLICNAME);
+ assertNotNull("Expecting bundle to be found:" + BUNDLE_SYMBOLICNAME, b);
+ assertEquals("Expecting bundle to be active:" + BUNDLE_SYMBOLICNAME, Bundle.ACTIVE, b.getState());
}
@Test
public void initialContentInstalled() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-8118";
+ final String folderPath = CONTENT_ROOT_PATH + "/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());
+ assertEquals("folder has node type 'sling:Folder'", "sling:Folder", session.getNode(folderPath).getPrimaryNodeType().getName());
}
@Test
@@ -102,7 +111,7 @@
@Test
public void aceWithRestrictionsCreated() throws RepositoryException {
- final String folderPath = contentRootPath + "/SLING-8118";
+ final String folderPath = CONTENT_ROOT_PATH + "/SLING-8118";
assertTrue("Expecting test folder to exist", session.itemExists(folderPath));
AccessControlManager accessControlManager = AccessControlUtil.getAccessControlManager(session);
@@ -110,11 +119,8 @@
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);
- }
+ AccessControlEntry[] accessControlEntries = ((AccessControlList) accessControlPolicy).getAccessControlEntries();
+ allEntries.addAll(Arrays.asList(accessControlEntries));
}
}
assertEquals(3, allEntries.size());
@@ -123,7 +129,7 @@
aceMap.put(accessControlEntry.getPrincipal().getName(), accessControlEntry);
}
- // check ACE for sling8118_user
+ //check ACE for sling8118_user
AccessControlEntry testUserAce = aceMap.get("sling8118_user");
assertNotNull("Expected ACE for test user", testUserAce);
assertEquals("sling8118_user", testUserAce.getPrincipal().getName());
@@ -137,7 +143,7 @@
assertTrue("Expecting granted read privilege", privilegeNames.contains("jcr:read"));
assertTrue("Expecting granted write privilege", privilegeNames.contains("jcr:write"));
- // check restrictions
+ //check restrictions
assertTrue(testUserAce instanceof JackrabbitAccessControlEntry);
JackrabbitAccessControlEntry testUserJAce = (JackrabbitAccessControlEntry) testUserAce;
String[] testUserRestrictionNames = testUserJAce.getRestrictionNames();
@@ -148,7 +154,7 @@
assertNotNull(globRestriction);
assertEquals("glob1", globRestriction.getString());
- // check ACE for sling8118_group
+ //check ACE for sling8118_group
AccessControlEntry testGroupAce = aceMap.get("sling8118_group");
assertNotNull("Expected ACE for test user", testGroupAce);
assertEquals("sling8118_group", testGroupAce.getPrincipal().getName());
@@ -159,10 +165,9 @@
for (Privilege privilege : privileges) {
privilegeNames.add(privilege.getName());
}
- assertTrue("Expecting granted modifyAccessControl privilege",
- privilegeNames.contains("jcr:modifyAccessControl"));
+ assertTrue("Expecting granted modifyAccessControl privilege", privilegeNames.contains("jcr:modifyAccessControl"));
- // check restrictions
+ //check restrictions
assertTrue(testGroupAce instanceof JackrabbitAccessControlEntry);
JackrabbitAccessControlEntry testGroupJAce = (JackrabbitAccessControlEntry) testGroupAce;
String[] testGroupRestrictionNames = testGroupJAce.getRestrictionNames();
@@ -175,7 +180,8 @@
assertEquals("name1", restrictions[0].getString());
assertEquals("name2", restrictions[1].getString());
- // check ACE for everyone group
+
+ //check ACE for everyone group
AccessControlEntry everyoneAce = aceMap.get("everyone");
assertNotNull("Expected ACE for everyone", everyoneAce);
assertEquals("everyone", everyoneAce.getPrincipal().getName());
@@ -185,11 +191,12 @@
assertEquals("Expecting granted read privilege", "jcr:read", privileges[0].getName());
- // check restrictions
+ //check restrictions
assertTrue(everyoneAce instanceof JackrabbitAccessControlEntry);
JackrabbitAccessControlEntry everyoneJAce = (JackrabbitAccessControlEntry) everyoneAce;
String[] everyoneRestrictionNames = everyoneJAce.getRestrictionNames();
assertNotNull(everyoneRestrictionNames);
assertEquals(0, everyoneRestrictionNames.length);
}
+
}