[dna-commits] DNA SVN: r386 - in trunk/connectors/dna-connector-jbosscache/src: test/java/org/jboss/dna/connector/jbosscache and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Aug 6 01:44:32 EDT 2008


Author: rhauch
Date: 2008-08-06 01:44:32 -0400 (Wed, 06 Aug 2008)
New Revision: 386

Added:
   trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
Modified:
   trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
   trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
Log:
DNA-83 - Federate content from JBoss Cache instance(s)
http://jira.jboss.com/jira/browse/DNA-83

Added more unit tests.

Modified: trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-08-06 05:43:44 UTC (rev 385)
+++ trunk/connectors/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheConnection.java	2008-08-06 05:44:32 UTC (rev 386)
@@ -218,6 +218,8 @@
                             Node<Name, Object> newParent,
                             boolean recursive,
                             Name uuidProperty ) {
+        assert original != null;
+        assert newParent != null;
         // Get or create the new node ...
         Segment name = (Segment)original.getFqn().getLastElement();
         Node<Name, Object> copy = newParent.addChild(getFullyQualifiedName(name));

Modified: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java	2008-08-06 05:43:44 UTC (rev 385)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java	2008-08-06 05:44:32 UTC (rev 386)
@@ -22,6 +22,7 @@
 package org.jboss.dna.connector.jbosscache;
 
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
 import static org.hamcrest.core.IsNull.notNullValue;
 import static org.hamcrest.core.IsNull.nullValue;
 import static org.hamcrest.core.IsSame.sameInstance;
@@ -215,6 +216,7 @@
     @Test
     public void shouldGetNodeIfItExistsInCache() {
         // Set up the cache with data ...
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
         Name uuidProperty = connection.getUuidPropertyName(context);
         Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
         Path nonExistantPath = pathFactory.create("/a/d");
@@ -239,6 +241,7 @@
     @Test
     public void shouldThrowExceptionWithLowestExistingNodeFromGetNodeIfTheNodeDoesNotExist() {
         // Set up the cache with data ...
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
         Name uuidProperty = connection.getUuidPropertyName(context);
         Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c")};
         Path nonExistantPath = pathFactory.create("/a/d");
@@ -262,4 +265,46 @@
         }
     }
 
+    @Test
+    public void shouldCopyNode() {
+        // Set up the cache with data ...
+        stub(source.getUuidPropertyName()).toReturn(DnaLexicon.PropertyNames.UUID);
+        Name uuidProperty = connection.getUuidPropertyName(context);
+        Path[] paths = {pathFactory.create("/a"), pathFactory.create("/a/b"), pathFactory.create("/a/b/c"),
+            pathFactory.create("/a/d")};
+        UUID[] uuids = {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+        cache.put(Fqn.fromList(paths[0].getSegmentsList()), uuidProperty, uuids[0]);
+        cache.put(Fqn.fromList(paths[1].getSegmentsList()), uuidProperty, uuids[1]);
+        cache.put(Fqn.fromList(paths[2].getSegmentsList()), uuidProperty, uuids[2]);
+        cache.put(Fqn.fromList(paths[3].getSegmentsList()), uuidProperty, uuids[3]);
+        Node<Name, Object> nodeA = cache.getNode(Fqn.fromList(paths[0].getSegmentsList()));
+        Node<Name, Object> nodeB = cache.getNode(Fqn.fromList(paths[1].getSegmentsList()));
+        Node<Name, Object> nodeC = cache.getNode(Fqn.fromList(paths[2].getSegmentsList()));
+        Node<Name, Object> nodeD = cache.getNode(Fqn.fromList(paths[3].getSegmentsList()));
+        assertThat(nodeA, is(notNullValue()));
+        assertThat(nodeB, is(notNullValue()));
+        assertThat(nodeC, is(notNullValue()));
+        assertThat(nodeD, is(notNullValue()));
+        assertThat(nodeA.get(uuidProperty), is((Object)uuids[0]));
+        assertThat(nodeB.get(uuidProperty), is((Object)uuids[1]));
+        assertThat(nodeC.get(uuidProperty), is((Object)uuids[2]));
+        assertThat(nodeD.get(uuidProperty), is((Object)uuids[3]));
+        // Make sure the new nodes doesn't exist
+        Path newPathB = pathFactory.create("/a/d/b");
+        Path newPathC = pathFactory.create("/a/d/b/c");
+        Node<Name, Object> newNodeB = cache.getNode(Fqn.fromList(newPathB.getSegmentsList()));
+        Node<Name, Object> newNodeC = cache.getNode(Fqn.fromList(newPathC.getSegmentsList()));
+        assertThat(newNodeB, is(nullValue()));
+        assertThat(newNodeC, is(nullValue()));
+        // Copy node B and place under node D
+        assertThat(connection.copyNode(nodeB, nodeD, true, uuidProperty), is(2));
+        newNodeB = cache.getNode(Fqn.fromList(newPathB.getSegmentsList()));
+        newNodeC = cache.getNode(Fqn.fromList(newPathC.getSegmentsList()));
+        assertThat(newNodeB, is(notNullValue()));
+        assertThat(newNodeC, is(notNullValue()));
+        // Make sure the UUIDs are new ...
+        assertThat(newNodeB.get(uuidProperty), is(not(nodeB.get(uuidProperty))));
+        assertThat(newNodeC.get(uuidProperty), is(not(nodeC.get(uuidProperty))));
+    }
+
 }

Added: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
===================================================================
--- trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java	                        (rev 0)
+++ trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java	2008-08-06 05:44:32 UTC (rev 386)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.jbosscache;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class JBossCacheSourceTest {
+
+    private JBossCacheSource source;
+
+    @Before
+    public void beforeEach() throws Exception {
+        source = new JBossCacheSource();
+    }
+
+    @Test
+    public void shouldReturnNonNullCapabilities() {
+        assertThat(source.getCapabilities(), is(notNullValue()));
+    }
+
+    @Test
+    public void shouldSupportSameNameSiblings() {
+        assertThat(source.getCapabilities().supportsSameNameSiblings(), is(true));
+    }
+
+    @Test
+    public void shouldSupportUpdates() {
+        assertThat(source.getCapabilities().supportsUpdates(), is(true));
+    }
+
+    @Test
+    public void shouldHaveNullSourceNameUponConstruction() {
+        source = new JBossCacheSource();
+        assertThat(source.getName(), is(nullValue()));
+    }
+
+    @Test
+    public void shouldAllowSettingName() {
+        source.setName("Something");
+        assertThat(source.getName(), is("Something"));
+        source.setName("another name");
+        assertThat(source.getName(), is("another name"));
+    }
+
+    @Test
+    public void shouldAllowSettingNameToNull() {
+        source.setName("some name");
+        source.setName(null);
+        assertThat(source.getName(), is(nullValue()));
+    }
+
+}


Property changes on: trunk/connectors/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheSourceTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list