jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1128384 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Fri, 27 May 2011 16:24:54 GMT
Author: mduerig
Date: Fri May 27 16:24:54 2011
New Revision: 1128384

URL: http://svn.apache.org/viewvc?rev=1128384&view=rev
Log:
spi2microkernel prototype (WIP)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1128384&r1=1128383&r2=1128384&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri May 27 16:24:54 2011
@@ -158,7 +158,11 @@ public class RepositoryServiceImpl exten
 
     @Override
     protected void checkWorkspace(String workspaceName) throws NoSuchWorkspaceException {
-        // todo implement checkWorkspace
+        String wspName = Paths.getWorkspaceName(workspaceName);
+        String head = microKernel.getHeadRevision();
+        if (!microKernel.nodeExists('/' + wspName, head)) {
+            throw new NoSuchWorkspaceException(workspaceName);
+        }
     }
 
     //------------------------------------------< Access Control >---

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java?rev=1128384&r1=1128383&r2=1128384&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
Fri May 27 16:24:54 2011
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.spi.NameFac
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 
+import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.RepositoryException;
 
 public final class Paths {
@@ -49,12 +50,12 @@ public final class Paths {
         return cat('/' + getWorkspaceName(wspName), translateQPath(path));
     }
 
-    public static String getWorkspaceName(String name) throws RepositoryException {
+    public static String getWorkspaceName(String name) throws NoSuchWorkspaceException {
         if (name == null || "".equals(name)) {
             return DEFAULT_WORKSPACE;
         }
         else if (name.contains("/")) {
-            throw new RepositoryException("Invalid workspace name: " + name);
+            throw new NoSuchWorkspaceException(name);
         }
         else {
             return name;

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1128384&r1=1128383&r2=1128384&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Fri May 27 16:24:54 2011
@@ -19,10 +19,12 @@
 package org.apache.jackrabbit.spi2microkernel;
 
 import org.apache.jackrabbit.mk.MicroKernelImpl;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
@@ -43,6 +45,9 @@ import static org.junit.Assert.*;
 
 public class Tests {
     private static final File REPO_HOME_DIR = new File("target/repository");
+    
+    private Repository repository;
+    private Session session;
 
     @Before
     public void setup() {
@@ -60,22 +65,34 @@ public class Tests {
         }
     }
 
+    @After
+    public void tearDown() {
+        if (session != null) {
+            session.logout();
+            session = null;
+        }
+    }
+
     @Test
     public void createRepository() throws RepositoryException {
-        Repository repository = acquireRepository(REPO_HOME_DIR);
+        Repository repository = getRepository();
         assertNotNull(repository);        
     }
 
     @Test
     public void login() throws RepositoryException {
-        Session session = getSession();
-        assertNotNull(session);
+        assertNotNull(getSession());
+    }
+
+    @Test(expected = NoSuchWorkspaceException.class)
+    public void loginInvalidWorkspace() throws RepositoryException {
+        Repository repository = getRepository();
+        repository.login("invalid");
     }
 
     @Test
     public void getWorkspaceNames() throws RepositoryException {
-        Session session = getSession();
-        String[] workspaces = session.getWorkspace().getAccessibleWorkspaceNames();
+        String[] workspaces = getSession().getWorkspace().getAccessibleWorkspaceNames();
 
         Set<String> names = new HashSet<String>() {{
             add("default");
@@ -91,24 +108,34 @@ public class Tests {
 
     @Test
     public void createDeleteWorkspace() throws RepositoryException {
-        Session session1 = getSession();
-        session1.getWorkspace().createWorkspace("new");
+        getSession().getWorkspace().createWorkspace("new");
+
+        Session session2 = getRepository().login();
+        try {
+            String[] workspaces = session2.getWorkspace().getAccessibleWorkspaceNames();
+            assertTrue(Arrays.asList(workspaces).contains("new"));
+            Session session3 = getRepository().login("new");
+            assertEquals("new", session3.getWorkspace().getName());
+            session3.logout();
+            session2.getWorkspace().deleteWorkspace("new");
+        }
+        finally {
+            session2.logout();
+        }
 
-        Session session2 = getSession();
-        String[] workspaces = session2.getWorkspace().getAccessibleWorkspaceNames();
-        assertTrue(Arrays.asList(workspaces).contains("new"));
-
-        session2.getWorkspace().deleteWorkspace("new");
-
-        Session session3 = getSession();
-        workspaces = session3.getWorkspace().getAccessibleWorkspaceNames();
-        assertFalse(Arrays.asList(workspaces).contains("new"));
+        Session session4 = getRepository().login();
+        try {
+            String[] workspaces = session4.getWorkspace().getAccessibleWorkspaceNames();
+            assertFalse(Arrays.asList(workspaces).contains("new"));
+        }
+        finally {
+            session4.logout();
+        }
     }
 
     @Test
     public void getRoot() throws RepositoryException {
-        Session session = getSession();
-        Node root = session.getRootNode();
+        Node root = getSession().getRootNode();
         assertNotNull(root);
         assertEquals("", root.getName());
         assertEquals("/", root.getPath());
@@ -136,8 +163,7 @@ public class Tests {
 
     @Test
     public void getProperty() throws RepositoryException {
-        Session session = getSession();
-        Property property = session.getProperty("/foo/stringProp");
+        Property property = getSession().getProperty("/foo/stringProp");
         assertNotNull(property);
         assertEquals("stringProp", property.getName());
         assertEquals("/foo/stringProp", property.getPath());
@@ -164,26 +190,27 @@ public class Tests {
 
     //------------------------------------------< private >---
 
-    private static Repository acquireRepository(File homeDir) throws RepositoryException
{
-        Repository repository = null;
-
-        Iterator<RepositoryFactory> factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);
-        while (repository == null && factories.hasNext()) {
-            RepositoryFactory factory = factories.next();
-            repository = factory.getRepository(Collections.singletonMap(
-                    RepositoryServiceFactoryImpl.PARAM_HOME_DIR, "file:///" + homeDir.getAbsolutePath()));
 
+    private Repository getRepository() throws RepositoryException {
+        if (repository == null) {
+            Iterator<RepositoryFactory> factories = ServiceRegistry.lookupProviders(RepositoryFactory.class);
+            while (repository == null && factories.hasNext()) {
+                RepositoryFactory factory = factories.next();
+                repository = factory.getRepository(Collections.singletonMap(
+                        RepositoryServiceFactoryImpl.PARAM_HOME_DIR, "file:///" + REPO_HOME_DIR.getAbsolutePath()));
+            }
         }
 
         return repository;
     }
 
-    private static Session getSession() throws RepositoryException {
-        Repository repository = acquireRepository(REPO_HOME_DIR);
-        return repository.login();
+    private Session getSession() throws RepositoryException {
+        if (session == null) {
+            session = getRepository().login();
+        }
+        return session;
     }
 
-    private static Node getNode(String path) throws RepositoryException {
-        Session session = getSession();
-        return session.getNode(path);
+    private Node getNode(String path) throws RepositoryException {
+        return getSession().getNode(path);
     }
 }



Mime
View raw message