Author: rhauch
Date: 2008-10-08 16:24:19 -0400 (Wed, 08 Oct 2008)
New Revision: 565
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CopyBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/DeleteBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Location.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/MoveBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadPropertyRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RenameNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RequestProcessor.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
Log:
DNA-213 - Review the graph SPI commands to add missing commands and better handle node
identification (e.g., when getting children)
http://jira.jboss.com/jira/browse/DNA-213
Minor changes to the code that was in the patch, and it's now committed to SVN. Added
a RequestProcessor abstract class.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2008-09-29 22:24:12
UTC (rev 564)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2008-10-08 20:24:19
UTC (rev 565)
@@ -64,6 +64,7 @@
public static I18n executedGraphCommand;
public static I18n closingCommandExecutor;
public static I18n closedCommandExecutor;
+ public static I18n multipleErrorsWhileExecutingRequests;
// XML Sequencer
public static I18n errorSequencingXmlDocument;
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,210 @@
+/*
+ * 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.graph.requests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ * A request that wraps multiple other requests.
+ *
+ * @author Randall Hauch
+ */
+public class CompositeRequest extends Request implements Iterable<Request> {
+
+ /**
+ * Return a request that either wraps multiple requests, or the single request if
only one is supplied.
+ *
+ * @param requests the requests to wrap
+ * @return the requests wrapped in a CompositeRequest, or if only one request is
supplied that single request
+ * @throws IllegalArgumentException if there requests are null, empty, or contains
only nulls
+ */
+ public static Request with( Request... requests ) {
+ CheckArg.isNotEmpty(requests, "requests");
+ if (requests.length == 1) {
+ CheckArg.isNotNull(requests[0], "requests[0]");
+ return requests[0];
+ }
+ List<Request> list = new ArrayList<Request>(requests.length);
+ for (Request request : requests) {
+ if (request == null) continue;
+ if (request instanceof CompositeRequest) {
+ CompositeRequest composite = (CompositeRequest)request;
+ list.addAll(composite.getRequests());
+ } else {
+ list.add(request);
+ }
+ }
+ CheckArg.isNotEmpty(list, "requests");
+ return new CompositeRequest(list);
+ }
+
+ /**
+ * Return a request that either wraps multiple requests, or the single request if
only one is supplied.
+ *
+ * @param requests the requests to wrap
+ * @return the requests wrapped in a CompositeRequest, or if only one request is
supplied that single request
+ * @throws IllegalArgumentException if there requests are null, empty, or contains
only nulls
+ */
+ public static Request with( Iterator<Request> requests ) {
+ CheckArg.isNotNull(requests, "requests");
+ List<Request> list = new LinkedList<Request>();
+ while (requests.hasNext()) {
+ Request request = requests.next();
+ if (request == null) continue;
+ if (request instanceof CompositeRequest) {
+ CompositeRequest composite = (CompositeRequest)request;
+ list.addAll(composite.getRequests());
+ } else {
+ list.add(request);
+ }
+ }
+ if (list.size() == 1) {
+ return list.get(0);
+ }
+ CheckArg.isNotEmpty(list, "requests");
+ return new CompositeRequest(list);
+ }
+
+ /**
+ * Add requests to the supplied composite request.
+ *
+ * @param composite the composite request to which the requests are to be added
+ * @param requests the requests to wrap
+ * @return the requests wrapped in a CompositeRequest, or if only one request is
supplied that single request, or null if
+ * there are no request
+ * @throws IllegalArgumentException if the composite request is null
+ */
+ public static CompositeRequest add( CompositeRequest composite,
+ Request... requests ) {
+ CheckArg.isNotNull(composite, "composite");
+ if (requests == null || requests.length == 0) return composite;
+ List<Request> list = new ArrayList<Request>(requests.length +
composite.size());
+ if (composite.size() != 0) list.addAll(composite.getRequests());
+ for (Request request : requests) {
+ if (request == null) continue;
+ if (request instanceof CompositeRequest) {
+ CompositeRequest compositeRequest = (CompositeRequest)request;
+ list.addAll(compositeRequest.getRequests());
+ } else {
+ list.add(request);
+ }
+ }
+ return new CompositeRequest(list);
+ }
+
+ /**
+ * Add requests to the supplied composite request.
+ *
+ * @param composite the composite request to which the requests are to be added
+ * @param requests the requests to wrap
+ * @return the requests wrapped in a CompositeRequest, or if only one request is
supplied that single request, or null if
+ * there are no request
+ * @throws IllegalArgumentException if the composite request is null
+ */
+ public static CompositeRequest add( CompositeRequest composite,
+ Iterator<Request> requests ) {
+ CheckArg.isNotNull(composite, "composite");
+ List<Request> list = new LinkedList<Request>();
+ if (composite.size() != 0) list.addAll(composite.getRequests());
+ while (requests.hasNext()) {
+ Request request = requests.next();
+ if (request == null) continue;
+ if (request instanceof CompositeRequest) {
+ CompositeRequest compositeRequest = (CompositeRequest)request;
+ list.addAll(compositeRequest.getRequests());
+ } else {
+ list.add(request);
+ }
+ }
+ return new CompositeRequest(list);
+ }
+
+ private final List<Request> requests;
+
+ /**
+ * Create a composite request from the supplied list of requests.
+ *
+ * @param requests the modifiable list of requests; may not be null
+ */
+ protected CompositeRequest( List<Request> requests ) {
+ this.requests = Collections.unmodifiableList(requests);
+ }
+
+ /**
+ * Return the unmodifiable requests contained in this composite request.
+ *
+ * @return requests
+ */
+ public List<Request> getRequests() {
+ return requests;
+ }
+
+ /**
+ * Get the number of requests.
+ *
+ * @return the number of requests
+ */
+ public int size() {
+ return requests.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Request> iterator() {
+ return requests.iterator();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj instanceof CompositeRequest) {
+ CompositeRequest that = (CompositeRequest)obj;
+ if (this.size() != that.size()) return false;
+ Iterator<Request> thisIter = this.iterator();
+ Iterator<Request> thatIter = that.iterator();
+ while (thisIter.hasNext()) {
+ Request thisRequest = thisIter.next();
+ Request thatRequest = thatIter.next();
+ if (thisRequest == null) {
+ if (thatRequest != null) return false;
+ } else {
+ if (!thisRequest.equals(thatRequest)) return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CopyBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CopyBranchRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CopyBranchRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,94 @@
+/*
+ * 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.graph.requests;
+
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ * Instruction that a branch be copied from one location into another.
+ *
+ * @author Randall Hauch
+ */
+public class CopyBranchRequest extends Request {
+
+ private final Location from;
+ private final Location into;
+
+ /**
+ * Create a request to copy a branch to another.
+ *
+ * @param from the location of the top node in the existing branch that is to be
copied
+ * @param into the location of the existing node into which the copy should be
placed
+ * @throws IllegalArgumentException if <code>from</code> or
<code>into</code> are null
+ */
+ public CopyBranchRequest( Location from,
+ Location into ) {
+ CheckArg.isNotNull(from, "from");
+ CheckArg.isNotNull(into, "into");
+ this.from = from;
+ this.into = into;
+ }
+
+ /**
+ * Get the location defining the top of the branch to be copied
+ *
+ * @return the from location; never null
+ */
+ public Location from() {
+ return from;
+ }
+
+ /**
+ * Get the location defining the parent where the new copy is to be placed
+ *
+ * @return the to location; never null
+ */
+ public Location into() {
+ return into;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ CopyBranchRequest that = (CopyBranchRequest)obj;
+ if (!this.from().equals(that.from())) return false;
+ if (!this.into().equals(that.into())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "copy branch " + from() + " into " + into();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CopyBranchRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,175 @@
+/*
+ * 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.graph.requests;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to create the node at the specified location. This command will create the
node and set the initial properties.
+ *
+ * @author Randall Hauch
+ */
+public class CreateNodeRequest extends Request implements Iterable<Property> {
+
+ private final Location at;
+ private final List<Property> properties;
+
+ /**
+ * Create a request to create a node with the given properties at the supplied
location.
+ *
+ * @param at the location of the node to be read
+ * @param properties the properties of the new node, which should not include the
location's
+ * {@link Location#getIdProperties() identification properties}
+ * @throws IllegalArgumentException if the location is null
+ */
+ public CreateNodeRequest( Location at,
+ Property... properties ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ int number = properties.length + (at.hasIdProperties() ?
at.getIdProperties().size() : 0);
+ List<Property> props = new ArrayList<Property>(number);
+ for (Property property : properties) {
+ if (property != null) props.add(property);
+ }
+ // Add in the location properties ...
+ if (at.hasIdProperties()) {
+ for (Property property : at.getIdProperties()) {
+ if (property != null) props.add(property);
+ }
+ }
+ this.properties = Collections.unmodifiableList(props);
+ }
+
+ /**
+ * Create a request to create a node with the given properties at the supplied
location.
+ *
+ * @param at the location of the node to be read
+ * @param properties the properties of the new node, which should not include the
location's
+ * {@link Location#getIdProperties() identification properties}
+ * @throws IllegalArgumentException if the location is null
+ */
+ public CreateNodeRequest( Location at,
+ Iterable<Property> properties ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ List<Property> props = new LinkedList<Property>();
+ for (Property property : properties) {
+ if (property != null) props.add(property);
+ }
+ // Add in the location properties ...
+ if (at.hasIdProperties()) {
+ for (Property property : at.getIdProperties()) {
+ if (property != null) props.add(property);
+ }
+ }
+ this.properties = Collections.unmodifiableList(props);
+ }
+
+ /**
+ * Create a request to create a node with the given properties at the supplied
location.
+ *
+ * @param at the location of the node to be read
+ * @param properties the properties of the new node, which should not include the
location's
+ * {@link Location#getIdProperties() identification properties}
+ * @throws IllegalArgumentException if the location is null
+ */
+ public CreateNodeRequest( Location at,
+ Iterator<Property> properties ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ List<Property> props = new LinkedList<Property>();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ if (property != null) props.add(property);
+ }
+ // Add in the location properties ...
+ if (at.hasIdProperties()) {
+ for (Property property : at.getIdProperties()) {
+ if (property != null) props.add(property);
+ }
+ }
+ this.properties = Collections.unmodifiableList(props);
+ }
+
+ /**
+ * Get the location defining the node that is to be created.
+ *
+ * @return the location of the node; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Property> iterator() {
+ return this.properties.iterator();
+ }
+
+ /**
+ * Get the properties for the node. If the node's {@link #at() location} has
identification properties, the resulting
+ * properties will include the {@link Location#getIdProperties() identification
properties}.
+ *
+ * @return the collection of properties; never null
+ */
+ public Collection<Property> properties() {
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ CreateNodeRequest that = (CreateNodeRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ if (!this.properties().equals(that.properties())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "create node at " + at() + " with properties " +
StringUtil.readableString(properties());
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CreateNodeRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/DeleteBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/DeleteBranchRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/DeleteBranchRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -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.graph.requests;
+
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ * Instruction that a branch be deleted.
+ *
+ * @author Randall Hauch
+ */
+public class DeleteBranchRequest extends Request {
+
+ private final Location at;
+
+ /**
+ * Create a request to delete a branch.
+ *
+ * @param at the location of the top node in the existing branch that is to be
deleted
+ * @throws IllegalArgumentException if the location is null
+ */
+ public DeleteBranchRequest( Location at ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ }
+
+ /**
+ * Get the location defining the top of the branch to be deleted
+ *
+ * @return the location of the branch; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ DeleteBranchRequest that = (DeleteBranchRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "delete branch " + at();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/DeleteBranchRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Location.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Location.java
(rev 0)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Location.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,276 @@
+/*
+ * 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.graph.requests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.DnaLexicon;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+import org.jboss.dna.graph.properties.basic.BasicSingleValueProperty;
+
+/**
+ * The location of a node, as specified by either its path, UUID, and/or identification
properties.
+ *
+ * @author Randall Hauch
+ */
+@Immutable
+public class Location {
+
+ private final Path path;
+ private final List<Property> idProperties;
+
+ /**
+ * Create a location defined by a path.
+ *
+ * @param path the path
+ * @throws IllegalArgumentException if <code>path</code> is null
+ */
+ public Location( Path path ) {
+ CheckArg.isNotNull(path, "path");
+ this.path = path;
+ this.idProperties = null;
+ }
+
+ /**
+ * Create a location defined by a UUID.
+ *
+ * @param uuid the UUID
+ * @throws IllegalArgumentException if <code>uuid</code> is null
+ */
+ public Location( UUID uuid ) {
+ CheckArg.isNotNull(uuid, "uuid");
+ this.path = null;
+ Property idProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
+ this.idProperties = Collections.singletonList(idProperty);
+ }
+
+ /**
+ * Create a location defined by a path and an UUID.
+ *
+ * @param path the path
+ * @param uuid the UUID
+ * @throws IllegalArgumentException if <code>uuid</code> is null
+ */
+ public Location( Path path,
+ UUID uuid ) {
+ CheckArg.isNotNull(uuid, "uuid");
+ CheckArg.isNotNull(path, "path");
+ this.path = path;
+ Property idProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
+ this.idProperties = Collections.singletonList(idProperty);
+ }
+
+ /**
+ * Create a location defined by a path and a single identification property.
+ *
+ * @param path the path
+ * @param idProperty the identification property
+ * @throws IllegalArgumentException if <code>path</code> or
<code>idProperty</code> is null
+ */
+ public Location( Path path,
+ Property idProperty ) {
+ CheckArg.isNotNull(path, "path");
+ CheckArg.isNotNull(idProperty, "idProperty");
+ this.path = path;
+ this.idProperties = Collections.singletonList(idProperty);
+ }
+
+ /**
+ * Create a location defined by a path and multiple identification properties.
+ *
+ * @param path the path
+ * @param firstIdProperty the first identification property
+ * @param remainingIdProperties the remaining identification property
+ * @throws IllegalArgumentException if any of the arguments are null
+ */
+ public Location( Path path,
+ Property firstIdProperty,
+ Property... remainingIdProperties ) {
+ CheckArg.isNotNull(path, "path");
+ CheckArg.isNotNull(firstIdProperty, "firstIdProperty");
+ CheckArg.isNotNull(remainingIdProperties, "remainingIdProperties");
+ this.path = path;
+ List<Property> idProperties = new ArrayList<Property>(1 +
remainingIdProperties.length);
+ idProperties.add(firstIdProperty);
+ for (Property property : remainingIdProperties) {
+ idProperties.add(property);
+ }
+ this.idProperties = Collections.unmodifiableList(idProperties);
+ }
+
+ /**
+ * Create a location defined by a single identification property.
+ *
+ * @param idProperty the identification property
+ * @throws IllegalArgumentException if <code>idProperty</code> is null
+ */
+ public Location( Property idProperty ) {
+ CheckArg.isNotNull(idProperty, "idProperty");
+ this.path = null;
+ this.idProperties = Collections.singletonList(idProperty);
+ }
+
+ /**
+ * Create a location defined by multiple identification properties.
+ *
+ * @param firstIdProperty the first identification property
+ * @param remainingIdProperties the remaining identification property
+ * @throws IllegalArgumentException if any of the arguments are null
+ */
+ public Location( Property firstIdProperty,
+ Property... remainingIdProperties ) {
+ CheckArg.isNotNull(firstIdProperty, "firstIdProperty");
+ CheckArg.isNotNull(remainingIdProperties, "remainingIdProperties");
+ this.path = null;
+ List<Property> idProperties = new ArrayList<Property>(1 +
remainingIdProperties.length);
+ idProperties.add(firstIdProperty);
+ for (Property property : remainingIdProperties) {
+ idProperties.add(property);
+ }
+ this.idProperties = Collections.unmodifiableList(idProperties);
+ }
+
+ /**
+ * Create a location defined by multiple identification properties.
+ *
+ * @param idProperties the identification properties
+ * @throws IllegalArgumentException if <code>idProperties</code> is null
or empty
+ */
+ public Location( List<Property> idProperties ) {
+ CheckArg.isNotEmpty(idProperties, "idProperties");
+ this.path = null;
+ this.idProperties = idProperties;
+ }
+
+ /**
+ * Create a location defined by a path and multiple identification properties.
+ *
+ * @param path the path
+ * @param idProperties the identification properties
+ * @throws IllegalArgumentException if <code>path</code> or
<code>idProperties</code> is null, or if
<code>idProperties</code>
+ * is empty
+ */
+ public Location( Path path,
+ List<Property> idProperties ) {
+ CheckArg.isNotNull(path, "path");
+ CheckArg.isNotEmpty(idProperties, "idProperties");
+ this.path = path;
+ this.idProperties = idProperties;
+ }
+
+ /**
+ * Get the path that (at least in part) defines this location.
+ *
+ * @return the path, or null if this location is not defined with a path
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * Return whether this location is defined (at least in part) by a path.
+ *
+ * @return true if a {@link #getPath() path} helps define this location
+ */
+ public boolean hasPath() {
+ return path != null;
+ }
+
+ /**
+ * Get the identification properties that (at least in part) define this location.
+ *
+ * @return the identification properties, or null if this location is not defined
with identification properties
+ */
+ public List<Property> getIdProperties() {
+ return idProperties;
+ }
+
+ /**
+ * Return whether this location is defined (at least in part) with identification
properties.
+ *
+ * @return true if a {@link #getIdProperties() identification properties} help define
this location
+ */
+ public boolean hasIdProperties() {
+ return idProperties != null && idProperties.size() != 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return HashCode.compute(path, idProperties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj instanceof Location) {
+ Location that = (Location)obj;
+ if (this.hasPath()) {
+ if (!this.getPath().equals(that.getPath())) return false;
+ } else {
+ if (that.hasPath()) return false;
+ }
+ if (this.hasIdProperties()) {
+ if (!this.getIdProperties().equals(that.getIdProperties())) return
false;
+ } else {
+ if (that.hasIdProperties()) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if (this.hasPath()) {
+ if (this.hasIdProperties()) sb.append("[ ");
+ sb.append(this.getPath());
+ if (this.hasIdProperties()) sb.append(" && ");
+ }
+ if (this.hasIdProperties()) {
+ sb.append(StringUtil.readableString(this.getIdProperties()));
+ if (this.hasPath()) sb.append(" ]");
+ }
+ return sb.toString();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Location.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/MoveBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/MoveBranchRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/MoveBranchRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,94 @@
+/*
+ * 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.graph.requests;
+
+import org.jboss.dna.common.util.CheckArg;
+
+/**
+ * Instruction that a branch be moved from one location into another.
+ *
+ * @author Randall Hauch
+ */
+public class MoveBranchRequest extends Request {
+
+ private final Location from;
+ private final Location into;
+
+ /**
+ * Create a request to move a branch from one location into another.
+ *
+ * @param from the location of the top node in the existing branch that is to be
moved
+ * @param into the location of the existing node into which the branch should be
moved
+ * @throws IllegalArgumentException if <code>from</code> or
<code>into</code> are null
+ */
+ public MoveBranchRequest( Location from,
+ Location into ) {
+ CheckArg.isNotNull(from, "from");
+ CheckArg.isNotNull(into, "into");
+ this.from = from;
+ this.into = into;
+ }
+
+ /**
+ * Get the location defining the top of the branch to be moved
+ *
+ * @return the from location; never null
+ */
+ public Location from() {
+ return from;
+ }
+
+ /**
+ * Get the location defining the parent where the branch is to be placed
+ *
+ * @return the to location; never null
+ */
+ public Location into() {
+ return into;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ MoveBranchRequest that = (MoveBranchRequest)obj;
+ if (!this.from().equals(that.from())) return false;
+ if (!this.into().equals(that.into())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "move branch " + from() + " into " + into();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/MoveBranchRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllChildrenRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllChildrenRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllChildrenRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,154 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read all of the children of a node at a specific location.
+ *
+ * @author Randall Hauch
+ */
+public class ReadAllChildrenRequest extends Request implements Iterable<Location>
{
+
+ private final Location of;
+ private final List<Location> children = new LinkedList<Location>();
+
+ /**
+ * Create a request to read the children of a node at the supplied location.
+ *
+ * @param of the location of the node whose children are to be read
+ * @throws IllegalArgumentException if the location is null
+ */
+ public ReadAllChildrenRequest( Location of ) {
+ CheckArg.isNotNull(of, "of");
+ this.of = of;
+ }
+
+ /**
+ * Get the location defining the node whose children are to be read.
+ *
+ * @return the location of the parent node; never null
+ */
+ public Location of() {
+ return of;
+ }
+
+ /**
+ * Get the children that were read from the {@link RepositoryConnection} after the
request was processed. Each child is
+ * represented by a location.
+ *
+ * @return the children that were read; never null
+ */
+ public List<Location> getChildren() {
+ return children;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Location> iterator() {
+ return children.iterator();
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param child the location of the child that was read
+ * @throws IllegalArgumentException if the location is null
+ * @see #addChild(Path, Property)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Location child ) {
+ CheckArg.isNotNull(child, "child");
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param firstIdProperty the first identification property of the child that was
just read
+ * @param remainingIdProperties the remaining identification properties of the child
that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property)
+ */
+ public void addChild( Path pathToChild,
+ Property firstIdProperty,
+ Property... remainingIdProperties ) {
+ Location child = new Location(pathToChild, firstIdProperty,
remainingIdProperties);
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification property. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param idProperty the identification property of the child that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Path pathToChild,
+ Property idProperty ) {
+ Location child = new Location(pathToChild, idProperty);
+ this.children.add(child);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadAllChildrenRequest that = (ReadAllChildrenRequest)obj;
+ if (!this.of().equals(that.of())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "read children of " + of();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllChildrenRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,162 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read the properties and the number of children of the node at the
specifed location.
+ *
+ * @author Randall Hauch
+ */
+public class ReadAllPropertiesRequest extends Request implements Iterable<Property>
{
+
+ public static final int UNKNOWN_NUMBER_OF_CHILDREN = -1;
+
+ private final Location at;
+ private final Map<Name, Property> properties = new HashMap<Name,
Property>();
+ private int numberOfChildren = UNKNOWN_NUMBER_OF_CHILDREN;
+
+ /**
+ * Create a request to read the properties and number of children of a node at the
supplied location.
+ *
+ * @param at the location of the node to be read
+ * @throws IllegalArgumentException if the location is null
+ */
+ public ReadAllPropertiesRequest( Location at ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ }
+
+ /**
+ * Get the location defining the node that is to be read.
+ *
+ * @return the location of the node; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * Get the properties that were read from the {@link RepositoryConnection}.
+ *
+ * @return the properties, as a map of property name to property; never null
+ */
+ public Map<Name, Property> getPropertiesByName() {
+ return properties;
+ }
+
+ /**
+ * Get the properties that were read from the {@link RepositoryConnection}.
+ *
+ * @return the collection of properties; never null
+ */
+ public Collection<Property> getProperties() {
+ return properties.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Property> iterator() {
+ return getProperties().iterator();
+ }
+
+ /**
+ * Add a property that was read from the {@link RepositoryConnection}
+ *
+ * @param property the property that was read
+ * @return the previous property that had the same name, or null if there was no
previously-recorded property with the same
+ * name
+ * @throws IllegalArgumentException if the property is null
+ */
+ public Property addProperty( Property property ) {
+ return this.properties.put(property.getName(), property);
+ }
+
+ /**
+ * Add a property that was read from the {@link RepositoryConnection}
+ *
+ * @param properties the properties that were read
+ * @throws IllegalArgumentException if the property is null
+ */
+ public void addProperties( Property... properties ) {
+ for (Property property : properties) {
+ this.properties.put(property.getName(), property);
+ }
+ }
+
+ /**
+ * Get the number of children for this node.
+ *
+ * @return the number of children, or {@link #UNKNOWN_NUMBER_OF_CHILDREN} if the
number of children was not yet read
+ */
+ public int getNumberOfChildren() {
+ return numberOfChildren;
+ }
+
+ /**
+ * Set the number of children for this node
+ *
+ * @param numberOfChildren the number of children
+ * @throws IllegalArgumentException if the number of childre is negative
+ */
+ public void setNumberOfChildren( int numberOfChildren ) {
+ CheckArg.isNonNegative(numberOfChildren, "numberOfChildren");
+ this.numberOfChildren = numberOfChildren;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadAllPropertiesRequest that = (ReadAllPropertiesRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "read properties of " + at();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,204 @@
+/*
+ * 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.graph.requests;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.common.text.Inflector;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read a block of the children of a node, where the block is dictated by
the {@link #startingAt() starting index}
+ * and the {@link #count() maximum number of children} to include in the block. This
command is useful when paging through a large
+ * number of children.
+ *
+ * @author Randall Hauch
+ */
+public class ReadBlockOfChildrenRequest extends Request {
+
+ private final Location of;
+ private final List<Location> children = new LinkedList<Location>();
+ private final int startingAt;
+ private final int count;
+
+ /**
+ * Create a request to read a block of the children of a node at the supplied
location. The block is defined by the starting
+ * index of the first child and the number of children to include. Note that this
index is <i>not</i> the
+ * {@link Path.Segment#getIndex() same-name-sibiling index}, but rather is the index
of the child as if the children were in
+ * an array.
+ *
+ * @param of the location of the node whose children are to be read
+ * @param startingIndex the index of the first child to be included in the block
+ * @param count the maximum number of children that should be included in the block
+ * @throws IllegalArgumentException if the location is null, if
<code>startingIndex</code> is negative, or if
+ * <code>count</count> is less than 1.
+ */
+ public ReadBlockOfChildrenRequest( Location of,
+ int startingIndex,
+ int count ) {
+ CheckArg.isNotNull(of, "of");
+ CheckArg.isNonNegative(startingIndex, "startingIndex");
+ CheckArg.isPositive(count, "count");
+ this.of = of;
+ this.startingAt = startingIndex;
+ this.count = count;
+ }
+
+ /**
+ * Get the location defining the node whose children are to be read.
+ *
+ * @return the location of the parent node; never null
+ */
+ public Location of() {
+ return of;
+ }
+
+ /**
+ * Get the maximum number of children that may be returned in the block.
+ *
+ * @return the block's maximum count
+ * @see #startingAt()
+ * @see #endingBefore()
+ */
+ public int count() {
+ return this.count;
+ }
+
+ /**
+ * Get the starting index of the block, which is the index of the first child to
include. This index corresponds to the index
+ * of all children in the list, not the {@link Path.Segment#getIndex()
same-name-sibiling index}.
+ *
+ * @return the child index at which this block starts; never negative and always less
than {@link #endingBefore()}
+ * @see #endingBefore()
+ * @see #count()
+ */
+ public int startingAt() {
+ return this.startingAt;
+ }
+
+ /**
+ * Get the index past the last child that is to be included in the block. This index
corresponds to the index of all children
+ * in the list, not the {@link Path.Segment#getIndex() same-name-sibiling index}.
+ *
+ * @return the index just past the last child included in the block; always positive
and always greater than
+ * {@link #startingAt()}.
+ * @see #startingAt()
+ * @see #count()
+ */
+ public int endingBefore() {
+ return this.startingAt + this.count;
+ }
+
+ /**
+ * Get the children that were read from the {@link RepositoryConnection} after the
request was processed. Each child is
+ * represented by a location.
+ *
+ * @return the children that were read; never null
+ */
+ public List<Location> getChildren() {
+ return children;
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param child the location of the child that was read
+ * @throws IllegalArgumentException if the location is null
+ * @see #addChild(Path, Property)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Location child ) {
+ CheckArg.isNotNull(child, "child");
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param firstIdProperty the first identification property of the child that was
just read
+ * @param remainingIdProperties the remaining identification properties of the child
that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property)
+ */
+ public void addChild( Path pathToChild,
+ Property firstIdProperty,
+ Property... remainingIdProperties ) {
+ Location child = new Location(pathToChild, firstIdProperty,
remainingIdProperties);
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification property. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param idProperty the identification property of the child that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Path pathToChild,
+ Property idProperty ) {
+ Location child = new Location(pathToChild, idProperty);
+ this.children.add(child);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadBlockOfChildrenRequest that = (ReadBlockOfChildrenRequest)obj;
+ if (!this.of().equals(that.of())) return false;
+ if (this.startingAt() != that.startingAt()) return false;
+ if (this.count() != that.count()) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ Inflector inflector = Inflector.getInstance();
+ if (count() == 1) {
+ return "read " + inflector.ordinalize(startingAt()) + " thru
" + inflector.ordinalize(endingBefore() - 1)
+ + " children of " + of();
+ }
+ return "read " + inflector.ordinalize(startingAt()) + " child of
" + of();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBranchRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBranchRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,254 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import net.jcip.annotations.NotThreadSafe;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read the properties and children of the nodes in the branch at the
supplied location. The children of the nodes at
+ * the bottom of the branch are not read.
+ *
+ * @author Randall Hauch
+ */
+@NotThreadSafe
+public class ReadBranchRequest extends Request implements Iterable<Location> {
+
+ public static final int DEFAULT_MAXIMUM_DEPTH = 2;
+
+ private final Location at;
+ private final int maxDepth;
+ private final Map<Location, Map<Name, Property>> nodeProperties = new
HashMap<Location, Map<Name, Property>>();
+ private final Map<Location, List<Location>> children = new
HashMap<Location, List<Location>>();
+
+ /**
+ * Create a request to read the branch at the supplied location, to a maximum depth
of 2.
+ *
+ * @param at the location of the branch
+ * @throws IllegalArgumentException if the location is null
+ */
+ public ReadBranchRequest( Location at ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ this.maxDepth = DEFAULT_MAXIMUM_DEPTH;
+ }
+
+ /**
+ * Create a request to read the branch (of given depth) at the supplied location.
+ *
+ * @param at the location of the branch
+ * @param maxDepth the maximum depth to read
+ * @throws IllegalArgumentException if the location is null or if the maximum depth
is not positive
+ */
+ public ReadBranchRequest( Location at,
+ int maxDepth ) {
+ CheckArg.isNotNull(at, "at");
+ CheckArg.isPositive(maxDepth, "maxDepth");
+ this.at = at;
+ this.maxDepth = maxDepth;
+ }
+
+ /**
+ * Get the location defining the top of the branch to be deleted
+ *
+ * @return the location of the branch; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * Get the maximum depth of the branch that is to be read.
+ *
+ * @return the maximum depth; always positive
+ */
+ public int maximumDepth() {
+ return maxDepth;
+ }
+
+ /**
+ * Add a node that was read from the {@link RepositoryConnection}. This method does
not verify or check that the node is
+ * indeed on the branch and that it is at a level prescribed by the request.
+ *
+ * @param node the location of the node that appears on this branch.
+ * @param properties the properties on the node
+ * @throws IllegalArgumentException if the node is null
+ */
+ public void setProperties( Location node,
+ Property... properties ) {
+ CheckArg.isNotNull(node, "node");
+ Map<Name, Property> propertiesMap = nodeProperties.get(node);
+ if (propertiesMap == null) {
+ propertiesMap = new HashMap<Name, Property>();
+ nodeProperties.put(node, propertiesMap);
+ }
+ for (Property property : properties) {
+ propertiesMap.put(property.getName(), property);
+ }
+ }
+
+ /**
+ * Add a node that was read from the {@link RepositoryConnection}. This method does
not verify or check that the node is
+ * indeed on the branch and that it is at a level prescribed by the request.
+ *
+ * @param node the location of the node that appears on this branch.
+ * @param properties the properties on the node
+ * @throws IllegalArgumentException if the node is null
+ */
+ public void setProperties( Location node,
+ Iterable<Property> properties ) {
+ CheckArg.isNotNull(node, "node");
+ Map<Name, Property> propertiesMap = nodeProperties.get(node);
+ if (propertiesMap == null) {
+ propertiesMap = new HashMap<Name, Property>();
+ nodeProperties.put(node, propertiesMap);
+ }
+ for (Property property : properties) {
+ propertiesMap.put(property.getName(), property);
+ }
+ }
+
+ /**
+ * Record the children for a parent node in the branch.
+ *
+ * @param parent the location of the parent
+ * @param children the location of each child, in the order they appear in the
parent
+ */
+ public void setChildren( Location parent,
+ Location... children ) {
+ CheckArg.isNotNull(parent, "parent");
+ CheckArg.isNotNull(children, "children");
+ this.children.put(parent, Arrays.asList(children));
+ }
+
+ /**
+ * Record the children for a parent node in the branch.
+ *
+ * @param parent the location of the parent
+ * @param children the location of each child, in the order they appear in the
parent
+ */
+ public void setChildren( Location parent,
+ List<Location> children ) {
+ CheckArg.isNotNull(parent, "parent");
+ CheckArg.isNotNull(children, "children");
+ this.children.put(parent, children);
+ }
+
+ /**
+ * Get the nodes that make up this branch. If this map is empty, the branch has not
yet been read. The resulting map maintains
+ * the order that the nodes were {@link #setProperties(Location, Property...)
added}.
+ *
+ * @return the branch information
+ * @see #iterator()
+ */
+ public Map<Location, Map<Name, Property>> getPropertiesByNode() {
+ return nodeProperties;
+ }
+
+ /**
+ * Get the nodes that make up this branch. If this map is empty, the branch has not
yet been read. The resulting map maintains
+ * the order that the nodes were {@link #setProperties(Location, Property...)
added}.
+ *
+ * @param location the location of the node for which the properties are to be
obtained
+ * @return the properties for the location, as a map keyed by the property name
+ * @see #iterator()
+ */
+ public Map<Name, Property> getPropertiesFor( Location location ) {
+ return nodeProperties.get(location);
+ }
+
+ /**
+ * Get the children of the node at the supplied location.
+ *
+ * @param parent the location of the parent
+ * @return the children, or null if there are no children (or if the parent has not
been read)
+ */
+ public List<Location> getChildren( Location parent ) {
+ CheckArg.isNotNull(parent, "parent");
+ return this.children.get(parent);
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * The resulting iterator accesses the {@link Location} objects in the branch, in
pre-order traversal order.
+ * </p>
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Location> iterator() {
+ final LinkedList<Location> queue = new LinkedList<Location>();
+ queue.addFirst(at());
+ return new Iterator<Location>() {
+ public boolean hasNext() {
+ return queue.peek() != null;
+ }
+
+ public Location next() {
+ // Add the children of the next node to the queue ...
+ Location next = queue.poll();
+ List<Location> children = getChildren(next);
+ if (children != null && children.size() > 0) queue.addAll(0,
children);
+ return next;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadBranchRequest that = (ReadBranchRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ if (this.maximumDepth() != that.maximumDepth()) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "read branch " + at() + " to depth " +
maximumDepth();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadBranchRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadNodeRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadNodeRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,201 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read the properties and children of the node at the specifed location.
+ *
+ * @author Randall Hauch
+ */
+public class ReadNodeRequest extends Request implements Iterable<Location> {
+
+ private final Location at;
+ private final Map<Name, Property> properties = new HashMap<Name,
Property>();
+ private final List<Location> children = new LinkedList<Location>();
+
+ /**
+ * Create a request to read the properties and number of children of a node at the
supplied location.
+ *
+ * @param at the location of the node to be read
+ * @throws IllegalArgumentException if the location is null
+ */
+ public ReadNodeRequest( Location at ) {
+ CheckArg.isNotNull(at, "at");
+ this.at = at;
+ }
+
+ /**
+ * Get the location defining the node that is to be read.
+ *
+ * @return the location of the node; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * Get the properties that were read from the {@link RepositoryConnection}.
+ *
+ * @return the properties, as a map of property name to property; never null
+ */
+ public Map<Name, Property> getPropertiesByName() {
+ return properties;
+ }
+
+ /**
+ * Get the properties that were read from the {@link RepositoryConnection}.
+ *
+ * @return the collection of properties; never null
+ */
+ public Collection<Property> getProperties() {
+ return properties.values();
+ }
+
+ /**
+ * Add a property that was read from the {@link RepositoryConnection}
+ *
+ * @param property the property that was read
+ * @return the previous property that had the same name, or null if there was no
previously-recorded property with the same
+ * name
+ * @throws IllegalArgumentException if the property is null
+ */
+ public Property addProperty( Property property ) {
+ return this.properties.put(property.getName(), property);
+ }
+
+ /**
+ * Add a property that was read from the {@link RepositoryConnection}
+ *
+ * @param properties the properties that were read
+ * @throws IllegalArgumentException if the property is null
+ */
+ public void addProperties( Property... properties ) {
+ for (Property property : properties) {
+ this.properties.put(property.getName(), property);
+ }
+ }
+
+ /**
+ * Get the children that were read from the {@link RepositoryConnection} after the
request was processed. Each child is
+ * represented by a location.
+ *
+ * @return the children that were read; never null
+ */
+ public List<Location> getChildren() {
+ return children;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Location> iterator() {
+ return children.iterator();
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param child the location of the child that was read
+ * @throws IllegalArgumentException if the location is null
+ * @see #addChild(Path, Property)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Location child ) {
+ CheckArg.isNotNull(child, "child");
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification properties. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param firstIdProperty the first identification property of the child that was
just read
+ * @param remainingIdProperties the remaining identification properties of the child
that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property)
+ */
+ public void addChild( Path pathToChild,
+ Property firstIdProperty,
+ Property... remainingIdProperties ) {
+ Location child = new Location(pathToChild, firstIdProperty,
remainingIdProperties);
+ this.children.add(child);
+ }
+
+ /**
+ * Add to the list of children that has been read the child with the given path and
identification property. The children
+ * should be added in order.
+ *
+ * @param pathToChild the path of the child that was just read
+ * @param idProperty the identification property of the child that was just read
+ * @throws IllegalArgumentException if the path or identification properties are
null
+ * @see #addChild(Location)
+ * @see #addChild(Path, Property, Property...)
+ */
+ public void addChild( Path pathToChild,
+ Property idProperty ) {
+ Location child = new Location(pathToChild, idProperty);
+ this.children.add(child);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadNodeRequest that = (ReadNodeRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "read node at " + at();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadNodeRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadPropertyRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadPropertyRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadPropertyRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,120 @@
+/*
+ * 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.graph.requests;
+
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to read a single property on the node at the specified location.
+ *
+ * @author Randall Hauch
+ */
+public class ReadPropertyRequest extends Request {
+
+ private final Location on;
+ private final Name propertyName;
+ private Property property;
+
+ /**
+ * Create a request to read the properties and number of children of a node at the
supplied location.
+ *
+ * @param on the location of the node to be read
+ * @param propertyName the name of the property to read
+ * @throws IllegalArgumentException if the location or property name are null
+ */
+ public ReadPropertyRequest( Location on,
+ Name propertyName ) {
+ CheckArg.isNotNull(on, "on");
+ CheckArg.isNotNull(propertyName, "propertyName");
+ this.on = on;
+ this.propertyName = propertyName;
+ }
+
+ /**
+ * Get the location defining the node that is to be read.
+ *
+ * @return the location of the node; never null
+ */
+ public Location on() {
+ return on;
+ }
+
+ /**
+ * Get the name of the property that is to be read
+ *
+ * @return the property name; never null
+ */
+ public Name named() {
+ return propertyName;
+ }
+
+ /**
+ * Get the property that was read.
+ *
+ * @return the property, or null if the property was not read or did not exist on the
node
+ */
+ public Property getProperty() {
+ return property;
+ }
+
+ /**
+ * Set the property on the node as read from the {@link RepositoryConnection}
+ *
+ * @param property the property that was read
+ * @throws IllegalArgumentException if the property's name does not match the
{@link #named() name of the property} that was
+ * to be read
+ */
+ public void setProperty( Property property ) {
+ if (property != null) CheckArg.isEquals(property.getName(), "property's
name", named(), "property name");
+ this.property = property;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ ReadPropertyRequest that = (ReadPropertyRequest)obj;
+ if (!this.on().equals(that.on())) return false;
+ if (!this.named().equals(that.named())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "read " + named() + " property at " + on();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/ReadPropertyRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,154 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.properties.Name;
+
+/**
+ * Instruction to remove properties from the node at the specified location.
+ *
+ * @author Randall Hauch
+ */
+public class RemovePropertiesRequest extends Request implements Iterable<Name> {
+
+ private final Location from;
+ private final Set<Name> propertyNames;
+
+ /**
+ * Create a request to remove the properties with the given names from the node at
the supplied location.
+ *
+ * @param from the location of the node to be read
+ * @param propertyNames the names of the properties to be removed from the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to remove
+ */
+ public RemovePropertiesRequest( Location from,
+ Name... propertyNames ) {
+ CheckArg.isNotNull(from, "from");
+ CheckArg.isNotEmpty(propertyNames, "propertyNames");
+ this.from = from;
+ Set<Name> names = new HashSet<Name>();
+ for (Name name : propertyNames) {
+ if (name != null) names.add(name);
+ }
+ this.propertyNames = Collections.unmodifiableSet(names);
+ }
+
+ /**
+ * Create a request to remove the properties with the given names from the node at
the supplied location.
+ *
+ * @param from the location of the node to be read
+ * @param propertyNames the names of the properties to be removed from the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to remove
+ */
+ public RemovePropertiesRequest( Location from,
+ Iterable<Name> propertyNames ) {
+ CheckArg.isNotNull(from, "from");
+ this.from = from;
+ Set<Name> names = new HashSet<Name>();
+ for (Name name : propertyNames) {
+ if (name != null) names.add(name);
+ }
+ this.propertyNames = Collections.unmodifiableSet(names);
+ CheckArg.isNotEmpty(this.propertyNames, "propertyNames");
+ }
+
+ /**
+ * Create a request to remove the properties with the given names from the node at
the supplied location.
+ *
+ * @param from the location of the node to be read
+ * @param propertyNames the names of the properties to be removed from the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to remove
+ */
+ public RemovePropertiesRequest( Location from,
+ Iterator<Name> propertyNames ) {
+ CheckArg.isNotNull(from, "from");
+ this.from = from;
+ Set<Name> names = new HashSet<Name>();
+ while (propertyNames.hasNext()) {
+ Name name = propertyNames.next();
+ if (name != null) names.add(name);
+ }
+ this.propertyNames = Collections.unmodifiableSet(names);
+ CheckArg.isNotEmpty(this.propertyNames, "propertyNames");
+ }
+
+ /**
+ * Get the location defining the node from which the properties are to be removed.
+ *
+ * @return the location of the node; never null
+ */
+ public Location from() {
+ return from;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Name> iterator() {
+ return this.propertyNames.iterator();
+ }
+
+ /**
+ * Get the names of the properties that are to be removed from the node.
+ *
+ * @return the collection of property names; never null and never empty
+ */
+ public Collection<Name> propertyNames() {
+ return propertyNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ RemovePropertiesRequest that = (RemovePropertiesRequest)obj;
+ if (!this.from().equals(that.from())) return false;
+ if (!this.propertyNames().equals(that.propertyNames())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "remove from " + from() + " properties named " +
StringUtil.readableString(propertyNames());
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RenameNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RenameNodeRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RenameNodeRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,97 @@
+/*
+ * 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.graph.requests;
+
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.properties.Name;
+
+/**
+ * Instruction to rename an existing node (but keep it under the same parent). The
same-name-sibling index will be determined
+ * automatically, based upon it's current location within the list of children.
+ *
+ * @author Randall Hauch
+ */
+public class RenameNodeRequest extends Request {
+
+ private final Location at;
+ private final Name newName;
+
+ /**
+ * Create a request to rename the node at the supplied location.
+ *
+ * @param at the location of the node to be read
+ * @param newName the new name for the node
+ * @throws IllegalArgumentException if the location is null
+ */
+ public RenameNodeRequest( Location at,
+ Name newName ) {
+ CheckArg.isNotNull(at, "at");
+ CheckArg.isNotNull(newName, "newName");
+ this.at = at;
+ this.newName = newName;
+ }
+
+ /**
+ * Get the location defining the node that is to be read.
+ *
+ * @return the location of the node; never null
+ */
+ public Location at() {
+ return at;
+ }
+
+ /**
+ * Get the new name for the node.
+ *
+ * @return the new name; never null
+ */
+ public Name toName() {
+ return newName;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ RenameNodeRequest that = (RenameNodeRequest)obj;
+ if (!this.at().equals(that.at())) return false;
+ if (!this.toName().equals(that.toName())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "rename node at " + at() + " to " + toName();
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RenameNodeRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java
(rev 0)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,62 @@
+/*
+ * 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.graph.requests;
+
+import org.jboss.dna.graph.connectors.RepositoryConnection;
+
+/**
+ * The abstract base class for all classes representing requests to be executed against a
{@link RepositoryConnection}.
+ *
+ * @author Randall Hauch
+ */
+public abstract class Request {
+
+ private Throwable error;
+
+ /**
+ * Set the error for this request.
+ *
+ * @param error the error to be associated with this request, or null if this request
is to have no error
+ */
+ public void setError( Throwable error ) {
+ this.error = error;
+ }
+
+ /**
+ * Return whether there is an error associated with this request
+ *
+ * @return true if there is an error, or false otherwise
+ */
+ public boolean hasError() {
+ return this.error != null;
+ }
+
+ /**
+ * Get the error associated with this request, if there is such an error.
+ *
+ * @return the error, or null if there is none
+ */
+ public Throwable getError() {
+ return error;
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RequestProcessor.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RequestProcessor.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RequestProcessor.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,414 @@
+/*
+ * 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.graph.requests;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.GraphI18n;
+import org.jboss.dna.graph.connectors.RepositorySourceException;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+import org.jboss.dna.graph.properties.basic.BasicEmptyProperty;
+
+/**
+ * A component that is used to process and execute {@link Request}s. This class is
intended to be subclassed and methods
+ * overwritten to define the behavior for executing the different kinds of requests.
Abstract methods must be overridden, but
+ * non-abstract methods all have meaningful default implementations.
+ *
+ * @author Randall Hauch
+ */
+@Immutable
+public abstract class RequestProcessor {
+
+ private final ExecutionContext context;
+ private final String sourceName;
+
+ protected RequestProcessor( String sourceName,
+ ExecutionContext context ) {
+ CheckArg.isNotEmpty(sourceName, "sourceName");
+ CheckArg.isNotNull(context, "context");
+ this.context = context;
+ this.sourceName = sourceName;
+ }
+
+ /**
+ * Get the name of the source against which this processor is executing.
+ *
+ * @return the repository source name; never null or empty
+ */
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ /**
+ * The execution context that this process is operating within.
+ *
+ * @return the execution context; never null
+ */
+ public ExecutionContext getExecutionContext() {
+ return this.context;
+ }
+
+ /**
+ * Process a request by determining the type of request and delegating to the
appropriate <code>process</code> method for that
+ * type.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the general request
+ */
+ public void process( Request request ) {
+ if (request == null) return;
+ if (request instanceof CompositeRequest) {
+ process((CompositeRequest)request);
+ } else if (request instanceof CopyBranchRequest) {
+ process((CopyBranchRequest)request);
+ } else if (request instanceof CreateNodeRequest) {
+ process((CreateNodeRequest)request);
+ } else if (request instanceof DeleteBranchRequest) {
+ process((DeleteBranchRequest)request);
+ } else if (request instanceof MoveBranchRequest) {
+ process((MoveBranchRequest)request);
+ } else if (request instanceof ReadAllChildrenRequest) {
+ process((ReadAllChildrenRequest)request);
+ } else if (request instanceof ReadBlockOfChildrenRequest) {
+ process((ReadBlockOfChildrenRequest)request);
+ } else if (request instanceof ReadBranchRequest) {
+ process((ReadBranchRequest)request);
+ } else if (request instanceof ReadNodeRequest) {
+ process((ReadNodeRequest)request);
+ } else if (request instanceof ReadAllPropertiesRequest) {
+ process((ReadAllPropertiesRequest)request);
+ } else if (request instanceof ReadPropertyRequest) {
+ process((ReadPropertyRequest)request);
+ } else if (request instanceof RemovePropertiesRequest) {
+ process((RemovePropertiesRequest)request);
+ } else if (request instanceof RenameNodeRequest) {
+ process((RenameNodeRequest)request);
+ } else if (request instanceof UpdatePropertiesRequest) {
+ process((UpdatePropertiesRequest)request);
+ }
+ }
+
+ /**
+ * Process a request that is composed of multiple other (non-composite) requests. If
any of the embedded requests
+ * {@link Request#hasError() has an error} after it is processed, the submitted
request will be marked with an error.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the composite request
+ */
+ public void process( CompositeRequest request ) {
+ if (request == null) return;
+ int numberOfErrors = 0;
+ Throwable firstError = null;
+ for (Request embedded : request) {
+ assert embedded != null;
+ process(embedded);
+ if (embedded.hasError()) {
+ if (numberOfErrors == 0) firstError = embedded.getError();
+ ++numberOfErrors;
+ }
+ }
+ if (firstError == null) return;
+ if (numberOfErrors == 1) {
+ request.setError(firstError);
+ } else {
+ String msg =
GraphI18n.multipleErrorsWhileExecutingRequests.text(numberOfErrors, request.size());
+ request.setError(new RepositorySourceException(getSourceName(), msg));
+ }
+ }
+
+ /**
+ * Process a request to copy a branch into another location.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the copy request
+ */
+ public abstract void process( CopyBranchRequest request );
+
+ /**
+ * Process a request to create a node at a specified location.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the create request
+ */
+ public abstract void process( CreateNodeRequest request );
+
+ /**
+ * Process a request to delete a branch at a specified location.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the delete request
+ */
+ public abstract void process( DeleteBranchRequest request );
+
+ /**
+ * Process a request to move a branch at a specified location into a different
location.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the move request
+ */
+ public abstract void process( MoveBranchRequest request );
+
+ /**
+ * Process a request to read all of the children of a node.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public abstract void process( ReadAllChildrenRequest request );
+
+ /**
+ * Process a request to read a block of the children of a node. The block is defined
by a
+ * {@link ReadBlockOfChildrenRequest#startingAt() starting index} and a {@link
ReadBlockOfChildrenRequest#count() maximum
+ * number of children to include in the block}.
+ * <p>
+ * This method does nothing if the request is null. The default implementation
converts the command to a
+ * {@link ReadAllChildrenRequest}, and then finds the children within the block.
Obviously for large numbers of children, this
+ * implementation may not be efficient and may need to be overridden.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public void process( ReadBlockOfChildrenRequest request ) {
+ if (request == null) return;
+ // Convert the request to a ReadAllChildrenRequest and execute it ...
+ ReadAllChildrenRequest readAll = new ReadAllChildrenRequest(request.of());
+ process(readAll);
+ if (readAll.hasError()) {
+ request.setError(readAll.getError());
+ return;
+ }
+ List<Location> allChildren = readAll.getChildren();
+
+ // If there aren't enough children for the block's range ...
+ if (allChildren.size() < request.endingBefore()) return;
+
+ // Now, find the children in the block ...
+ for (int i = request.startingAt(); i != request.endingBefore(); ++i) {
+ request.addChild(allChildren.get(i));
+ }
+ }
+
+ /**
+ * Process a request to read a branch or subgraph that's below a node at a
specified location.
+ * <p>
+ * This method does nothing if the request is null. The default implementation
processes the branch by submitting the
+ * equivalent requests to {@link ReadNodeRequest read the nodes} and the {@link
ReadAllChildrenRequest children}. It starts by
+ * doing this for the top-level node, then proceeds for each of the children of that
node, and so forth.
+ * </p>
+ *
+ * @param request the request to read the branch
+ */
+ public void process( ReadBranchRequest request ) {
+ if (request == null) return;
+ // Create a queue for locations that need to be read ...
+ Queue<LocationWithDepth> locationsToRead = new
LinkedList<LocationWithDepth>();
+ locationsToRead.add(new LocationWithDepth(request.at(), 1));
+
+ // Now read the locations ...
+ while (locationsToRead.peek() != null) {
+ LocationWithDepth read = locationsToRead.poll();
+
+ // Check the depth ...
+ if (read.depth > request.maximumDepth()) continue;
+
+ // Read the properties ...
+ ReadNodeRequest readNode = new ReadNodeRequest(read.location);
+ process(readNode);
+ if (readNode.hasError()) {
+ request.setError(readNode.getError());
+ return;
+ }
+ request.setProperties(read.location, readNode.getProperties());
+
+ // Read the children for this node, and add them to the list of locations to
be read ...
+ ReadAllChildrenRequest readChildren = new
ReadAllChildrenRequest(read.location);
+ process(readChildren);
+ request.setChildren(read.location, readChildren.getChildren());
+
+ // Add each of the children to the list of locations that we need to read
...
+ for (Location child : readChildren) {
+ locationsToRead.add(new LocationWithDepth(child, read.depth + 1));
+ }
+ }
+ }
+
+ /**
+ * Process a request to read the properties of a node at the supplied location.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public abstract void process( ReadAllPropertiesRequest request );
+
+ /**
+ * Process a request to read the properties and children of a node at the supplied
location.
+ * <p>
+ * This method does nothing if the request is null. Unless overridden, this method
converts the single request into a
+ * {@link ReadAllChildrenRequest} and a {@link ReadAllPropertiesRequest}.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public void process( ReadNodeRequest request ) {
+ if (request == null) return;
+ // Read the properties ...
+ ReadAllPropertiesRequest readProperties = new
ReadAllPropertiesRequest(request.at());
+ process(readProperties);
+ if (readProperties.hasError()) {
+ request.setError(readProperties.getError());
+ return;
+ }
+ // Read the children ...
+ ReadAllChildrenRequest readChildren = new ReadAllChildrenRequest(request.at());
+ process(readChildren);
+ if (readChildren.hasError()) {
+ request.setError(readChildren.getError());
+ return;
+ }
+ // Now, copy all of the results into the submitted request ...
+ for (Property property : readProperties) {
+ request.addProperty(property);
+ }
+ for (Location child : readChildren) {
+ request.addChild(child);
+ }
+ }
+
+ /**
+ * Process a request to read a single property of a node at the supplied location.
+ * <p>
+ * This method does nothing if the request is null. Unless overridden, this method
converts the request that
+ * {@link ReadNodeRequest reads the node} and simply returns the one property.
+ * </p>
+ *
+ * @param request the read request
+ */
+ public void process( ReadPropertyRequest request ) {
+ if (request == null) return;
+ ReadNodeRequest readNode = new ReadNodeRequest(request.on());
+ process(readNode);
+ if (readNode.hasError()) {
+ request.setError(readNode.getError());
+ return;
+ }
+ Property property = readNode.getPropertiesByName().get(request.named());
+ request.setProperty(property);
+ }
+
+ /**
+ * Process a request to remove the specified properties from a node.
+ * <p>
+ * This method does nothing if the request is null. Unless overridden, this method
converts this request into a
+ * {@link UpdatePropertiesRequest}.
+ * </p>
+ *
+ * @param request the request to remove the properties with certain names
+ */
+ public void process( RemovePropertiesRequest request ) {
+ if (request == null) return;
+ Collection<Name> names = request.propertyNames();
+ if (names.isEmpty()) return;
+ List<Property> emptyProperties = new
ArrayList<Property>(names.size());
+ for (Name propertyName : names) {
+ emptyProperties.add(new BasicEmptyProperty(propertyName));
+ }
+ UpdatePropertiesRequest update = new UpdatePropertiesRequest(request.from(),
emptyProperties);
+ process(update);
+ if (update.hasError()) {
+ request.setError(update.getError());
+ }
+ }
+
+ /**
+ * Process a request to remove the specified properties from a node.
+ * <p>
+ * This method does nothing if the request is null.
+ * </p>
+ *
+ * @param request the remove request
+ */
+ public abstract void process( UpdatePropertiesRequest request );
+
+ /**
+ * Process a request to rename a node specified location into a different location.
+ * <p>
+ * This method does nothing if the request is null. Unless overridden, this method
converts the rename into a
+ * {@link MoveBranchRequest move}. However, this only works if the
<code>request</code> has a {@link Location#hasPath() path}
+ * for its {@link RenameNodeRequest#at() location}. (If not, this method throws an
{@link UnsupportedOperationException} and
+ * must be overriddent.)
+ * </p>
+ *
+ * @param request the rename request
+ */
+ public void process( RenameNodeRequest request ) {
+ if (request == null) return;
+ Location from = request.at();
+ if (!from.hasPath()) {
+ throw new UnsupportedOperationException();
+ }
+ Path newPath =
getExecutionContext().getValueFactories().getPathFactory().create(from.getPath(),
request.toName());
+ Location to = new Location(newPath);
+ MoveBranchRequest move = new MoveBranchRequest(from, to);
+ process(move);
+ }
+
+ /**
+ * A class that represents a location at a known depth
+ *
+ * @author Randall Hauch
+ */
+ protected static class LocationWithDepth {
+ protected final Location location;
+ protected final int depth;
+
+ protected LocationWithDepth( Location location,
+ int depth ) {
+ this.location = location;
+ this.depth = depth;
+ }
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RequestProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,151 @@
+/*
+ * 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.graph.requests;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.properties.Property;
+
+/**
+ * Instruction to update the properties on the node at the specified location. Any
property with no values will be removed.
+ *
+ * @author Randall Hauch
+ */
+public class UpdatePropertiesRequest extends Request implements Iterable<Property>
{
+
+ private final Location on;
+ private final List<Property> properties;
+
+ /**
+ * Create a request to update the properties on the node at the supplied location.
+ *
+ * @param on the location of the node to be read
+ * @param properties the new properties on the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to update
+ */
+ public UpdatePropertiesRequest( Location on,
+ Property... properties ) {
+ CheckArg.isNotNull(on, "on");
+ CheckArg.isNotEmpty(properties, "properties");
+ this.on = on;
+ this.properties = Collections.unmodifiableList(Arrays.asList(properties));
+ }
+
+ /**
+ * Create a request to update the properties on the node at the supplied location.
+ *
+ * @param on the location of the node to be read
+ * @param properties the new properties on the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to update
+ */
+ public UpdatePropertiesRequest( Location on,
+ Iterable<Property> properties ) {
+ CheckArg.isNotNull(on, "on");
+ this.on = on;
+ List<Property> props = new LinkedList<Property>();
+ for (Property property : properties) {
+ if (property != null) props.add(property);
+ }
+ this.properties = Collections.unmodifiableList(props);
+ CheckArg.isNotEmpty(this.properties, "properties");
+ }
+
+ /**
+ * Create a request to update the properties on the node at the supplied location.
+ *
+ * @param on the location of the node to be read
+ * @param properties the new properties on the node
+ * @throws IllegalArgumentException if the location is null or if there are no
properties to update
+ */
+ public UpdatePropertiesRequest( Location on,
+ Iterator<Property> properties ) {
+ CheckArg.isNotNull(on, "on");
+ this.on = on;
+ List<Property> props = new LinkedList<Property>();
+ while (properties.hasNext()) {
+ Property property = properties.next();
+ if (property != null) props.add(property);
+ }
+ this.properties = Collections.unmodifiableList(props);
+ CheckArg.isNotEmpty(this.properties, "properties");
+ }
+
+ /**
+ * Get the location defining the node that is to be updated.
+ *
+ * @return the location of the node; never null
+ */
+ public Location on() {
+ return on;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<Property> iterator() {
+ return this.properties.iterator();
+ }
+
+ /**
+ * Get the properties for the node.
+ *
+ * @return the collection of properties; never null and never empty
+ */
+ public Collection<Property> properties() {
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (this.getClass().isInstance(obj)) {
+ UpdatePropertiesRequest that = (UpdatePropertiesRequest)obj;
+ if (!this.on().equals(that.on())) return false;
+ if (!this.properties().equals(that.properties())) return false;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "update properties on " + on() + " to " +
StringUtil.readableString(properties());
+ }
+
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2008-09-29
22:24:12 UTC (rev 564)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2008-10-08
20:24:19 UTC (rev 565)
@@ -51,6 +51,7 @@
executedGraphCommand = Executed {0}
closingCommandExecutor = Closing command executor
closedCommandExecutor = Closed command executor
+multipleErrorsWhileExecutingRequests = {0} of the {1} requests resulted in errors
errorSequencingXmlDocument = An error was received while sequencing XML: {0}
fatalErrorSequencingXmlDocument = A fatal error was received while sequencing XML: {0}
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,86 @@
+/*
+ * 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.graph.requests;
+
+import java.util.UUID;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.connectors.BasicExecutionContext;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
+import org.junit.Before;
+
+/**
+ * @author Randall Hauch
+ */
+public abstract class AbstractRequestTest {
+
+ protected ExecutionContext context;
+ protected Location validPathLocation;
+ protected Location validUuidLocation;
+ protected Location validPropsLocation;
+ protected Location validPathLocation1;
+ protected Location validUuidLocation1;
+ protected Location validPropsLocation1;
+ protected Location validPathLocation2;
+ protected Location validUuidLocation2;
+ protected Location validPropsLocation2;
+ protected Property validProperty1;
+ protected Property validProperty2;
+
+ @Before
+ public void beforeEach() {
+ context = new BasicExecutionContext();
+ Path validPath = createPath("/a/b/c");
+ UUID validUuid = UUID.randomUUID();
+ Name idProperty1Name = createName("id1");
+ Name idProperty2Name = createName("id2");
+ Property idProperty1 = context.getPropertyFactory().create(idProperty1Name,
"1");
+ Property idProperty2 = context.getPropertyFactory().create(idProperty2Name,
"2");
+ validPathLocation = new Location(validPath);
+ validUuidLocation = new Location(validUuid);
+ validPropsLocation = new Location(idProperty1, idProperty2);
+
+ validPathLocation1 = new Location(validPath);
+ validUuidLocation1 = new Location(validUuid);
+ validPropsLocation1 = new Location(idProperty1, idProperty2);
+
+ validPath = createPath("/a/c/d");
+ validUuid = UUID.randomUUID();
+ idProperty1 = context.getPropertyFactory().create(idProperty1Name,
"3");
+ idProperty2 = context.getPropertyFactory().create(idProperty2Name,
"4");
+ validPathLocation2 = new Location(validPath);
+ validUuidLocation2 = new Location(validUuid);
+ validPropsLocation2 = new Location(idProperty1, idProperty2);
+
+ validProperty1 =
context.getPropertyFactory().create(createName("fooProperty"),
"foo");
+ validProperty2 =
context.getPropertyFactory().create(createName("barProperty"),
"bar");
+ }
+
+ protected Path createPath( String path ) {
+ return context.getValueFactories().getPathFactory().create(path);
+ }
+
+ protected Name createName( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,126 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class CompositeRequestTest extends AbstractRequestTest {
+
+ private Request request;
+ private Request[] requests;
+ private List<Request> requestList;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ Request request1 = new ReadPropertyRequest(validPathLocation1,
createName("property"));
+ Request request2 = new ReadPropertyRequest(validPathLocation2,
createName("property"));
+ Request request3 = new ReadAllChildrenRequest(validPathLocation);
+ requests = new Request[] {request1, request2, request3};
+ requestList = Arrays.asList(requests);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingCompositeRequestWithNullRequest() {
+ CompositeRequest.with((Request)null);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingCompositeRequestWithNullRequestArray() {
+ CompositeRequest.with((Request[])null);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingCompositeRequestWithNullRequestIterator() {
+ CompositeRequest.with((Iterator<Request>)null);
+ }
+
+ @Test
+ public void shouldReturnRequestWhenCreatingCompositeFromSingleRequest() {
+ request = CompositeRequest.with(requests[0]);
+ assertThat(request, is(sameInstance(requests[0])));
+ }
+
+ @Test
+ public void shouldReturnRequestWhenCreatingCompositeFromIteratorOverSingleRequest()
{
+ requestList = Collections.singletonList(requests[0]);
+ request = CompositeRequest.with(requestList.iterator());
+ assertThat(request, is(sameInstance(requestList.get(0))));
+ }
+
+ @Test
+ public void shouldCreateCompositeFromMultipleRequests() {
+ request = CompositeRequest.with(requests);
+ assertThat(request, is(instanceOf(CompositeRequest.class)));
+ CompositeRequest composite = (CompositeRequest)request;
+ assertThat(composite.size(), is(3));
+ assertThat(composite.size(), is(requests.length));
+ assertThat(composite.getRequests(), hasItems(requests));
+ Iterator<Request> actual = composite.iterator();
+ Iterator<Request> expected = requestList.iterator();
+ while (actual.hasNext() && expected.hasNext()) {
+ assertThat(actual.next(), is(sameInstance(expected.next())));
+ }
+ assertThat(actual.hasNext(), is(expected.hasNext()));
+ assertThat(composite.hasError(), is(false));
+ }
+
+ @Test
+ public void shouldCreateCompositeFromIteratorOverRequests() {
+ request = CompositeRequest.with(requestList.iterator());
+ assertThat(request, is(instanceOf(CompositeRequest.class)));
+ CompositeRequest composite = (CompositeRequest)request;
+ assertThat(composite.size(), is(3));
+ assertThat(composite.size(), is(requestList.size()));
+ assertThat(composite.getRequests(), hasItems(requests));
+ Iterator<Request> actual = composite.iterator();
+ Iterator<Request> expected = requestList.iterator();
+ while (actual.hasNext() && expected.hasNext()) {
+ assertThat(actual.next(), is(sameInstance(expected.next())));
+ }
+ assertThat(actual.hasNext(), is(expected.hasNext()));
+ assertThat(composite.hasError(), is(false));
+ }
+
+ @Test
+ public void shouldConsiderTwoCompositesOfSameRequestsToBeEqual() {
+ request = CompositeRequest.with(requests);
+ Request request2 = CompositeRequest.with(requests);
+ assertThat(request, is(request2));
+ assertThat(request.hasError(), is(false));
+ }
+
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,76 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class CopyBranchRequestTest extends AbstractRequestTest {
+
+ private CopyBranchRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidFromLocationAndValidToLocation() {
+ request = new CopyBranchRequest(validPathLocation1, validPathLocation2);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.into(), is(sameInstance(validPathLocation2)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new CopyBranchRequest(validPathLocation1, validPathLocation2);
+ CopyBranchRequest request2 = new CopyBranchRequest(validPathLocation1,
validPathLocation2);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new CopyBranchRequest(validPathLocation1, validPathLocation2);
+ CopyBranchRequest request2 = new CopyBranchRequest(validPathLocation1,
validUuidLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,75 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class DeleteBranchRequestTest extends AbstractRequestTest {
+
+ private DeleteBranchRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new DeleteBranchRequest(validPathLocation1);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new DeleteBranchRequest(validPathLocation1);
+ DeleteBranchRequest request2 = new DeleteBranchRequest(validPathLocation1);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new DeleteBranchRequest(validPathLocation1);
+ DeleteBranchRequest request2 = new DeleteBranchRequest(validPathLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,76 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class MoveBranchRequestTest extends AbstractRequestTest {
+
+ private MoveBranchRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidFromLocationAndValidToLocation() {
+ request = new MoveBranchRequest(validPathLocation1, validPathLocation2);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.into(), is(sameInstance(validPathLocation2)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new MoveBranchRequest(validPathLocation1, validPathLocation2);
+ MoveBranchRequest request2 = new MoveBranchRequest(validPathLocation1,
validPathLocation2);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new MoveBranchRequest(validPathLocation1, validPathLocation2);
+ MoveBranchRequest request2 = new MoveBranchRequest(validPathLocation1,
validUuidLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,85 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadAllChildrenRequestTest extends AbstractRequestTest {
+
+ private ReadAllChildrenRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadAllChildrenRequest(validPathLocation1);
+ assertThat(request.of(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new ReadAllChildrenRequest(validPathLocation1);
+ ReadAllChildrenRequest request2 = new
ReadAllChildrenRequest(validPathLocation1);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadAllChildrenRequest(validPathLocation1);
+ ReadAllChildrenRequest request2 = new
ReadAllChildrenRequest(validPathLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void shouldAllowAddingChildren() {
+ request = new ReadAllChildrenRequest(validPathLocation);
+ request.addChild(validPathLocation1);
+ request.addChild(validPathLocation2);
+ assertThat(request.getChildren().size(), is(2));
+ assertThat(request.getChildren(), hasItems(validPathLocation1,
validPathLocation2));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,87 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadAllPropertiesRequestTest extends AbstractRequestTest {
+
+ private ReadAllPropertiesRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadAllPropertiesRequest(validPathLocation1);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new ReadAllPropertiesRequest(validPathLocation1);
+ ReadAllPropertiesRequest request2 = new
ReadAllPropertiesRequest(validPathLocation1);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadAllPropertiesRequest(validPathLocation1);
+ ReadAllPropertiesRequest request2 = new
ReadAllPropertiesRequest(validPathLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void shouldAllowAddingProperties() {
+ request = new ReadAllPropertiesRequest(validPathLocation);
+ request.addProperty(validProperty1);
+ request.addProperty(validProperty2);
+ assertThat(request.getProperties().size(), is(2));
+ assertThat(request.getProperties(), hasItems(validProperty1, validProperty2));
+ assertThat(request.getPropertiesByName().get(validProperty1.getName()),
is(validProperty1));
+ assertThat(request.getPropertiesByName().get(validProperty2.getName()),
is(validProperty2));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,89 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadBlockOfChildrenRequestTest extends AbstractRequestTest {
+
+ private ReadBlockOfChildrenRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadBlockOfChildrenRequest(validPathLocation1, 2, 10);
+ assertThat(request.of(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new ReadBlockOfChildrenRequest(validPathLocation1, 2, 20);
+ ReadBlockOfChildrenRequest request2 = new
ReadBlockOfChildrenRequest(validPathLocation1, 2, 20);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadBlockOfChildrenRequest(validPathLocation1, 20, 20);
+ ReadBlockOfChildrenRequest request2 = new
ReadBlockOfChildrenRequest(validPathLocation2, 2, 20);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationsButDifferentStartingIndexes() {
+ request = new ReadBlockOfChildrenRequest(validPathLocation1, 20, 20);
+ ReadBlockOfChildrenRequest request2 = new
ReadBlockOfChildrenRequest(validPathLocation1, 2, 20);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationsButDifferentBlockSizes() {
+ request = new ReadBlockOfChildrenRequest(validPathLocation1, 2, 2);
+ ReadBlockOfChildrenRequest request2 = new
ReadBlockOfChildrenRequest(validPathLocation1, 2, 20);
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,92 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadBranchRequestTest extends AbstractRequestTest {
+
+ private ReadBranchRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadBranchRequest(validPathLocation1);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.maximumDepth(), is(ReadBranchRequest.DEFAULT_MAXIMUM_DEPTH));
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocationAndMaximumDepth() {
+ request = new ReadBranchRequest(validPathLocation1, 10);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.maximumDepth(), is(10));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new ReadBranchRequest(validPathLocation1);
+ ReadBranchRequest request2 = new ReadBranchRequest(validPathLocation1);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadBranchRequest(validPathLocation1, 20);
+ ReadBranchRequest request2 = new ReadBranchRequest(validPathLocation2, 20);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationsButDifferentMaximumDepths() {
+ request = new ReadBranchRequest(validPathLocation1, 20);
+ ReadBranchRequest request2 = new ReadBranchRequest(validPathLocation1, 2);
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,96 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadNodeRequestTest extends AbstractRequestTest {
+
+ private ReadNodeRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadNodeRequest(validPathLocation1);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new ReadNodeRequest(validPathLocation1);
+ ReadNodeRequest request2 = new ReadNodeRequest(validPathLocation1);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadNodeRequest(validPathLocation1);
+ ReadNodeRequest request2 = new ReadNodeRequest(validPathLocation2);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void shouldAllowAddingChildren() {
+ request = new ReadNodeRequest(validPathLocation);
+ request.addChild(validPathLocation1);
+ request.addChild(validPathLocation2);
+ assertThat(request.getChildren().size(), is(2));
+ assertThat(request.getChildren(), hasItems(validPathLocation1,
validPathLocation2));
+ }
+
+ @Test
+ public void shouldAllowAddingProperties() {
+ request = new ReadNodeRequest(validPathLocation);
+ request.addProperty(validProperty1);
+ request.addProperty(validProperty2);
+ assertThat(request.getProperties().size(), is(2));
+ assertThat(request.getProperties(), hasItems(validProperty1, validProperty2));
+ assertThat(request.getPropertiesByName().get(validProperty1.getName()),
is(validProperty1));
+ assertThat(request.getPropertiesByName().get(validProperty2.getName()),
is(validProperty2));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,100 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.jboss.dna.graph.properties.Name;
+import org.jboss.dna.graph.properties.Property;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class ReadPropertyRequestTest extends AbstractRequestTest {
+
+ private ReadPropertyRequest request;
+ private Property validProperty;
+ private Name validPropertyName;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ validProperty = validProperty1;
+ validPropertyName = validProperty.getName();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocation() {
+ request = new ReadPropertyRequest(validPathLocation1, validPropertyName);
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocationsAndSamePropertyName() {
+ request = new ReadPropertyRequest(validPathLocation1, validPropertyName);
+ ReadPropertyRequest request2 = new ReadPropertyRequest(validPathLocation1,
validPropertyName);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new ReadPropertyRequest(validPathLocation1, validPropertyName);
+ ReadPropertyRequest request2 = new ReadPropertyRequest(validPathLocation2,
validPropertyName);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationButDifferentPropertyNames() {
+ request = new ReadPropertyRequest(validPathLocation1, validProperty2.getName());
+ ReadPropertyRequest request2 = new ReadPropertyRequest(validPathLocation2,
validPropertyName);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void shouldAllowSettingProperties() {
+ request = new ReadPropertyRequest(validPathLocation, validPropertyName);
+ request.setProperty(validProperty1);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowSettingPropertyIfNameDoeNotMatch() {
+ request = new ReadPropertyRequest(validPathLocation, validPropertyName);
+ request.setProperty(validProperty2);
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,140 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.dna.graph.properties.Name;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class RemovePropertiesRequestTest extends AbstractRequestTest {
+
+ private RemovePropertiesRequest request;
+ private Name validPropertyName1;
+ private Name validPropertyName2;
+ private Name validPropertyName3;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ validPropertyName1 = createName("foo1");
+ validPropertyName2 = createName("foo2");
+ validPropertyName3 = createName("foo3");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocationAndValidPropertyName() {
+ request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.propertyNames(), hasItems(validPropertyName1));
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocationAndValidPropertyNames() {
+ request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1,
validPropertyName2);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.propertyNames(), hasItems(validPropertyName1,
validPropertyName2));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIteratorOverValidPropertyName() {
+ List<Name> names = new ArrayList<Name>();
+ names.add(validPropertyName1);
+ request = new RemovePropertiesRequest(validPathLocation1, names);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.propertyNames(), hasItems(validPropertyName1));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIteratorOverValidPropertyNames() {
+ List<Name> names = new ArrayList<Name>();
+ names.add(validPropertyName1);
+ names.add(validPropertyName2);
+ names.add(validPropertyName3);
+ request = new RemovePropertiesRequest(validPathLocation1, names.iterator());
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.propertyNames(), hasItems(validPropertyName1,
validPropertyName2, validPropertyName3));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIterableWithValidPropertyNames() {
+ List<Name> names = new ArrayList<Name>();
+ names.add(validPropertyName1);
+ names.add(validPropertyName2);
+ names.add(validPropertyName3);
+ request = new RemovePropertiesRequest(validPathLocation1, names);
+ assertThat(request.from(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.propertyNames(), hasItems(validPropertyName1,
validPropertyName2, validPropertyName3));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocationsAndSamePropertyNames() {
+ request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1,
validPropertyName2);
+ RemovePropertiesRequest request2 = new
RemovePropertiesRequest(validPathLocation1, validPropertyName1, validPropertyName2);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1,
validPropertyName2);
+ RemovePropertiesRequest request2 = new
RemovePropertiesRequest(validPathLocation2, validPropertyName1, validPropertyName2);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationButDifferentPropertyNames() {
+ request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1,
validPropertyName2);
+ RemovePropertiesRequest request2 = new
RemovePropertiesRequest(validPathLocation2, validPropertyName2, validPropertyName3);
+ assertThat(request.equals(request2), is(false));
+ }
+
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,86 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import org.jboss.dna.graph.properties.Name;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class RenameNodeRequestTest extends AbstractRequestTest {
+
+ private RenameNodeRequest request;
+ private Name newName;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ newName = createName("SomethingElse");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidFromLocationAndValidToLocation() {
+ request = new RenameNodeRequest(validPathLocation1, newName);
+ assertThat(request.at(), is(sameInstance(validPathLocation1)));
+ assertThat(request.toName(), is(sameInstance(newName)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocations() {
+ request = new RenameNodeRequest(validPathLocation1, newName);
+ RenameNodeRequest request2 = new RenameNodeRequest(validPathLocation1, newName);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new RenameNodeRequest(validPathLocation1, newName);
+ RenameNodeRequest request2 = new RenameNodeRequest(validPathLocation2, newName);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithSameLocationsAndDifferentNames() {
+ request = new RenameNodeRequest(validPathLocation1, newName);
+ RenameNodeRequest request2 = new RenameNodeRequest(validPathLocation1,
createName("OtherName"));
+ assertThat(request.equals(request2), is(false));
+ }
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java
(rev 0)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java 2008-10-08
20:24:19 UTC (rev 565)
@@ -0,0 +1,143 @@
+/*
+ * 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.graph.requests;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.hamcrest.core.IsSame.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.dna.graph.properties.Property;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Randall Hauch
+ */
+public class UpdatePropertiesRequestTest extends AbstractRequestTest {
+
+ private UpdatePropertiesRequest request;
+
+ @Override
+ @Before
+ public void beforeEach() {
+ super.beforeEach();
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+ new CopyBranchRequest(null, validPathLocation);
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldNotAllowCreatingRequestWithNullToLocation() {
+ new CopyBranchRequest(validPathLocation, null);
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocationAndValidProperty() {
+ request = new UpdatePropertiesRequest(validPathLocation1, validProperty1);
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1));
+ }
+
+ @Test
+ public void shouldCreateValidRequestWithValidLocationAndValidPropertyNames() {
+ request = new UpdatePropertiesRequest(validPathLocation1, validProperty1,
validProperty2);
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1, validProperty2));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIteratorOverValidPropertyName() {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(validProperty1);
+ request = new UpdatePropertiesRequest(validPathLocation1,
properties.iterator());
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIteratorOverValidPropertyNames() {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(validProperty1);
+ properties.add(validProperty2);
+ request = new UpdatePropertiesRequest(validPathLocation1,
properties.iterator());
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1, validProperty2));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIterableWithValidPropertyName() {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(validProperty1);
+ request = new UpdatePropertiesRequest(validPathLocation1, properties);
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1));
+ }
+
+ @Test
+ public void
shouldCreateValidRequestWithValidLocationAndIterableWithValidPropertyNames() {
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(validProperty1);
+ properties.add(validProperty2);
+ request = new UpdatePropertiesRequest(validPathLocation1, properties);
+ assertThat(request.on(), is(sameInstance(validPathLocation1)));
+ assertThat(request.hasError(), is(false));
+ assertThat(request.getError(), is(nullValue()));
+ assertThat(request.properties(), hasItems(validProperty1, validProperty2));
+ }
+
+ @Test
+ public void shouldConsiderEqualTwoRequestsWithSameLocationsAndSamePropertyNames() {
+ request = new UpdatePropertiesRequest(validPathLocation1, validProperty1,
validProperty2);
+ UpdatePropertiesRequest request2 = new
UpdatePropertiesRequest(validPathLocation1, validProperty1, validProperty2);
+ assertThat(request, is(request2));
+ }
+
+ @Test
+ public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() {
+ request = new UpdatePropertiesRequest(validPathLocation1, validProperty1,
validProperty2);
+ UpdatePropertiesRequest request2 = new
UpdatePropertiesRequest(validPathLocation2, validProperty1, validProperty2);
+ assertThat(request.equals(request2), is(false));
+ }
+
+ @Test
+ public void
shouldConsiderNotEqualTwoRequestsWithSameLocationButDifferentPropertyNames() {
+ request = new UpdatePropertiesRequest(validPathLocation1, validProperty1,
validProperty2);
+ UpdatePropertiesRequest request2 = new
UpdatePropertiesRequest(validPathLocation2, validProperty1);
+ assertThat(request.equals(request2), is(false));
+ }
+
+}
Property changes on:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain