jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r931486 - in /jackrabbit/branches/2.1: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
Date Wed, 07 Apr 2010 10:00:46 GMT
Author: jukka
Date: Wed Apr  7 10:00:46 2010
New Revision: 931486

URL: http://svn.apache.org/viewvc?rev=931486&view=rev
Log:
2.1: Merged revisions 931483 and 931484 (JCR-2568)

Added:
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
      - copied, changed from r931483, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
Modified:
    jackrabbit/branches/2.1/   (props changed)
    jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java

Propchange: jackrabbit/branches/2.1/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr  7 10:00:46 2010
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:931479
+/jackrabbit/trunk:931479,931483-931484

Modified: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java?rev=931486&r1=931485&r2=931486&view=diff
==============================================================================
--- jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/JackrabbitRepositoryStub.java
Wed Apr  7 10:00:46 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -24,29 +23,16 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.security.Principal;
 import java.security.acl.Group;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Properties;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
 
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.PropertyType;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.retention.RetentionPolicy;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import org.apache.jackrabbit.api.JackrabbitWorkspace;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.jackrabbit.core.retention.RetentionPolicyImpl;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.RepositoryStub;
 import org.apache.jackrabbit.test.RepositoryStubException;
@@ -73,11 +59,6 @@ public class JackrabbitRepositoryStub ex
         "org.apache.jackrabbit.repository.home";
 
     /**
-     * The encoding of the test resources.
-     */
-    private static final String ENCODING = "UTF-8";
-
-    /**
      * Repository settings.
      */
     private final Properties settings;
@@ -200,7 +181,8 @@ public class JackrabbitRepositoryStub ex
                 repo = createRepository(dir, xml);
                 Session session = repo.login(superuser);
                 try {
-                    prepareTestContent(session);
+                    TestContentLoader loader = new TestContentLoader();
+                    loader.loadTestContent(session);
                 } finally {
                     session.logout();
                 }
@@ -211,216 +193,11 @@ public class JackrabbitRepositoryStub ex
         }
     }
 
