jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1157046 - in /jackrabbit/sandbox/spi2microkernel/src/test: java/org/apache/jackrabbit/spi2microkernel/test/ resources/
Date Fri, 12 Aug 2011 10:59:20 GMT
Author: mduerig
Date: Fri Aug 12 10:59:19 2011
New Revision: 1157046

URL: http://svn.apache.org/viewvc?rev=1157046&view=rev
Log:
spi2microkernel (WIP)
- tests: enable TCK

Added:
    jackrabbit/sandbox/spi2microkernel/src/test/resources/
    jackrabbit/sandbox/spi2microkernel/src/test/resources/repositoryStubImpl.properties
      - copied unchanged from r1155302, jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/repositoryStubImpl.properties
Removed:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/repositoryStubImpl.properties
Modified:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/RepositoryStubImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestAll.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestContentLoader.java

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/RepositoryStubImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/RepositoryStubImpl.java?rev=1157046&r1=1157045&r2=1157046&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/RepositoryStubImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/RepositoryStubImpl.java
Fri Aug 12 10:59:19 2011
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.spi2microkernel.test;
 
-import org.apache.jackrabbit.mk.MicroKernelFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.spi2microkernel.Spi2MicrokernelRepositoryServiceFactory;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.RepositoryStub;
@@ -33,24 +31,26 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.Properties;
 
