You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/20 14:41:30 UTC
[sling-org-apache-sling-jcr-repository-it-resource-versioning]
01/13: SLING-848 Support getting versioned resources by using uri path
parameters
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repository-it-resource-versioning.git
commit 70c6b506249850a392d126140cd6913e812673c7
Author: tomekr <to...@unknown>
AuthorDate: Mon Feb 9 16:00:52 2015 +0000
SLING-848 Support getting versioned resources by using uri path parameters
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1658445 13f79535-47bb-0310-9956-ffa450edef68
---
.gitignore | 3 +
pom.xml | 61 ++++++++
.../jcr/resource/it/ResourceVersioningTest.java | 160 +++++++++++++++++++++
3 files changed, 224 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f3c32a6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/jackrabbit
+/oak
+/sling
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..4f489fb
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>22</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.repository.it-resource-versioning</artifactId>
+ <packaging>jar</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <name>Apache Sling Versioning Integration Tests</name>
+ <description>Tests versioning API implementation in JcrResourceProvider</description>
+ <inceptionYear>2015</inceptionYear>
+
+ <properties>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock</artifactId>
+ <version>1.1.3-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock-jackrabbit</artifactId>
+ <version>0.1.3-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/test/java/org/apache/sling/jcr/resource/it/ResourceVersioningTest.java b/src/test/java/org/apache/sling/jcr/resource/it/ResourceVersioningTest.java
new file mode 100644
index 0000000..40b62dd
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/resource/it/ResourceVersioningTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.jcr.resource.it;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.version.VersionManager;
+import javax.naming.NamingException;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.testing.mock.sling.MockSling;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ResourceVersioningTest {
+
+ private VersionManager versionManager;
+
+ private Node testNode;
+
+ private ResourceResolver resolver;
+
+ private Session session;
+
+ @Before
+ public void setUp() throws Exception {
+ resolver = MockSling.newResourceResolver(ResourceResolverType.JCR_JACKRABBIT);
+ session = resolver.adaptTo(Session.class);
+ versionManager = session.getWorkspace().getVersionManager();
+ registerNamespace("sling", "http://sling.apache.org/jcr/sling/1.0");
+
+ Node testRoot = session.getRootNode().addNode("content");
+ testNode = testRoot.addNode("test");
+ testNode.addMixin(JcrConstants.MIX_VERSIONABLE);
+ session.save();
+
+ versionManager.checkout(testNode.getPath());
+ testNode.setProperty("prop", "oldvalue");
+ testNode.addNode("x").addNode("y").setProperty("child_prop", "child_old_value");
+ session.save();
+ versionManager.checkin(testNode.getPath());
+
+ versionManager.checkout(testNode.getPath());
+ testNode.setProperty("prop", "newvalue");
+ testNode.getProperty("x/y/child_prop").setValue("child_new_value");
+ session.save();
+ versionManager.checkin(testNode.getPath());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ session.removeItem("/content");
+ session.save();
+ resolver.close();
+ }
+
+ @Test
+ public void getResourceOnVersionableNode() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test;v='1.0'");
+ String prop = resource.adaptTo(ValueMap.class).get("prop", String.class);
+ assertEquals("/content/test;v='1.0'", resource.getPath());
+ assertEquals("oldvalue", prop);
+ }
+
+ @Test
+ public void getResourceOnVersionableProperty() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test/prop;v='1.0'");
+ String prop = resource.adaptTo(String.class);
+ assertEquals("/content/test/prop;v='1.0'", resource.getPath());
+ assertEquals("oldvalue", prop);
+ }
+
+ @Test
+ public void resolveOnVersionableNode() throws RepositoryException, NamingException {
+ for (String path : Arrays.asList("/content/test;v='1.0'.html", "/content/test.html;v=1.0",
+ "/content/test;v='1.0'.html/some/suffix", "/content/test.html;v=1.0/some/suffix")) {
+ Resource resource = resolver.resolve(path);
+ String prop = resource.adaptTo(ValueMap.class).get("prop", String.class);
+ assertEquals("/content/test;v='1.0'", resource.getPath());
+ assertEquals("oldvalue", prop);
+ }
+ }
+
+ @Test
+ public void getResourceOnVersionableDescendant() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test/x/y;v='1.0'");
+ String prop = resource.adaptTo(ValueMap.class).get("child_prop", String.class);
+ assertEquals("/content/test/x/y;v='1.0'", resource.getPath());
+ assertEquals("child_old_value", prop);
+ }
+
+ @Test
+ public void getResourceOnVersionableDescendantProperty() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test/x/y/child_prop;v='1.0'");
+ String prop = resource.adaptTo(String.class);
+ assertEquals("/content/test/x/y/child_prop;v='1.0'", resource.getPath());
+ assertEquals("child_old_value", prop);
+ }
+
+ @Test
+ public void getChildOnVersionableResource() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test;v='1.0'").getChild("x/y");
+ String prop = resource.adaptTo(ValueMap.class).get("child_prop", String.class);
+ assertEquals("/content/test/x/y;v='1.0'", resource.getPath());
+ assertEquals("child_old_value", prop);
+ }
+
+ @Test
+ public void listChildrenOnVersionableResource() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test/x;v='1.0'").listChildren().next();
+ String prop = resource.adaptTo(ValueMap.class).get("child_prop", String.class);
+ assertEquals("/content/test/x/y;v='1.0'", resource.getPath());
+ assertEquals("child_old_value", prop);
+ }
+
+ @Test
+ public void getParentOnVersionableResource() throws RepositoryException, NamingException {
+ Resource resource = resolver.getResource("/content/test/x;v='1.0'").getParent();
+ String prop = resource.adaptTo(ValueMap.class).get("prop", String.class);
+ assertEquals("/content/test", resource.getPath());
+ assertEquals("newvalue", prop);
+ }
+
+ private void registerNamespace(String prefix, String uri) throws RepositoryException {
+ NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
+ if (!ArrayUtils.contains(registry.getPrefixes(), prefix)) {
+ session.getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri);
+ }
+
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.