-    private void prepareTestContent(Session session)
-            throws RepositoryException, IOException {
-        JackrabbitWorkspace workspace =
-            (JackrabbitWorkspace) session.getWorkspace();
-        Collection<String> workspaces =
-            Arrays.asList(workspace.getAccessibleWorkspaceNames());
-        if (!workspaces.contains("test")) {
-            workspace.createWorkspace("test");
-        }
-
-        JackrabbitNodeTypeManager manager =
-            (JackrabbitNodeTypeManager) workspace.getNodeTypeManager();
-        if (!manager.hasNodeType("test:versionable")) {
-            InputStream xml = getResource("test-nodetypes.xml");
-            try {
-                manager.registerNodeTypes(xml, JackrabbitNodeTypeManager.TEXT_XML);
-            } finally {
-                xml.close();
-            }
-        }
-
-        Node data = getOrAddNode(session.getRootNode(), "testdata");
-        addPropertyTestData(getOrAddNode(data, "property"));
-        addQueryTestData(getOrAddNode(data, "query"));
-        addNodeTestData(getOrAddNode(data, "node"));
-        addLifecycleTestData(getOrAddNode(data, "lifecycle"));
-        addExportTestData(getOrAddNode(data, "docViewTest"));
-
-        Node conf = getOrAddNode(session.getRootNode(), "testconf");
-        addRetentionTestData(getOrAddNode(conf, "retentionTest"));
-
-        session.save();
-    }
-
-    private Node getOrAddNode(Node node, String name)
-            throws RepositoryException {
-        try {
-            return node.getNode(name);
-        } catch (PathNotFoundException e) {
-            return node.addNode(name);
-        }
-    }
-
-    /**
-     * Creates a boolean, double, long, calendar and a path property at the
-     * given node.
-     */
-    private void addPropertyTestData(Node node) throws RepositoryException {
-        node.setProperty("boolean", true);
-        node.setProperty("double", Math.PI);
-        node.setProperty("long", 90834953485278298l);
-        Calendar c = Calendar.getInstance();
-        c.set(2005, 6, 18, 17, 30);
-        node.setProperty("calendar", c);
-        ValueFactory factory = node.getSession().getValueFactory();
-        node.setProperty("path", factory.createValue("/", PropertyType.PATH));
-        node.setProperty("multi", new String[] { "one", "two", "three" });
-    }
-
-    /**
-     * Creates a node with a RetentionPolicy
-     */
-    private void addRetentionTestData(Node node) throws RepositoryException {
-        RetentionPolicy rp = RetentionPolicyImpl.createRetentionPolicy("testRetentionPolicy",
node.getSession());
-        node.getSession().getRetentionManager().setRetentionPolicy(node.getPath(), rp);
-    }
-
-    /**
-     * Creates four nodes under the given node. Each node has a String
-     * property named "prop1" with some content set.
-     */
-    private void addQueryTestData(Node node) throws RepositoryException {
-        while (node.hasNode("node1")) {
-            node.getNode("node1").remove();
-        }
-        getOrAddNode(node, "node1").setProperty(
-                "prop1", "You can have it good, cheap, or fast. Any two.");
-        getOrAddNode(node, "node1").setProperty("prop1", "foo bar");
-        getOrAddNode(node, "node1").setProperty("prop1", "Hello world!");
-        getOrAddNode(node, "node2").setProperty("prop1", "Apache Jackrabbit");
-    }
-
-
-    /**
-     * Creates three nodes under the given node: one of type nt:resource
-     * and the other nodes referencing it.
-     */
-    private void addNodeTestData(Node node) throws RepositoryException, IOException {
-        if (node.hasNode("multiReference")) {
-            node.getNode("multiReference").remove();
-        }
-        if (node.hasNode("resReference")) {
-            node.getNode("resReference").remove();
-        }
-        if (node.hasNode("myResource")) {
-            node.getNode("myResource").remove();
-        }
-
-        Node resource = node.addNode("myResource", "nt:resource");
-        // nt:resource not longer referenceable since JCR 2.0
-        resource.addMixin("mix:referenceable");
-        resource.setProperty("jcr:encoding", ENCODING);
-        resource.setProperty("jcr:mimeType", "text/plain");
-        resource.setProperty(
-                "jcr:data",
-                new ByteArrayInputStream("Hello w\u00F6rld.".getBytes(ENCODING)));
-        resource.setProperty("jcr:lastModified", Calendar.getInstance());
-
-        Node resReference = getOrAddNode(node, "reference");
-        resReference.setProperty("ref", resource);
-        // make this node itself referenceable
-        resReference.addMixin("mix:referenceable");
-
-        Node multiReference = node.addNode("multiReference");
-        ValueFactory factory = node.getSession().getValueFactory();
-        multiReference.setProperty("ref", new Value[] {
-                factory.createValue(resource),
-                factory.createValue(resReference)
-            });
-    }
-
-    /**
-     * Creates a lifecycle policy node and another node with a lifecycle
-     * referencing that policy.
-     */
-    private void addLifecycleTestData(Node node) throws RepositoryException {
-        Node policy = getOrAddNode(node, "policy");
-        policy.addMixin(NodeType.MIX_REFERENCEABLE);
-        Node transitions = getOrAddNode(policy, "transitions");
-        Node transition = getOrAddNode(transitions, "identity");
-        transition.setProperty("from", "identity");
-        transition.setProperty("to", "identity");
-
-        Node lifecycle = getOrAddNode(node, "node");
-        ((NodeImpl) lifecycle).assignLifecyclePolicy(policy, "identity");
-    }
-
-    private void addExportTestData(Node node) throws RepositoryException, IOException {
-        getOrAddNode(node, "invalidXmlName").setProperty("propName", "some text");
-
-        // three nodes which should be serialized as xml text in docView export
-        // separated with spaces
-        getOrAddNode(node, "jcr:xmltext").setProperty(
-                "jcr:xmlcharacters", "A text without any special character.");
-        getOrAddNode(node, "some-element");
-        getOrAddNode(node, "jcr:xmltext").setProperty(
-                "jcr:xmlcharacters",
-                " The entity reference characters: <, ', ,&, >,  \" should"
-                + " be escaped in xml export. ");
-        getOrAddNode(node, "some-element");
-        getOrAddNode(node, "jcr:xmltext").setProperty(
-                "jcr:xmlcharacters", "A text without any special character.");
-
-        Node big = getOrAddNode(node, "bigNode");
-        big.setProperty(
-                "propName0",
-                "SGVsbG8gd8O2cmxkLg==;SGVsbG8gd8O2cmxkLg==".split(";"),
-                PropertyType.BINARY);
-        big.setProperty("propName1", "text 1");
-        big.setProperty(
-                "propName2",
-                "multival text 1;multival text 2;multival text 3".split(";"));
-        big.setProperty("propName3", "text 1");
-
-        addExportValues(node, "propName");
-        addExportValues(node, "Prop<>prop");
-    }
-
-    /**
-     * create nodes with following properties
-     * binary & single
-     * binary & multival
-     * notbinary & single
-     * notbinary & multival
-     */
-    private void addExportValues(Node node, String name)
-            throws RepositoryException, IOException {
-        String prefix = "valid";
-        if (name.indexOf('<') != -1) {
-            prefix = "invalid";
-        }
-        node = getOrAddNode(node, prefix + "Names");
-
-        String[] texts = new String[] {
-                "multival text 1", "multival text 2", "multival text 3" };
-        getOrAddNode(node, prefix + "MultiNoBin").setProperty(name, texts);
-
-        Node resource = getOrAddNode(node, prefix + "MultiBin");
-        resource.setProperty("jcr:encoding", ENCODING);
-        resource.setProperty("jcr:mimeType", "text/plain");
-        String[] values =
-            new String[] { "SGVsbG8gd8O2cmxkLg==", "SGVsbG8gd8O2cmxkLg==" };
-        resource.setProperty(name, values, PropertyType.BINARY);
-        resource.setProperty("jcr:lastModified", Calendar.getInstance());
-
-        getOrAddNode(node, prefix + "NoBin").setProperty(name,  "text 1");
-
-        resource = getOrAddNode(node, "invalidBin");
-        resource.setProperty("jcr:encoding", ENCODING);
-        resource.setProperty("jcr:mimeType", "text/plain");
-        byte[] bytes = "Hello w\u00F6rld.".getBytes(ENCODING);
-        resource.setProperty(name, new ByteArrayInputStream(bytes));
-        resource.setProperty("jcr:lastModified", Calendar.getInstance());
-    }
-
     @Override
     public Principal getKnownPrincipal(Session session) throws RepositoryException {
-        
+
         Principal knownPrincipal = null;
-        
+
         if (session instanceof SessionImpl) {
             for (Principal p : ((SessionImpl)session).getSubject().getPrincipals()) {
                 if (! (p instanceof Group)) {
@@ -428,7 +205,7 @@ public class JackrabbitRepositoryStub ex
                 }
             }
         }
-        
+
         if (knownPrincipal != null) {
             return knownPrincipal;
         }
@@ -442,7 +219,7 @@ public class JackrabbitRepositoryStub ex
             return "an_unknown_user";
         }
     };
