Added: 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java?rev=1333418&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
 (added)
+++ 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
 Thu May  3 12:13:44 2012
@@ -0,0 +1,133 @@
+/*
+ * 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.rave.jcr.bootstrapping;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.rave.jcr.RaveSystem;
+
+public class ModuleRegistryTest extends AbstractJCRTest {
+
+    private Session session;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        new RaveSystem(getHelper().getRepository(), null).initialize();
+        this.session = getHelper().getReadWriteSession();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        session.refresh(false);
+        session.logout();
+    }
+
+    public void testWriteModule() throws Exception {
+        final ModuleRegistry moduleRegistry = new ModuleRegistry(session, 
"/rave:system");
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        final Module module = 
moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+        moduleRegistry.writeModule(module);
+
+        assertTrue(session.nodeExists("/rave:system/modules/foo"));
+
+        // module properties
+        Node moduleNode = session.getNode("/rave:system/modules/foo");
+        assertTrue(moduleNode.hasProperty("version"));
+        assertEquals(1, moduleNode.getProperty("version").getLong());
+        assertTrue(moduleNode.hasProperty("baseUrl"));
+
+        // namespaces
+        assertTrue(moduleNode.hasNode("namespaces"));
+        assertEquals(1, moduleNode.getNode("namespaces").getNodes().getSize());
+        assertTrue(moduleNode.hasNode("namespaces/foo"));
+        Node namespaceNode = moduleNode.getNode("namespaces/foo");
+        assertTrue(namespaceNode.hasProperty("uri"));
+        assertEquals("http://foo.com/1.0";, 
namespaceNode.getProperty("uri").getString());
+
+        // cnds
+        assertTrue(moduleNode.hasNode("cnds"));
+        assertEquals(1, moduleNode.getNode("cnds").getNodes().getSize());
+        assertTrue(moduleNode.hasNode("cnds/foo"));
+        Node cndNode = moduleNode.getNode("cnds/foo");
+        assertTrue(cndNode.hasProperty("file"));
+        assertEquals("foo.cnd", cndNode.getProperty("file").getString());
+        assertTrue(cndNode.hasProperty("reload"));
+        assertFalse(cndNode.getProperty("reload").getBoolean());
+
+        // contents
+        assertTrue(moduleNode.hasNode("contents"));
+        assertEquals(2, moduleNode.getNode("contents").getNodes().getSize());
+        assertTrue(moduleNode.hasNode("contents/foo"));
+        Node contentNode = moduleNode.getNode("contents/foo");
+        assertTrue(contentNode.hasProperty("file"));
+        assertEquals("foo.json", contentNode.getProperty("file").getString());
+        assertTrue(contentNode.hasProperty("parent"));
+        assertEquals("/testroot", 
contentNode.getProperty("parent").getString());
+        assertTrue(contentNode.hasProperty("importBehavior"));
+        assertEquals("MERGE", 
contentNode.getProperty("importBehavior").getString());
+
+        // resources
+        assertTrue(moduleNode.hasNode("resources"));
+        assertEquals(1, moduleNode.getNode("resources").getNodes().getSize());
+        assertTrue(moduleNode.hasNode("resources/quux"));
+        Node resourceNode = moduleNode.getNode("resources/quux");
+        assertTrue(resourceNode.hasProperty("path"));
+        assertEquals("quux", resourceNode.getProperty("path").getString());
+        assertTrue(resourceNode.hasProperty("parent"));
+        assertEquals("/testroot", 
resourceNode.getProperty("parent").getString());
+        assertTrue(resourceNode.hasProperty("reload"));
+        assertFalse(resourceNode.getProperty("reload").getBoolean());
+        assertTrue(resourceNode.hasProperty("importBehavior"));
+        assertEquals("SKIP", 
resourceNode.getProperty("importBehavior").getString());
+
+    }
+
+    public void testWriteReadModule() throws Exception {
+        final ModuleRegistry moduleRegistry = new ModuleRegistry(session, 
"/rave:system");
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        final Module module = 
moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+        moduleRegistry.writeModule(module);
+        assertEquals(module, moduleRegistry.readModule(module.getName()));
+    }
+
+    public void testRemoveModule() throws Exception {
+        final ModuleRegistry moduleRegistry = new ModuleRegistry(session, 
"/rave:system");
+        final Module module = new Module("foo", "foo", -1);
+        moduleRegistry.writeModule(module);
+        moduleRegistry.removeModule(module);
+        assertFalse(session.nodeExists("/rave:system/modules/foo"));
+    }
+
+    public void testUpdateModule() throws Exception {
+        final ModuleRegistry moduleRegistry = new ModuleRegistry(session, 
"/rave:system");
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        Module module = 
moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+        moduleRegistry.writeModule(module);
+
+        module.addNamespace("bar", "http://bar.com/1.0";, Module.Status.NEW);
+        moduleRegistry.updateModule(module, 
moduleRegistry.readModule(module.getName()));
+
+        module = moduleRegistry.readModule(module.getName());
+        assertEquals(2, module.getNamespaces().size());
+    }
+}

Added: 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleScannerTest.java
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleScannerTest.java?rev=1333418&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleScannerTest.java
 (added)
+++ 
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleScannerTest.java
 Thu May  3 12:13:44 2012
@@ -0,0 +1,87 @@
+/*
+ * 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.rave.jcr.bootstrapping;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.rave.jcr.importing.ImportBehavior;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+public class ModuleScannerTest {
+
+    @Test
+    public void testParseModuleDescriptor() throws Exception {
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        final Module module = 
moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+        checkModule(module);
+    }
+
+    @Test
+    public void testScanModules() throws Exception {
+        final ModuleScanner moduleScanner = new ModuleScanner("rave");
+        final Map<String,Module> modules = moduleScanner.scan();
+        checkModule(modules.get("foo"));
+    }
+
+    private void checkModule(Module module) {
+        assertEquals("foo", module.getName());
+        assertTrue(module.getBaseUrl().endsWith("target/test-classes/"));
+        assertEquals(1, module.getVersion());
+
+        assertEquals(2, module.getDependencies().size());
+        assertTrue(module.getDependencies().contains("bar"));
+        assertTrue(module.getDependencies().contains("quz"));
+
+        assertEquals(1, module.getNamespaces().size());
+        final Module.Namespace namespace = 
module.getNamespaces().iterator().next();
+        assertEquals("foo", namespace.getPrefix());
+        assertEquals("http://foo.com/1.0";, namespace.getUri());
+
+        assertEquals(1, module.getCnds().size());
+        final Module.Cnd cnd = module.getCnds().iterator().next();
+        assertEquals("foo.cnd", cnd.getFile());
+        assertFalse(cnd.isReload());
+
+        assertEquals(2, module.getContents().size());
+        final Iterator<Module.Content> iter = module.getContents().iterator();
+        final Module.Content foo = iter.next();
+        assertEquals("foo.json", foo.getFile());
+        assertEquals("/testroot", foo.getParent());
+        assertTrue(foo.isReload());
+        assertEquals(ImportBehavior.MERGE, foo.getImportBehavior());
+
+        final Module.Content bar = iter.next();
+        assertEquals("bar.json", bar.getFile());
+        assertEquals("/testroot", bar.getParent());
+        assertFalse(bar.isReload());
+
+        assertEquals(1, module.getResources().size());
+        final Module.Resource resource = 
module.getResources().iterator().next();
+        assertEquals("quux", resource.getPath());
+        assertEquals("/testroot", resource.getParent());
+        assertFalse(resource.isReload());
+        assertEquals(ImportBehavior.SKIP, resource.getImportBehavior());
+    }
+
+}

Added: 
rave/sandbox/content-services/rave-jcr-config/src/test/resources/META-INF/rave/module.json
URL: 
http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/resources/META-INF/rave/module.json?rev=1333418&view=auto
==============================================================================
--- 
rave/sandbox/content-services/rave-jcr-config/src/test/resources/META-INF/rave/module.json
 (added)
+++ 
rave/sandbox/content-services/rave-jcr-config/src/test/resources/META-INF/rave/module.json
 Thu May  3 12:13:44 2012
@@ -0,0 +1,34 @@
+{
+  "name" : "foo",
+  "version" : 1,
+  "dependencies" : [ "bar", "quz" ],
+  "namespaces" : {
+      "foo" : "http://foo.com/1.0";
+  },
+  "cnds" : {
+    "foo" : {
+      "file" : "foo.cnd",
+      "reload" : false
+    }
+  },
+  "contents" : {
+    "foo" : {
+      "file" : "foo.json",
+      "parent" : "/testroot",
+      "importBehavior" : "merge"
+    },
+    "bar" : {
+      "file" : "bar.json",
+      "parent" : "/testroot",
+      "reload" : false
+    }
+  },
+  "resources" : {
+    "quux" : {
+      "path" : "quux",
+      "parent" : "/testroot",
+      "importBehavior" : "skip",
+      "reload" : false
+    }
+  }
+}


Reply via email to