Author: jverhaeg(a)redhat.com
Date: 2008-08-26 17:12:04 -0400 (Tue, 26 Aug 2008)
New Revision: 474
Added:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
Log:
DNA-178: Just another checkpoint closer...
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -0,0 +1,80 @@
+/*
+ * 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.jcr;
+
+import javax.jcr.Item;
+
+/**
+ * @author jverhaeg
+ */
+abstract class AbstractJcrItem implements Item {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isModified()
+ */
+ public final boolean isModified() {
+ // TODO: Update when level 2
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#isNew()
+ */
+ public final boolean isNew() {
+ // TODO: Update when level 2
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#refresh(boolean)
+ */
+ public void refresh( boolean keepChanges ) {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#remove()
+ */
+ public void remove() {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#save()
+ */
+ public void save() {
+ // TODO: Update when level 2
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-26 21:10:10
UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -22,9 +22,14 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.UUID;
+import java.util.Map.Entry;
import javax.jcr.Item;
import javax.jcr.ItemVisitor;
import javax.jcr.Node;
@@ -33,6 +38,7 @@
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.lock.Lock;
import javax.jcr.nodetype.NodeDefinition;
@@ -41,20 +47,21 @@
import javax.jcr.version.VersionHistory;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
-import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path.Segment;
+import org.jboss.dna.spi.graph.impl.BasicPathSegment;
/**
* @author jverhaeg
*/
@NotThreadSafe
-abstract class AbstractJcrNode implements Node {
+abstract class AbstractJcrNode extends AbstractJcrItem implements Node {
private final Session session;
private Set<Property> properties;
+ private Map<Name, Integer> childCountsByName;
+ private UUID uuid;
- // private List<Segment> children;
-
AbstractJcrNode( Session session ) {
assert session != null;
this.session = session;
@@ -65,8 +72,8 @@
*
* @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
*/
- public void accept( ItemVisitor visitor ) {
- throw new UnsupportedOperationException();
+ public void accept( ItemVisitor visitor ) throws RepositoryException {
+ visitor.visit(this);
}
/**
@@ -145,10 +152,16 @@
/**
* {@inheritDoc}
*
+ * @throws IllegalArgumentException if <code>depth</code> is negative.
* @see javax.jcr.Item#getAncestor(int)
*/
- public Item getAncestor( int depth ) {
- throw new UnsupportedOperationException();
+ public final Item getAncestor( int depth ) throws RepositoryException {
+ ArgCheck.isNonNegative(depth, "depth");
+ Node ancestor = this;
+ while (--depth >= 0) {
+ ancestor = ancestor.getParent();
+ }
+ return ancestor;
}
/**
@@ -160,6 +173,13 @@
throw new UnsupportedOperationException();
}
+ private Map<Name, Integer> getChildCountsByName() {
+ if (childCountsByName == null) {
+ childCountsByName = new HashMap<Name, Integer>();
+ }
+ return childCountsByName;
+ }
+
/**
* {@inheritDoc}
*
@@ -181,21 +201,16 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getDepth()
- */
- public int getDepth() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Node#getIndex()
*/
public int getIndex() {
throw new UnsupportedOperationException();
}
+ final UUID getInternalUuid() {
+ return uuid;
+ }
+
/**
* {@inheritDoc}
*
@@ -219,7 +234,7 @@
*
* @see javax.jcr.Node#getNode(java.lang.String)
*/
- public Node getNode( String relPath ) {
+ public final Node getNode( String relativePath ) {
throw new UnsupportedOperationException();
}
@@ -238,16 +253,55 @@
* @see javax.jcr.Node#getNodes(java.lang.String)
*/
public NodeIterator getNodes( String namePattern ) {
- throw new UnsupportedOperationException();
- }
+ ArgCheck.isNotEmpty(namePattern, "namePattern");
+ String[] disjuncts = namePattern.split("\\|");
+ List<Segment> nodes = new ArrayList<Segment>();
+ for (String disjunct : disjuncts) {
+ String pattern = disjunct.trim();
+ ArgCheck.isNotEmpty(pattern, "namePattern");
+ String ndxPattern;
+ int endNdx = pattern.length() - 1;
+ if (pattern.charAt(endNdx) == ']') {
+ int ndx = pattern.indexOf('[');
+ ndxPattern = pattern.substring(ndx + 1, endNdx);
+ pattern = pattern.substring(0, ndx);
+ } else ndxPattern = null;
+ for (Entry<Name, Integer> entry : getChildCountsByName().entrySet()) {
+ if (entry.getKey().getString().matches(pattern)) {
+ if (ndxPattern != null &&
!entry.getValue().toString().matches(ndxPattern)) continue;
+ if (entry.getValue() > 1) nodes.add(new
BasicPathSegment(entry.getKey(), entry.getValue()));
+ else nodes.add(new BasicPathSegment(entry.getKey()));
+ }
+ }
+ }
+ return new NodeIterator() {
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#getPath()
- */
- public String getPath() {
- throw new UnsupportedOperationException();
+ public Node nextNode() {
+ return null;
+ }
+
+ public long getPosition() {
+ return 0;
+ }
+
+ public long getSize() {
+ return 0;
+ }
+
+ public void skip( long skipNum ) {
+ }
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public Object next() {
+ return null;
+ }
+
+ public void remove() {
+ }
+ };
}
/**
@@ -291,13 +345,11 @@
*
* @see javax.jcr.Node#getProperty(java.lang.String)
*/
- public Property getProperty( String relativePath ) throws RepositoryException {
+ public final Property getProperty( String relativePath ) throws RepositoryException
{
ArgCheck.isNotEmpty(relativePath, "relativePath");
// TODO: Handle multi-segment paths
for (Property property : properties) {
- if (relativePath.equals(property.getName())) {
- return property;
- }
+ if (relativePath.equals(property.getName())) return property;
}
return null;
}
@@ -316,7 +368,7 @@
*
* @see javax.jcr.Item#getSession()
*/
- public Session getSession() {
+ public final Session getSession() {
return session;
}
@@ -325,10 +377,15 @@
*
* @see javax.jcr.Node#getUUID()
*/
- public String getUUID() throws RepositoryException {
- // TODO: Check if node is referenceable
- Property prop = getProperty(DnaLexicon.UUID.getString());
- return (prop == null ? null : prop.getString());
+ public final String getUUID() throws RepositoryException {
+ // Check if node is referenceable
+ Property mixinsProp = getProperty("jcr:mixinTypes");
+ if (mixinsProp != null) {
+ for (Value value : mixinsProp.getValues()) {
+ if ("mix:referenceable".equals(value.getString())) return
getProperty("jcr:uuid").getString();
+ }
+ }
+ throw new UnsupportedRepositoryOperationException();
}
/**
@@ -406,28 +463,10 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isModified()
- */
- public boolean isModified() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isNew()
- */
- public boolean isNew() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Item#isNode()
*/
- public boolean isNode() {
- throw new UnsupportedOperationException();
+ public final boolean isNode() {
+ return true;
}
/**
@@ -445,7 +484,7 @@
* @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
public boolean isSame( Item otherItem ) {
- throw new UnsupportedOperationException();
+ return false;
}
/**
@@ -481,24 +520,6 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#refresh(boolean)
- */
- public void refresh( boolean keepChanges ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
* @see javax.jcr.Node#removeMixin(java.lang.String)
*/
public void removeMixin( String mixinName ) {
@@ -546,21 +567,22 @@
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#save()
- */
- public void save() {
- throw new UnsupportedOperationException();
+ final void setChildren( List<Segment> children ) {
+ assert children != null;
+ for (Segment seg : children) {
+ Name name = seg.getName();
+ Integer count = getChildCountsByName().get(name);
+ if (count == null) getChildCountsByName().put(name, 1);
+ else getChildCountsByName().put(name, count + 1);
+ }
}
- void setChildren( List<Segment> children ) {
- assert children != null;
- // this.children = children;
+ final void setInternalUuid( UUID uuid ) {
+ assert uuid != null;
+ this.uuid = uuid;
}
- void setProperties( Set<Property> properties ) {
+ final void setProperties( Set<Property> properties ) {
assert properties != null;
this.properties = properties;
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-26
21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrProperty.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -39,7 +39,7 @@
* @author jverhaeg
*/
@NotThreadSafe
-abstract class AbstractJcrProperty implements Property {
+abstract class AbstractJcrProperty extends AbstractJcrItem implements Property {
private final Node node;
private final ExecutionContext executionContext;
@@ -59,247 +59,189 @@
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getDefinition()
+ * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
*/
- public PropertyDefinition getDefinition() {
- throw new UnsupportedOperationException();
+ public void accept( ItemVisitor visitor ) throws RepositoryException {
+ visitor.visit(this);
}
- ExecutionContext getExecutionContext() {
- return executionContext;
- }
-
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getNode()
+ * @throws IllegalArgumentException if <code>depth</code> is negative.
+ * @see javax.jcr.Item#getAncestor(int)
*/
- public Node getNode() {
- return node;
+ public final Item getAncestor( int depth ) throws RepositoryException {
+ return (depth == 0 ? this : node.getAncestor(depth - 1));
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#getValues()
+ * @see javax.jcr.Property#getDefinition()
*/
- public Value[] getValues() {
+ public PropertyDefinition getDefinition() {
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Property#setValue(javax.jcr.Value)
- */
- public void setValue( Value value ) {
- throw new UnsupportedOperationException();
+ final ExecutionContext getExecutionContext() {
+ return executionContext;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(javax.jcr.Value[])
+ * @see javax.jcr.Property#getNode()
*/
- public void setValue( Value[] values ) {
- throw new UnsupportedOperationException();
+ final public Node getNode() {
+ return node;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.lang.String)
+ * @see javax.jcr.Item#getName()
*/
- public void setValue( String value ) {
- throw new UnsupportedOperationException();
+ public final String getName() {
+ return name.getString();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.lang.String[])
+ * @see javax.jcr.Item#getParent()
*/
- public void setValue( String[] values ) {
- throw new UnsupportedOperationException();
+ public final Node getParent() {
+ return node;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.io.InputStream)
+ * @see javax.jcr.Item#getPath()
*/
- public void setValue( InputStream value ) {
- throw new UnsupportedOperationException();
+ public String getPath() throws RepositoryException {
+ return node.getPath() + '/' + getName();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(long)
+ * @see javax.jcr.Item#getSession()
*/
- public void setValue( long value ) {
- throw new UnsupportedOperationException();
+ public final Session getSession() throws RepositoryException {
+ return node.getSession();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(double)
+ * @see javax.jcr.Item#isNode()
*/
- public void setValue( double value ) {
- throw new UnsupportedOperationException();
+ public final boolean isNode() {
+ return false;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(java.util.Calendar)
+ * @see javax.jcr.Item#isSame(javax.jcr.Item)
*/
- public void setValue( Calendar value ) {
- throw new UnsupportedOperationException();
+ public boolean isSame( Item otherItem ) throws RepositoryException {
+ if (otherItem instanceof Property) {
+ Property otherProp = (Property)otherItem;
+ return (getName().equals(otherProp.getName()) &&
getNode().isSame(otherProp.getNode()));
+ }
+ return false;
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(boolean)
+ * @see javax.jcr.Property#setValue(javax.jcr.Value)
*/
- public void setValue( boolean value ) {
+ public void setValue( Value value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Property#setValue(javax.jcr.Node)
+ * @see javax.jcr.Property#setValue(javax.jcr.Value[])
*/
- public void setValue( Node value ) {
+ public void setValue( Value[] values ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#accept(javax.jcr.ItemVisitor)
+ * @see javax.jcr.Property#setValue(java.lang.String)
*/
- public void accept( ItemVisitor visitor ) {
+ public void setValue( String value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getAncestor(int)
+ * @see javax.jcr.Property#setValue(java.lang.String[])
*/
- public Item getAncestor( int depth ) {
+ public void setValue( String[] values ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getDepth()
+ * @see javax.jcr.Property#setValue(java.io.InputStream)
*/
- public int getDepth() {
+ public void setValue( InputStream value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getName()
+ * @see javax.jcr.Property#setValue(long)
*/
- public String getName() {
- return name.getString();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#getParent()
- */
- public Node getParent() {
+ public void setValue( long value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getPath()
+ * @see javax.jcr.Property#setValue(double)
*/
- public String getPath() {
+ public void setValue( double value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#getSession()
+ * @see javax.jcr.Property#setValue(java.util.Calendar)
*/
- public Session getSession() throws RepositoryException {
- return node.getSession();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isModified()
- */
- public boolean isModified() {
+ public void setValue( Calendar value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isNew()
+ * @see javax.jcr.Property#setValue(boolean)
*/
- public boolean isNew() {
+ public void setValue( boolean value ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
*
- * @see javax.jcr.Item#isNode()
+ * @see javax.jcr.Property#setValue(javax.jcr.Node)
*/
- public boolean isNode() {
+ public void setValue( Node value ) {
throw new UnsupportedOperationException();
}
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#isSame(javax.jcr.Item)
- */
- public boolean isSame( Item otherItem ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#refresh(boolean)
- */
- public void refresh( boolean keepChanges ) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see javax.jcr.Item#save()
- */
- public void save() {
- throw new UnsupportedOperationException();
- }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-26 21:10:10 UTC
(rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNode.java 2008-08-26 21:12:04 UTC
(rev 474)
@@ -21,11 +21,13 @@
*/
package org.jboss.dna.jcr;
+import java.util.UUID;
import javax.jcr.Node;
-import javax.jcr.Property;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.spi.graph.Name;
/**
* @author jverhaeg
@@ -33,20 +35,35 @@
@NotThreadSafe
final class JcrNode extends AbstractJcrNode {
- JcrNode( Session session ) {
+ private final UUID parentUuid;
+ private final Name name;
+
+ JcrNode( Session session,
+ UUID parentUuid,
+ Name name ) {
super(session);
+ assert parentUuid != null;
+ assert name != null;
+ this.parentUuid = parentUuid;
+ this.name = name;
}
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() throws RepositoryException {
+ return getParent().getDepth() + 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Item#getName()
*/
- public String getName() throws RepositoryException {
- Property prop = getProperty("jcr:name");
- assert prop != null;
- assert prop.getValue() != null;
- return prop.getValue().getString();
+ public String getName() {
+ return name.getString();
}
/**
@@ -54,7 +71,30 @@
*
* @see javax.jcr.Item#getParent()
*/
- public Node getParent() {
- throw new UnsupportedOperationException();
+ public Node getParent() throws RepositoryException {
+ return getSession().getNodeByUUID(parentUuid.toString());
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() throws RepositoryException {
+ Node parent = getParent();
+ StringBuilder builder = new StringBuilder(parent.getPath());
+ assert builder.length() > 0;
+ if (builder.charAt(builder.length() - 1) != '/') {
+ builder.append('/');
+ }
+ String name = getName();
+ builder.append(name);
+ NodeIterator iter = parent.getNodes(name);
+ if (iter.getSize() > 1) {
+ builder.append('[');
+ builder.append(getIndex());
+ builder.append(']');
+ }
+ return builder.toString();
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-26 21:10:10 UTC
(rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrProperty.java 2008-08-26 21:12:04 UTC
(rev 474)
@@ -22,6 +22,7 @@
package org.jboss.dna.jcr;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
@@ -32,6 +33,7 @@
import javax.jcr.ValueFormatException;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
import org.jboss.dna.spi.graph.ValueFactories;
/**
@@ -63,11 +65,19 @@
} else if (value instanceof Long) {
jcrValue = new JcrValue<Long>(valueFactories, PropertyType.LONG,
(Long)value);
} else if (value instanceof UUID) {
- jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.STRING,
(UUID)value);
+ jcrValue = new JcrValue<UUID>(valueFactories, PropertyType.REFERENCE,
(UUID)value);
} else if (value instanceof String) {
jcrValue = new JcrValue<String>(valueFactories, PropertyType.STRING,
(String)value);
+ } else if (value instanceof Name) {
+ jcrValue = new JcrValue<Name>(valueFactories, PropertyType.NAME,
(Name)value);
+ } else if (value instanceof Path) {
+ jcrValue = new JcrValue<Path>(valueFactories, PropertyType.PATH,
(Path)value);
+ } else if (value instanceof InputStream) {
+ jcrValue = new JcrValue<InputStream>(valueFactories,
PropertyType.BINARY, (InputStream)value);
+ } else if (value instanceof Reader) {
+ jcrValue = new JcrValue<Reader>(valueFactories, PropertyType.BINARY,
(Reader)value);
} else {
- jcrValue = new JcrValue<Object>(valueFactories, PropertyType.BINARY,
value);
+ jcrValue = new
JcrValue<Object>(getExecutionContext().getValueFactories(), PropertyType.BINARY,
value);
}
}
@@ -92,6 +102,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() throws RepositoryException {
+ return getParent().getDepth() + 1;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() throws RepositoryException {
@@ -160,4 +179,69 @@
public Value getValue() {
return jcrValue;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() throws ValueFormatException {
+ throw new ValueFormatException();
+ }
+ //
+ // /**
+ // * {@inheritDoc}
+ // *
+ // * @throws IllegalArgumentException if <code>value</code> is
<code>null</code>.
+ // * @see javax.jcr.Property#setValue(javax.jcr.Value)
+ // */
+ // @SuppressWarnings( "fallthrough" )
+ // public void setValue( Value value ) throws RepositoryException {
+ // ArgCheck.isNotNull(value, "value");
+ // // TODOx: Check node type constraint
+ // try {
+ // jcrValue = JcrValue.class.cast(value);
+ // } catch (ClassCastException error) {
+ // // TODOx: not sure if this is even possible
+ // ValueFactories valueFactories = getExecutionContext().getValueFactories();
+ // int type = value.getType();
+ // switch (type) {
+ // case PropertyType.BINARY: {
+ // jcrValue = new JcrValue<InputStream>(valueFactories, type,
value.getStream());
+ // break;
+ // }
+ // case PropertyType.BOOLEAN: {
+ // jcrValue = new JcrValue<Boolean>(valueFactories, type, value.getBoolean());
+ // break;
+ // }
+ // case PropertyType.DATE: {
+ // jcrValue = new JcrValue<Calendar>(valueFactories, type, value.getDate());
+ // break;
+ // }
+ // case PropertyType.DOUBLE: {
+ // jcrValue = new JcrValue<Double>(valueFactories, type, value.getDouble());
+ // break;
+ // }
+ // case PropertyType.LONG: {
+ // jcrValue = new JcrValue<Long>(valueFactories, type, value.getLong());
+ // break;
+ // }
+ // case PropertyType.REFERENCE: {
+ // try {
+ // jcrValue = new JcrValue<UUID>(valueFactories, type,
UUID.fromString(value.getString()));
+ // } catch (IllegalArgumentException fallsThroughToString) {
+ // }
+ // }
+ // case PropertyType.NAME:
+ // case PropertyType.PATH:
+ // case PropertyType.STRING: {
+ // jcrValue = new JcrValue<String>(valueFactories, type, value.getString());
+ // break;
+ // }
+ // default: {
+ // throw new AssertionError("Unsupported PropertyType: " +
value.getType());
+ // }
+ // }
+ // }
+ // }
}
Added: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
(rev 0)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -0,0 +1,114 @@
+/*
+ * 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.jcr;
+
+import java.util.Iterator;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+
+/**
+ * @author jverhaeg
+ */
+@NotThreadSafe
+class JcrPropertyIterator implements PropertyIterator {
+
+ private final Set<Property> properties;
+ private final Iterator<Property> iterator;
+ private long index = 0L;
+
+ JcrPropertyIterator( Set<Property> properties ) {
+ assert properties != null;
+ this.properties = properties;
+ iterator = properties.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.PropertyIterator#nextProperty()
+ */
+ public Property nextProperty() {
+ Property property = iterator.next();
+ index++;
+ return property;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getPosition()
+ */
+ public long getPosition() {
+ return index;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#getSize()
+ */
+ public long getSize() {
+ return properties.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.RangeIterator#skip(long)
+ */
+ public void skip( long count ) {
+ ArgCheck.isNonNegative(count, "count");
+ while (--count >= 0) {
+ iterator.next();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#next()
+ */
+ public Object next() {
+ return nextProperty();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ iterator.remove();
+ }
+}
Property changes on:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyIterator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-26 21:10:10
UTC (rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import java.util.WeakHashMap;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
@@ -253,7 +254,7 @@
// Create session
try {
return new JcrSession(this, execContext, workspaceName,
connectionFactory.createConnection(workspaceName),
- new WeakHashMap<String,
WeakReference<Node>>());
+ new WeakHashMap<UUID,
WeakReference<Node>>());
} catch (InterruptedException error) {
throw new RepositoryException(error);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-26 21:10:10 UTC
(rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRootNode.java 2008-08-26 21:12:04 UTC
(rev 474)
@@ -39,6 +39,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Item#getName()
*/
public String getName() {
@@ -53,4 +62,13 @@
public Node getParent() throws ItemNotFoundException {
throw new ItemNotFoundException();
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Item#getPath()
+ */
+ public String getPath() {
+ return "/";
+ }
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-26 21:10:10 UTC
(rev 473)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-08-26 21:12:04 UTC
(rev 474)
@@ -49,6 +49,7 @@
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.graph.Name;
import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.UuidFactory;
import org.jboss.dna.spi.graph.Path.Segment;
import org.jboss.dna.spi.graph.commands.GraphCommand;
import org.jboss.dna.spi.graph.commands.impl.BasicGetNodeCommand;
@@ -64,7 +65,7 @@
private final Repository repository;
private final ExecutionContext executionContext;
private RepositoryConnection connection;
- private final Map<String, WeakReference<Node>> uuid2NodeMap;
+ private final Map<UUID, WeakReference<Node>> nodesByUuid;
private boolean isLive;
private Workspace workspace;
private JcrRootNode rootNode;
@@ -73,16 +74,16 @@
ExecutionContext executionContext,
String workspaceName,
RepositoryConnection connection,
- Map<String, WeakReference<Node>> uuid2NodeMap ) throws
RepositoryException {
+ Map<UUID, WeakReference<Node>> nodesByUuid ) throws
RepositoryException {
assert repository != null;
assert executionContext != null;
assert workspaceName != null;
assert connection != null;
- assert uuid2NodeMap != null;
+ assert nodesByUuid != null;
this.repository = repository;
this.executionContext = executionContext;
this.connection = connection;
- this.uuid2NodeMap = uuid2NodeMap;
+ this.nodesByUuid = nodesByUuid;
this.isLive = true;
// Following must be initialized after session's state is initialized
this.workspace = new JcrWorkspace(this, workspaceName);
@@ -210,7 +211,8 @@
BasicGetNodeCommand getNodeCommand = new BasicGetNodeCommand(parentPath);
execute(getNodeCommand);
// First search for a child with the last name in the path
- Name name = path.getLastSegment().getName();
+ Segment lastSeg = path.getLastSegment();
+ Name name = lastSeg.getName();
for (Segment seg : getNodeCommand.getChildren()) {
if (seg.getName().equals(name)) {
return getNode(path);
@@ -218,9 +220,8 @@
}
// If a node isn't found & last segment contains no index, get parent
node & search for a property with the last name in
// the path
- Segment seg = path.getLastSegment();
- if (!seg.hasIndex()) {
- return getNode(parentPath).getProperty(seg.getString());
+ if (!lastSeg.hasIndex()) {
+ return getNode(parentPath).getProperty(lastSeg.getString());
}
// If a property isn't found, throw a PathNotFoundException
throw new PathNotFoundException(JcrI18n.pathNotFound.text(path));
@@ -267,10 +268,11 @@
BasicGetNodeCommand command = new BasicGetNodeCommand(path);
execute(command);
// First check if node already exists. We don't need to check for changes
since that will be handled by an observer
- org.jboss.dna.spi.graph.Property dnaUuidProp =
command.getPropertiesByName().get(DnaLexicon.UUID);
+ org.jboss.dna.spi.graph.Property dnaUuidProp =
command.getPropertiesByName().get(executionContext.getValueFactories().getNameFactory().create("jcr:uuid"));
+ if (dnaUuidProp == null) dnaUuidProp =
command.getPropertiesByName().get(DnaLexicon.UUID);
if (dnaUuidProp != null) {
- String uuid =
executionContext.getValueFactories().getStringFactory().create(dnaUuidProp.getValues()).next();
- WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ UUID uuid =
executionContext.getValueFactories().getUuidFactory().create(dnaUuidProp.getValues()).next();
+ WeakReference<Node> ref = nodesByUuid.get(uuid);
if (ref != null) {
Node node = ref.get();
if (node != null) {
@@ -279,7 +281,11 @@
}
}
// If not create a new one & populate it
- JcrNode node = new JcrNode(this);
+ JcrNode node;
+ Path parentPath = path.getParent();
+ if (parentPath.isRoot()) node = new JcrNode(this,
((JcrRootNode)getRootNode()).getInternalUuid(),
+ path.getLastSegment().getName());
+ else node = new JcrNode(this, ((JcrNode)getNode(parentPath)).getInternalUuid(),
path.getLastSegment().getName());
populateNode(node, command);
return node;
}
@@ -437,7 +443,7 @@
}
private void populateNode( AbstractJcrNode node,
- BasicGetNodeCommand getNodeCommand ) throws
RepositoryException {
+ BasicGetNodeCommand getNodeCommand ) {
// TODO: What do we do to validate node against its primary type?
assert node != null;
assert getNodeCommand != null;
@@ -445,20 +451,23 @@
node.setChildren(getNodeCommand.getChildren());
// Create JCR properties for corresponding DNA properties
Set<Property> properties = new HashSet<Property>();
- boolean uuidFound = false;
+ UUID uuid = null;
+ Name jcrUuidName =
executionContext.getValueFactories().getNameFactory().create("jcr:uuid");
+ UuidFactory uuidFactory = executionContext.getValueFactories().getUuidFactory();
for (org.jboss.dna.spi.graph.Property dnaProp : getNodeCommand.getProperties())
{
- if (DnaLexicon.UUID.equals(dnaProp.getName())) {
- uuidFound = true;
+ Name name = dnaProp.getName();
+ if (uuid == null && DnaLexicon.UUID.equals(name)) uuid =
uuidFactory.create(dnaProp.getValues()).next();
+ else {
+ if (jcrUuidName.equals(name)) uuid =
uuidFactory.create(dnaProp.getValues()).next();
+ properties.add(new JcrProperty(node, executionContext, name,
dnaProp.getValues().next()));
}
- properties.add(new JcrProperty(node, executionContext, dnaProp.getName(),
dnaProp.getValues().next()));
}
- // Ensure a UUID property exists
- if (!uuidFound) {
- properties.add(new JcrProperty(node, executionContext, DnaLexicon.UUID,
UUID.randomUUID()));
- }
node.setProperties(properties);
- // Setup node to be retrieved by UUID
- uuid2NodeMap.put(node.getUUID(), new WeakReference<Node>(node));
+ // Set node's UUID, creating one if necessary
+ if (uuid == null) uuid = UUID.randomUUID();
+ node.setInternalUuid(uuid);
+ // Setup node to be retrieved by DNA UUID
+ nodesByUuid.put(node.getInternalUuid(), new WeakReference<Node>(node));
}
/**
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
(rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -0,0 +1,105 @@
+/*
+ * 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.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author jverhaeg
+ */
+public class AbstractJcrItemTest {
+
+ private AbstractJcrItem item;
+
+ @Before
+ public void before() {
+ item = new AbstractJcrItem() {
+
+ public void accept( ItemVisitor visitor ) {
+ }
+
+ public Item getAncestor( int depth ) {
+ return null;
+ }
+
+ public int getDepth() {
+ return 0;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public Node getParent() {
+ return null;
+ }
+
+ public String getPath() {
+ return null;
+ }
+
+ public Session getSession() {
+ return null;
+ }
+
+ public boolean isNode() {
+ return false;
+ }
+
+ public boolean isSame( Item otherItem ) {
+ return false;
+ }
+ };
+ }
+
+ @Test
+ public void shouldNotBeNew() throws Exception {
+ assertThat(item.isNew(), is(false));
+ }
+
+ @Test
+ public void shouldNotBeModified() throws Exception {
+ assertThat(item.isModified(), is(false));
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowRefresh() throws Exception {
+ item.refresh(false);
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowRemove() throws Exception {
+ item.remove();
+ }
+
+ @Test( expected = UnsupportedOperationException.class )
+ public void shouldNotAllowSave() throws Exception {
+ item.save();
+ }
+}
Property changes on:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrItemTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-26
21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrNodeTest.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -26,10 +26,12 @@
import static org.mockito.Mockito.stub;
import java.util.HashSet;
import java.util.Set;
+import java.util.UUID;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
-import org.jboss.dna.spi.DnaLexicon;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -52,6 +54,10 @@
properties = new HashSet<Property>();
node = new AbstractJcrNode(session) {
+ public int getDepth() {
+ return 0;
+ }
+
public String getName() {
return null;
}
@@ -59,14 +65,29 @@
public Node getParent() {
return null;
}
+
+ public String getPath() {
+ return null;
+ }
};
node.setProperties(properties);
}
+ @Test
+ public void shouldAllowVisitation() throws Exception {
+ ItemVisitor visitor = Mockito.mock(ItemVisitor.class);
+ node.accept(visitor);
+ Mockito.verify(visitor).visit(node);
+ }
+
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
new AbstractJcrNode(null) {
+ public int getDepth() {
+ return 0;
+ }
+
public String getName() {
return null;
}
@@ -74,21 +95,33 @@
public Node getParent() {
return null;
}
+
+ public String getPath() {
+ return null;
+ }
};
}
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeAncestorDepth() throws Exception {
+ node.getAncestor(-1);
+ }
+
@Test
+ public void shouldProvideAncestor() throws Exception {
+ assertThat(node.getAncestor(0), is((Item)node));
+ }
+
+ @Test
public void shouldProvideSession() throws Exception {
assertThat(node.getSession(), is(session));
}
@Test
- public void shouldProvideUuid() throws Exception {
- Property property = Mockito.mock(Property.class);
- stub(property.getName()).toReturn(DnaLexicon.UUID.getString());
- stub(property.getString()).toReturn("uuid");
- properties.add(property);
- assertThat(node.getUUID(), is("uuid"));
+ public void shouldProvideInternalUuid() throws Exception {
+ UUID uuid = UUID.randomUUID();
+ node.setInternalUuid(uuid);
+ assertThat(node.getInternalUuid(), is(uuid));
}
@Test
@@ -98,4 +131,9 @@
properties.add(property);
assertThat(node.getProperty("test"), is(property));
}
+
+ @Test
+ public void shouldBeANode() {
+ assertThat(node.isNode(), is(true));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-26
21:10:10 UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrPropertyTest.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -26,7 +26,11 @@
import static org.mockito.Mockito.stub;
import java.io.InputStream;
import java.util.Calendar;
+import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemVisitor;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Session;
import javax.jcr.Value;
import org.jboss.dna.spi.ExecutionContext;
@@ -56,6 +60,13 @@
prop = new MockAbstractJcrProperty(node, executionContext, name);
}
+ @Test
+ public void shouldAllowVisitation() throws Exception {
+ ItemVisitor visitor = Mockito.mock(ItemVisitor.class);
+ prop.accept(visitor);
+ Mockito.verify(visitor).visit(prop);
+ }
+
@Test( expected = AssertionError.class )
public void shouldNotAllowNoSession() throws Exception {
new MockAbstractJcrProperty(null, executionContext, name);
@@ -71,7 +82,26 @@
new MockAbstractJcrProperty(node, executionContext, null);
}
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeAncestorDepth() throws Exception {
+ stub(node.getAncestor(-2)).toThrow(new IllegalArgumentException());
+ prop.getAncestor(-1);
+ }
+
@Test
+ public void shouldProvideAncestor() throws Exception {
+ assertThat(prop.getAncestor(0), is((Item)prop));
+ stub(node.getAncestor(0)).toReturn(node);
+ assertThat(prop.getAncestor(1), is((Item)node));
+ }
+
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ stub(node.getAncestor(1)).toThrow(new ItemNotFoundException());
+ prop.getAncestor(2);
+ }
+
+ @Test
public void shouldProvideSession() throws Exception {
Session session = Mockito.mock(Session.class);
stub(node.getSession()).toReturn(session);
@@ -94,6 +124,56 @@
assertThat(prop.getName(), is("name"));
}
+ @Test
+ public void shouldProvideParent() throws Exception {
+ assertThat(prop.getParent(), is(node));
+ }
+
+ @Test
+ public void shouldProvidePath() throws Exception {
+ stub(node.getPath()).toReturn("/nodeName");
+ stub(name.getString()).toReturn("propertyName");
+ assertThat(prop.getPath(), is("/nodeName/propertyName"));
+ }
+
+ @Test
+ public void shouldNotBeANode() {
+ assertThat(prop.isNode(), is(false));
+ }
+
+ @Test
+ public void shouldIndicateSameAsNodeWithSameParentAndName() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName");
+ stub(node.isSame(otherNode)).toReturn(true);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext,
otherName);
+ assertThat(prop.isSame(otherProp), is(true));
+ }
+
+ @Test
+ public void shouldIndicateDifferentThanNodeWithDifferentParent() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName");
+ stub(node.isSame(otherNode)).toReturn(false);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext,
otherName);
+ assertThat(prop.isSame(otherProp), is(false));
+ }
+
+ @Test
+ public void shouldIndicateDifferentThanNodeWithDifferentName() throws Exception {
+ stub(name.getString()).toReturn("propertyName");
+ Node otherNode = Mockito.mock(Node.class);
+ Name otherName = Mockito.mock(Name.class);
+ stub(otherName.getString()).toReturn("propertyName2");
+ stub(node.isSame(otherNode)).toReturn(true);
+ Property otherProp = new MockAbstractJcrProperty(otherNode, executionContext,
otherName);
+ assertThat(prop.isSame(otherProp), is(false));
+ }
+
private class MockAbstractJcrProperty extends AbstractJcrProperty {
MockAbstractJcrProperty( Node node,
@@ -123,6 +203,15 @@
/**
* {@inheritDoc}
*
+ * @see javax.jcr.Item#getDepth()
+ */
+ public int getDepth() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() {
@@ -191,5 +280,14 @@
public Value getValue() {
return null;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.jcr.Property#getValues()
+ */
+ public Value[] getValues() {
+ return null;
+ }
}
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-26 21:10:10 UTC
(rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNodeTest.java 2008-08-26 21:12:04 UTC
(rev 474)
@@ -24,11 +24,15 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.stub;
+import java.util.ArrayList;
import java.util.HashSet;
-import java.util.Set;
+import java.util.UUID;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
-import javax.jcr.Value;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path.Segment;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -41,26 +45,40 @@
public class JcrNodeTest {
private JcrNode node;
+ private Node root;
@Mock
private Session session;
- private Set<Property> properties;
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- properties = new HashSet<Property>();
- node = new JcrNode(session);
- node.setProperties(properties);
+ root = new JcrRootNode(session);
+ Name name = Mockito.mock(Name.class);
+ stub(name.getString()).toReturn("name");
+ UUID uuid = UUID.randomUUID();
+ node = new JcrNode(session, uuid, name);
+ stub(session.getNodeByUUID(uuid.toString())).toReturn(root);
+ node.setProperties(new HashSet<Property>());
+ node.setChildren(new ArrayList<Segment>());
}
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ node.getAncestor(2);
+ }
+
@Test
+ public void shouldHaveZeroDepth() throws Exception {
+ assertThat(node.getDepth(), is(1));
+ }
+
+ @Test
public void shouldProvideName() throws Exception {
- Property property = Mockito.mock(Property.class);
- stub(property.getName()).toReturn("jcr:name");
- Value value = Mockito.mock(Value.class);
- stub(value.getString()).toReturn("name");
- stub(property.getValue()).toReturn(value);
- properties.add(property);
assertThat(node.getName(), is("name"));
}
+
+ @Test
+ public void shouldProvidePath() throws Exception {
+ assertThat(node.getPath(), is("/name"));
+ }
}
Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
(rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java 2008-08-26
21:12:04 UTC (rev 474)
@@ -0,0 +1,180 @@
+/*
+ * 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.jcr;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * @author jverhaeg
+ */
+public class JcrPropertyIteratorTest {
+
+ @Test( expected = AssertionError.class )
+ public void shouldNotAllowNoProperties() throws Exception {
+ new JcrPropertyIterator(null);
+ }
+
+ @Test
+ public void shouldIndicateWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.hasNext(), is(false));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.hasNext(), is(true));
+ }
+
+ @Test
+ public void shouldAllowNextWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ Property prop1 = Mockito.mock(Property.class);
+ props.add(prop1);
+ Property prop2 = Mockito.mock(Property.class);
+ props.add(prop2);
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ Property iterProp1 = (Property)iter.next();
+ assertThat(iterProp1, notNullValue());
+ Property iterProp2 = (Property)iter.next();
+ assertThat(iterProp2, notNullValue());
+ assertThat(iterProp1, is(not(iterProp2)));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowNextWhenNoPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ }
+
+ @Test
+ public void shouldAllowNextPropertyWhenPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ Property prop1 = Mockito.mock(Property.class);
+ props.add(prop1);
+ Property prop2 = Mockito.mock(Property.class);
+ props.add(prop2);
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ Property iterProp1 = iter.nextProperty();
+ assertThat(iterProp1, notNullValue());
+ Property iterProp2 = iter.nextProperty();
+ assertThat(iterProp2, notNullValue());
+ assertThat(iterProp1, is(not(iterProp2)));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowNextPropertyWhenNoPropertiesRemain() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.nextProperty();
+ }
+
+ @Test
+ public void shouldAllowRemoveAfterNext() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ iter.remove();
+ assertThat(props.isEmpty(), is(true));
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowRemoveBeforeNext() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.remove();
+ }
+
+ @Test( expected = IllegalStateException.class )
+ public void shouldNotAllowRemoveTwice() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.next();
+ iter.remove();
+ iter.remove();
+ }
+
+ @Test
+ public void shouldProvideSize() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.getSize(), is(0L));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.getSize(), is(1L));
+ iter.next();
+ iter.remove();
+ assertThat(iter.getSize(), is(0L));
+ }
+
+ @Test
+ public void shouldProvidePosition() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ assertThat(iter.getPosition(), is(0L));
+ props.add(Mockito.mock(Property.class));
+ iter = new JcrPropertyIterator(props);
+ assertThat(iter.getPosition(), is(0L));
+ iter.next();
+ assertThat(iter.getPosition(), is(1L));
+ iter.remove();
+ assertThat(iter.getPosition(), is(1L));
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowNegativeSkip() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(-1);
+ }
+
+ @Test
+ public void shouldAllowSkip() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ props.add(Mockito.mock(Property.class));
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(0);
+ assertThat(iter.hasNext(), is(true));
+ iter.skip(1);
+ assertThat(iter.hasNext(), is(false));
+ }
+
+ @Test( expected = NoSuchElementException.class )
+ public void shouldNotAllowSkipPastRemainingProperties() throws Exception {
+ Set<Property> props = new HashSet<Property>();
+ PropertyIterator iter = new JcrPropertyIterator(props);
+ iter.skip(1);
+ }
+}
Property changes on:
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyIteratorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-26 21:10:10
UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -24,7 +24,9 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Calendar;
import java.util.UUID;
import javax.jcr.Node;
@@ -35,8 +37,10 @@
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -65,6 +69,7 @@
public void shouldProvideBoolean() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, true);
assertThat(prop.getBoolean(), is(true));
+ assertThat(prop.getType(), is(PropertyType.BOOLEAN));
}
@Test
@@ -72,36 +77,30 @@
Calendar cal = Calendar.getInstance();
Property prop = new JcrProperty(node, executionContext, name, cal);
assertThat(prop.getDate(), is(cal));
+ assertThat(prop.getType(), is(PropertyType.DATE));
prop = new JcrProperty(node, executionContext, name, cal.getTime());
assertThat(prop.getDate(), is(cal));
+ assertThat(prop.getType(), is(PropertyType.DATE));
}
@Test
public void shouldProvideDouble() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, 1.0);
assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
prop = new JcrProperty(node, executionContext, name, 1.0F);
assertThat(prop.getDouble(), is(1.0));
+ assertThat(prop.getType(), is(PropertyType.DOUBLE));
}
@Test
- public void shouldProvideLength() throws Exception {
- assertThat(new JcrProperty(node, executionContext, name,
"value").getLength(), is(5L));
- Object obj = new Object();
- assertThat(new JcrProperty(node, executionContext, name, obj).getLength(),
is((long)obj.toString().length()));
- }
-
- @Test( expected = ValueFormatException.class )
- public void shouldNotProvideLengths() throws Exception {
- new JcrProperty(node, executionContext, name, "value").getLengths();
- }
-
- @Test
public void shouldProvideLong() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, 1);
assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.LONG));
prop = new JcrProperty(node, executionContext, name, 1L);
assertThat(prop.getLong(), is(1L));
+ assertThat(prop.getType(), is(PropertyType.LONG));
}
@Test
@@ -116,26 +115,68 @@
public void shouldProvideString() throws Exception {
Property prop = new JcrProperty(node, executionContext, name,
"value");
assertThat(prop.getString(), is("value"));
+ assertThat(prop.getType(), is(PropertyType.STRING));
}
@Test
- public void shouldProvideUuid() throws Exception {
+ public void shouldAllowReferenceValue() throws Exception {
UUID uuid = UUID.randomUUID();
Property prop = new JcrProperty(node, executionContext, name, uuid);
assertThat(prop.getString(), is(uuid.toString()));
+ assertThat(prop.getType(), is(PropertyType.REFERENCE));
}
@Test
- public void shouldProvideType() throws Exception {
- Property prop = new JcrProperty(node, executionContext, name,
UUID.randomUUID());
- assertThat(prop.getType(), is(PropertyType.STRING));
+ public void shouldAllowBinaryValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name,
Mockito.mock(Reader.class));
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ prop = new JcrProperty(node, executionContext, name,
Mockito.mock(InputStream.class));
+ assertThat(prop.getType(), is(PropertyType.BINARY));
+ prop = new JcrProperty(node, executionContext, name, new Object());
+ assertThat(prop.getType(), is(PropertyType.BINARY));
}
@Test
+ public void shouldAllowNameValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, name);
+ assertThat(prop.getType(), is(PropertyType.NAME));
+ }
+
+ @Test
+ public void shouldAllowPathValue() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name,
Mockito.mock(Path.class));
+ assertThat(prop.getType(), is(PropertyType.PATH));
+ }
+
+ @Test
public void shouldProvideValue() throws Exception {
Property prop = new JcrProperty(node, executionContext, name, true);
Value val = prop.getValue();
assertThat(val, notNullValue());
assertThat(val.getBoolean(), is(true));
}
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideValues() throws Exception {
+ new JcrProperty(node, executionContext, name, true).getValues();
+ }
+
+ @Test
+ public void shouldProvideLength() throws Exception {
+ assertThat(new JcrProperty(node, executionContext, name,
"value").getLength(), is(5L));
+ Object obj = new Object();
+ assertThat(new JcrProperty(node, executionContext, name, obj).getLength(),
is((long)obj.toString().length()));
+ }
+
+ @Test( expected = ValueFormatException.class )
+ public void shouldNotProvideLengths() throws Exception {
+ new JcrProperty(node, executionContext, name, "value").getLengths();
+ }
+
+ @Test
+ public void shouldProvideDepth() throws Exception {
+ Property prop = new JcrProperty(node, executionContext, name, true);
+ stub(node.getDepth()).toReturn(0);
+ assertThat(prop.getDepth(), is(1));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-26 21:10:10
UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRootNodeTest.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -52,7 +52,17 @@
root.setProperties(properties);
}
+ @Test( expected = ItemNotFoundException.class )
+ public void shouldNotAllowAncestorDepthGreaterThanNodeDepth() throws Exception {
+ root.getAncestor(1);
+ }
+
@Test
+ public void shouldHaveZeroDepth() {
+ assertThat(root.getDepth(), is(0));
+ }
+
+ @Test
public void shouldHaveEmptyName() {
String name = root.getName();
assertThat(name, notNullValue());
@@ -63,4 +73,9 @@
public void shouldHaveNoParent() throws Exception {
root.getParent();
}
+
+ @Test
+ public void shouldProvidePath() {
+ assertThat(root.getPath(), is("/"));
+ }
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-26 21:10:10
UTC (rev 473)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java 2008-08-26 21:12:04
UTC (rev 474)
@@ -32,6 +32,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.UUID;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
@@ -84,7 +85,7 @@
private Session session;
@Mock
- private Map<String, WeakReference<Node>> uuid2NodeMap;
+ private Map<UUID, WeakReference<Node>> nodesByUuid;
@Before
public void before() throws Exception {
@@ -101,22 +102,22 @@
@Test( expected = AssertionError.class )
public void shouldNotAllowNoRepository() throws Exception {
- new JcrSession(null, executionContext, WORKSPACE_NAME, connection,
uuid2NodeMap);
+ new JcrSession(null, executionContext, WORKSPACE_NAME, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoExecutionContext() throws Exception {
- new JcrSession(repository, null, WORKSPACE_NAME, connection, uuid2NodeMap);
+ new JcrSession(repository, null, WORKSPACE_NAME, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoWorkspaceName() throws Exception {
- new JcrSession(repository, executionContext, null, connection, uuid2NodeMap);
+ new JcrSession(repository, executionContext, null, connection, nodesByUuid);
}
@Test( expected = AssertionError.class )
public void shouldNotAllowNoConnection() throws Exception {
- new JcrSession(repository, executionContext, WORKSPACE_NAME, null,
uuid2NodeMap);
+ new JcrSession(repository, executionContext, WORKSPACE_NAME, null, nodesByUuid);
}
@Test( expected = AssertionError.class )
@@ -172,7 +173,7 @@
stub(executionContext.getSubject()).toReturn(subject);
stub(executionContext.getLoginContext()).toReturn(Mockito.mock(LoginContext.class));
Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
Mockito.mock(RepositoryConnection.class),
- uuid2NodeMap);
+ nodesByUuid);
try {
assertThat(session.getUserID(), is("name"));
} finally {
@@ -182,15 +183,15 @@
@Test
public void shouldProvideRootNode() throws Exception {
- Map<String, WeakReference<Node>> uuid2NodeMap = new
HashMap<String, WeakReference<Node>>();
+ Map<UUID, WeakReference<Node>> nodesByUuid = new HashMap<UUID,
WeakReference<Node>>();
Session session = new JcrSession(repository, executionContext, WORKSPACE_NAME,
-
connectionFactory.createConnection(WORKSPACE_NAME), uuid2NodeMap);
- assertThat(uuid2NodeMap.isEmpty(), is(true));
+
connectionFactory.createConnection(WORKSPACE_NAME), nodesByUuid);
+ assertThat(nodesByUuid.isEmpty(), is(true));
Node root = session.getRootNode();
assertThat(root, notNullValue());
- String uuid = root.getUUID();
+ UUID uuid = ((JcrRootNode)root).getInternalUuid();
assertThat(uuid, notNullValue());
- WeakReference<Node> ref = uuid2NodeMap.get(uuid);
+ WeakReference<Node> ref = nodesByUuid.get(uuid);
assertThat(ref, notNullValue());
assertThat(ref.get(), is(root));
}