-    
+
     @Override
     public Principal getUnknownPrincipal(Session session) throws RepositoryException, NotExecutableException
{
         return UNKNOWN_PRINCIPAL;

Copied: jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
(from r931483, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java?p2=jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java&p1=jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java&r1=931483&r2=931486&rev=931486&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
(original)
+++ jackrabbit/branches/2.1/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TestContentLoader.java
Wed Apr  7 10:00:46 2010
@@ -42,17 +42,10 @@ import org.apache.jackrabbit.core.retent
  */
 public class TestContentLoader {
 
-    private String encoding;
-    private ClassLoader classLoader;
-
-    public TestContentLoader(String encoding, ClassLoader classLoader) {
-        this.encoding = encoding;
-        this.classLoader = classLoader;
-    }
-
-    private InputStream getResource(String name) {
-        return classLoader.getResourceAsStream(name);
-    }
+    /**
+     * The encoding of the test resources.
+     */
+    private static final String ENCODING = "UTF-8";
 
     public void loadTestContent(Session session) throws RepositoryException, IOException
{
         JackrabbitWorkspace workspace =
@@ -66,7 +59,8 @@ public class TestContentLoader {
         JackrabbitNodeTypeManager manager =
             (JackrabbitNodeTypeManager) workspace.getNodeTypeManager();
         if (!manager.hasNodeType("test:versionable")) {
-            InputStream xml = getResource("test-nodetypes.xml");
+            InputStream xml =
+                TestContentLoader.class.getResourceAsStream("test-nodetypes.xml");
             try {
                 manager.registerNodeTypes(xml, JackrabbitNodeTypeManager.TEXT_XML);
             } finally {
@@ -156,11 +150,11 @@ public class TestContentLoader {
         Node resource = node.addNode("myResource", "nt:resource");
         // nt:resource not longer referenceable since JCR 2.0
         resource.addMixin("mix:referenceable");
-        resource.setProperty("jcr:encoding", encoding);
+        resource.setProperty("jcr:encoding", ENCODING);
         resource.setProperty("jcr:mimeType", "text/plain");
         resource.setProperty(
                 "jcr:data",
-                new ByteArrayInputStream("Hello w\u00F6rld.".getBytes(encoding)));
+                new ByteArrayInputStream("Hello w\u00F6rld.".getBytes(ENCODING)));
         resource.setProperty("jcr:lastModified", Calendar.getInstance());
 
         Node resReference = getOrAddNode(node, "reference");
@@ -243,7 +237,7 @@ public class TestContentLoader {
         getOrAddNode(node, prefix + "MultiNoBin").setProperty(name, texts);
 
         Node resource = getOrAddNode(node, prefix + "MultiBin");
-        resource.setProperty("jcr:encoding", encoding);
+        resource.setProperty("jcr:encoding", ENCODING);
         resource.setProperty("jcr:mimeType", "text/plain");
         String[] values =
             new String[] { "SGVsbG8gd8O2cmxkLg==", "SGVsbG8gd8O2cmxkLg==" };
@@ -253,9 +247,9 @@ public class TestContentLoader {
         getOrAddNode(node, prefix + "NoBin").setProperty(name,  "text 1");
 
         resource = getOrAddNode(node, "invalidBin");
-        resource.setProperty("jcr:encoding", encoding);
+        resource.setProperty("jcr:encoding", ENCODING);
         resource.setProperty("jcr:mimeType", "text/plain");
-        byte[] bytes = "Hello w\u00F6rld.".getBytes(encoding);
+        byte[] bytes = "Hello w\u00F6rld.".getBytes(ENCODING);
         resource.setProperty(name, new ByteArrayInputStream(bytes));
         resource.setProperty("jcr:lastModified", Calendar.getInstance());
     }



Mime
View raw message