+import static org.apache.jackrabbit.spi2microkernel.util.Exceptions.setCause;
+
 /**
  * <code>RepositoryStubImpl</code> implements a repository stub that
  * initializes a Jackrabbit 3 spi2microkernel repository.
  */
 public class RepositoryStubImpl extends RepositoryStub {
 
-    // private static final String URL = "fs:target/repository-test/repository";
-    private static final String URL = "mem:";
+    private static final String URL = "fs:target/repository-test/repository";
+//    private static final String URL = "mem:";
 
-    private Repository repo;
+    private Repository repository;
 
-    private static Principal KNOWN_PRINCIPAL = new Principal() {
+    private static final Principal KNOWN_PRINCIPAL = new Principal() {
         public String getName() {
             return "an_known_user";
         }
     };
 
-    private static Principal UNKNOWN_PRINCIPAL = new Principal() {
+    private static final Principal UNKNOWN_PRINCIPAL = new Principal() {
         public String getName() {
             return "an_unknown_user";
         }
@@ -58,8 +58,6 @@ public class RepositoryStubImpl extends 
 
     /**
      * Constructor required by TCK.
-     *
-     * @param env the environment.
      */
     public RepositoryStubImpl(Properties settings) {
         super(settings);
@@ -68,69 +66,49 @@ public class RepositoryStubImpl extends 
         superuser.setAttribute("jackrabbit", "jackrabbit");
         readwrite.setAttribute("jackrabbit", "jackrabbit");
         readonly.setAttribute("jackrabbit", "jackrabbit");
+    }
 
-        // this.settings = settings;
+    @Override
+    public Principal getKnownPrincipal(Session session) throws RepositoryException {
+        return KNOWN_PRINCIPAL;
+    }
 
+    @Override
+    public Principal getUnknownPrincipal(Session session) throws RepositoryException, NotExecutableException
{
+        return UNKNOWN_PRINCIPAL;
     }
 
-    /**
-     * @return the repository instance to test.
-     * @throws RepositoryStubException if an error occurs while starting up the
-     *                                 repository.
-     */
+    @Override
     public Repository getRepository() throws RepositoryStubException {
-        if (repo == null) {
-            initRepo();
+        if (repository == null) {
             Iterator<RepositoryFactory> factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);
-            while (repo == null && factories.hasNext()) {
+            Repository rep = null;
+            while (rep == null && factories.hasNext()) {
                 RepositoryFactory factory = factories.next();
                 try {
-                    repo = factory.getRepository(Collections.singletonMap(
+                    rep = factory.getRepository(Collections.singletonMap(
                             Spi2MicrokernelRepositoryServiceFactory.PARAM_URL, URL));
-                    loadTestContent();
-                } catch (Exception e) {
-                    e.printStackTrace();
-
-
-
-                    throw (RepositoryStubException) new RepositoryStubException(e.getMessage()).initCause(e);
+                    loadTestContent(rep);
+                    repository = rep;
+                }
+                catch (Exception e) {
+                    throw setCause(new RepositoryStubException(e.getMessage()), e.getCause());
                 }
             }
         }
-        return repo;
+        return repository;
     }
 
-    private void initRepo() {
-        MicroKernel mk = MicroKernelFactory.getInstance(URL + ";clean");
-        String head = mk.getHeadRevision();
-
-        if (!mk.nodeExists("/default", head)) {
-            head = mk.commit("/",
-                "+\"default\" : {" +
-                    "\"{}testdata\" : {" +
-                        "\"{}stringProp\":\"stringVal\"," +
-                        "\"{}intProp\":42," +
-                        "\"{}mvProp\":[1,2,3]}, " +
-                    "\"{}bar\" : {}}", head, "");
-        }
-
-        mk.dispose();
-    }
-
-    private void loadTestContent() throws Exception {
-        Session session = repo.login();
-        new TestContentLoader().loadTestContent(session);
-        session.logout();
-    }
+    //------------------------------------------< private >---
 
-    @Override
-    public Principal getKnownPrincipal(Session session) throws RepositoryException {
-        return KNOWN_PRINCIPAL;
-    }
-
-    @Override
-    public Principal getUnknownPrincipal(Session session) throws RepositoryException, NotExecutableException
{
-        return UNKNOWN_PRINCIPAL;
+    private static void loadTestContent(Repository rep) throws Exception {
+        Session session = rep.login();
+        try {
+            new TestContentLoader().loadTestContent(session);
+        }
+        finally {
+            session.logout();
+        }
     }
 
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestAll.java?rev=1157046&r1=1157045&r2=1157046&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestAll.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestAll.java
Fri Aug 12 10:59:19 2011
@@ -18,24 +18,15 @@ package org.apache.jackrabbit.spi2microk
 
 import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestResult;
+import org.apache.jackrabbit.test.JCRTestSuite;
 
 public class TestAll extends TestCase {
 
     static {
-        System.setProperty("javax.jcr.tck.properties", "src/test/java/org/apache/jackrabbit/spi2microkernel/test/repositoryStubImpl.properties");
+        System.setProperty("javax.jcr.tck.properties", "src/test/resources/repositoryStubImpl.properties");
     }
 
     public static Test suite() {
-        // fixme return new JCRTestSuite();  
-        return new Test() {
-            public int countTestCases() {
-                return 0;
-            }
-
-            public void run(TestResult result) {
-                
-            }
-        };
+        return new JCRTestSuite();
     }
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestContentLoader.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestContentLoader.java?rev=1157046&r1=1157045&r2=1157046&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestContentLoader.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/test/TestContentLoader.java
Fri Aug 12 10:59:19 2011
@@ -16,11 +16,8 @@
  */
 package org.apache.jackrabbit.spi2microkernel.test;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collection;
+import org.apache.jackrabbit.commons.JcrUtils;
+
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
@@ -30,7 +27,11 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
 import javax.jcr.nodetype.NodeType;
-import org.apache.jackrabbit.commons.JcrUtils;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
 
 /**
  * Test Content Loader.
@@ -44,8 +45,8 @@ public class TestContentLoader {
 
     public void loadTestContent(Session session) throws RepositoryException, IOException
{
         Workspace workspace = session.getWorkspace();
-        Collection<String> workspaces =
-            Arrays.asList(workspace.getAccessibleWorkspaceNames());
+        Collection<String> workspaces = Arrays.asList(workspace.getAccessibleWorkspaceNames());
+
         if (!workspaces.contains("test")) {
             workspace.createWorkspace("test");
         }
@@ -57,7 +58,8 @@ public class TestContentLoader {
 //                TestContentLoader.class.getResourceAsStream("test-nodetypes.xml");
 //            try {
 //                manager.registerNodeTypes(xml, JackrabbitNodeTypeManager.TEXT_XML);
-//            } finally {
+//            }
+//            finally {
 //                xml.close();
 //            }
 //        }
@@ -75,13 +77,15 @@ public class TestContentLoader {
         session.save();
     }
 
+    //------------------------------------------< private >--- 
 
-
-    private  Node getOrAddNode(Node node, String name)
+    private static Node getOrAddNode(Node node, String name)
             throws RepositoryException {
+        
         try {
             return node.getNode(name);
-        } catch (PathNotFoundException e) {
+        }
+        catch (PathNotFoundException e) {
             return node.addNode(name);
         }
     }
@@ -90,7 +94,7 @@ public class TestContentLoader {
      * Creates a boolean, double, long, calendar and a path property at the
      * given node.
      */
-    private  void addPropertyTestData(Node node) throws RepositoryException {
+    private static void addPropertyTestData(Node node) throws RepositoryException {
         node.setProperty("boolean", true);
         node.setProperty("double", Math.PI);
         node.setProperty("long", 90834953485278298l);
@@ -105,7 +109,7 @@ public class TestContentLoader {
     /**
      * Creates a node with a RetentionPolicy
      */
-    private  void addRetentionTestData(Node node) throws RepositoryException {
+    private static void addRetentionTestData(Node node) throws RepositoryException {
 //        RetentionPolicy rp = RetentionPolicyImpl.createRetentionPolicy("testRetentionPolicy",
node.getSession());
 //        node.getSession().getRetentionManager().setRetentionPolicy(node.getPath(), rp);
     }
@@ -114,12 +118,11 @@ public class TestContentLoader {
      * 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 {
+    private static 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", "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");
@@ -130,7 +133,7 @@ public class TestContentLoader {
      * 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 {
+    private static void addNodeTestData(Node node) throws RepositoryException, IOException
{
         if (node.hasNode("multiReference")) {
             node.getNode("multiReference").remove();
         }
@@ -146,22 +149,22 @@ public class TestContentLoader {
         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:data", new ByteArrayInputStream("Hello w\u00F6rld.".getBytes(ENCODING)));
         resource.setProperty("jcr:lastModified", Calendar.getInstance());
+        resource.getSession().save();  // need to save here since with SPI mixins are only
applied on dispatch
 
         Node resReference = getOrAddNode(node, "reference");
         resReference.setProperty("ref", resource);
         // make this node itself referenceable
         resReference.addMixin("mix:referenceable");
+        resReference.getSession().save();  // need to save here since with SPI mixins are
only applied on dispatch
 
         Node multiReference = node.addNode("multiReference");
         ValueFactory factory = node.getSession().getValueFactory();
         multiReference.setProperty("ref", new Value[] {
                 factory.createValue(resource),
                 factory.createValue(resReference)
-            });
+        });
 
         // NodeDefTest requires a test node with a mandatory child node
         JcrUtils.putFile(
@@ -173,7 +176,7 @@ public class TestContentLoader {
      * Creates a lifecycle policy node and another node with a lifecycle
      * referencing that policy.
      */
-    private  void addLifecycleTestData(Node node) throws RepositoryException {
+    private static void addLifecycleTestData(Node node) throws RepositoryException {
         Node policy = getOrAddNode(node, "policy");
         policy.addMixin(NodeType.MIX_REFERENCEABLE);
         Node transitions = getOrAddNode(policy, "transitions");
@@ -223,7 +226,7 @@ public class TestContentLoader {
      * notbinary & single
      * notbinary & multival
      */
-    private  void addExportValues(Node node, String name)
+    private static void addExportValues(Node node, String name)
             throws RepositoryException, IOException {
         String prefix = "valid";
         if (name.indexOf('<') != -1) {



Mime
View raw message