[dna-commits] DNA SVN: r618 - in trunk/dna-graph/src: main/java/org/jboss/dna/graph/requests/processor and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Mon Nov 10 18:57:53 EST 2008


Author: rhauch
Date: 2008-11-10 18:57:53 -0500 (Mon, 10 Nov 2008)
New Revision: 618

Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.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/Request.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/processor/RequestProcessor.java
   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
Log:
DNA-217 - Connector SPI should have protocol for cancelling operations
http://jira.jboss.com/jira/browse/DNA-217

Added to Request a method isCancelled():boolean to check whether the request was cancelled, and another method "cancel():void" to mark a request as cancelled.  Also added to the CompositeRequest the ability to mark the composite (or any contained request) as cancelled, but to have all other requests (including the composite) be also cancelled.  This is done through a single AtomicBoolean instance shared amongst the composite and contained requests.

Also added tests to verify the desired behavior.

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/CompositeRequest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -26,10 +26,17 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.jboss.dna.common.util.CheckArg;
 
 /**
- * A request that wraps multiple other requests.
+ * A request that wraps multiple other requests, allowing multiple requests to be treated as a single request.
+ * <p>
+ * Note that {@link #isCancelled()} and {@link #cancel()} apply to all requests contained by the composite request. In other
+ * words, cancelling this request immediately marks all contained requests as cancelled. However, cancelling any request in the
+ * request has the effect of cancelling all other requests in the composite, including the composite. (This is implemented by
+ * having all {@link Request} objects in the composite share the same cancelled flag object.)
+ * </p>
  * 
  * @author Randall Hauch
  */
@@ -187,8 +194,13 @@
      * @param requests the modifiable list of requests; may not be null
      * @param readOnly true if all of the requests are {@link Request#isReadOnly() read-only}
      */
-    protected CompositeRequest( List<? extends Request> requests,
-                                boolean readOnly ) {
+    /*package*/CompositeRequest( List<? extends Request> requests,
+                                  boolean readOnly ) {
+        // Iterate through the requests and set the cancelled flag of each request to this object's flag ...
+        final AtomicBoolean flag = super.getCancelledFlag();
+        for (Request request : requests) {
+            request.setCancelledFlag(flag);
+        }
         this.requests = Collections.unmodifiableList(requests);
         this.readOnly = readOnly;
     }

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/RemovePropertiesRequest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -73,6 +73,7 @@
     public RemovePropertiesRequest( Location from,
                                     Iterable<Name> propertyNames ) {
         CheckArg.isNotNull(from, "from");
+        CheckArg.isNotNull(propertyNames, "propertyNames");
         this.from = from;
         Set<Name> names = new HashSet<Name>();
         for (Name name : propertyNames) {
@@ -92,6 +93,7 @@
     public RemovePropertiesRequest( Location from,
                                     Iterator<Name> propertyNames ) {
         CheckArg.isNotNull(from, "from");
+        CheckArg.isNotNull(propertyNames, "propertyNames");
         this.from = from;
         Set<Name> names = new HashSet<Name>();
         while (propertyNames.hasNext()) {

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/Request.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -22,6 +22,7 @@
 package org.jboss.dna.graph.requests;
 
 import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.jboss.dna.graph.connectors.RepositoryConnection;
 
 /**
@@ -34,7 +35,12 @@
     private static final long serialVersionUID = 1L;
 
     private Throwable error;
+    private AtomicBoolean cancelled;
 
+    protected Request() {
+        this.cancelled = new AtomicBoolean(false);
+    }
+
     /**
      * Set the error for this request.
      * 
@@ -63,10 +69,61 @@
     }
 
     /**
+     * Check whether this request has been cancelled. Although it is a recommendation that the result of this method be followed
+     * wherever possible, it is not required to immediately stop processing the request if this method returns <code>true</code>.
+     * For example, if processing is almost complete, it may be appropriate to simply finish processing the request.
+     * <p>
+     * This method is safe to be called by different threads.
+     * </p>
+     * 
+     * @return true if this request has been cancelled, or false otherwise.
+     */
+    public boolean isCancelled() {
+        return cancelled.get();
+    }
+
+    /**
+     * Set the cancelled state of this request. All requests are initially marked as not cancelled. Note that this is designed so
+     * that the same {@link AtomicBoolean} instance can be passed to multiple requests, allowing a single flag to dictate the
+     * cancelled state of all of those requests.
+     * <p>
+     * So, by default, each request should already be set up to not be cancelled, so for most cases this method does not need to
+     * be called at all. This method should be called when this flag is to be shared among multiple requests, usually when the
+     * requests are being initialized or assembled.
+     * </p>
+     * 
+     * @param cancelled the new (potentially shared) cancelled state for the request; may not be null
+     */
+    /*package*/void setCancelledFlag( AtomicBoolean cancelled ) {
+        assert cancelled != null;
+        this.cancelled = cancelled;
+    }
+
+    /**
+     * Get this request's cancelled flag.
+     * 
+     * @return the cancelled flag
+     */
+    /*package*/AtomicBoolean getCancelledFlag() {
+        return cancelled;
+    }
+
+    /**
+     * Cancel this request. After this method is called, the {@link #isCancelled() cancellation flag} is set, and any current or
+     * future processing of the request may be affected by the cancellation. (Note however, that processors may choose to not
+     * respect this request.)
+     * <p>
+     * This method is safe to be called by different threads.
+     * </p>
+     */
+    public void cancel() {
+        this.cancelled.set(true);
+    }
+
+    /**
      * Return whether this request only reads information.
      * 
      * @return true if this request reads information, or false if it requests that the repository content be changed in some way
      */
     public abstract boolean isReadOnly();
-
 }

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/UpdatePropertiesRequest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -70,6 +70,7 @@
     public UpdatePropertiesRequest( Location on,
                                     Iterable<Property> properties ) {
         CheckArg.isNotNull(on, "on");
+        CheckArg.isNotNull(properties, "properties");
         this.on = on;
         List<Property> props = new LinkedList<Property>();
         for (Property property : properties) {
@@ -89,6 +90,7 @@
     public UpdatePropertiesRequest( Location on,
                                     Iterator<Property> properties ) {
         CheckArg.isNotNull(on, "on");
+        CheckArg.isNotNull(properties, "properties");
         this.on = on;
         List<Property> props = new LinkedList<Property>();
         while (properties.hasNext()) {

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/processor/RequestProcessor.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/processor/RequestProcessor.java	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/requests/processor/RequestProcessor.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -120,6 +120,7 @@
      */
     public void process( Request request ) {
         if (request == null) return;
+        if (request.isCancelled()) return;
         if (request instanceof CompositeRequest) {
             process((CompositeRequest)request);
         } else if (request instanceof CopyBranchRequest) {
@@ -166,6 +167,7 @@
         Throwable firstError = null;
         for (Request embedded : request) {
             assert embedded != null;
+            if (embedded.isCancelled()) return;
             process(embedded);
             if (embedded.hasError()) {
                 if (numberOfErrors == 0) firstError = embedded.getError();
@@ -285,6 +287,7 @@
         // Now read the locations ...
         boolean first = true;
         while (locationsToRead.peek() != null) {
+            if (request.isCancelled()) return;
             LocationWithDepth read = locationsToRead.poll();
 
             // Check the depth ...
@@ -353,6 +356,7 @@
             request.setError(readChildren.getError());
             return;
         }
+        if (request.isCancelled()) return;
         // Now, copy all of the results into the submitted request ...
         for (Property property : readProperties) {
             request.addProperty(property);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -21,6 +21,8 @@
  */
 package org.jboss.dna.graph.requests;
 
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
 import java.util.UUID;
 import org.jboss.dna.graph.BasicExecutionContext;
 import org.jboss.dna.graph.ExecutionContext;
@@ -29,6 +31,7 @@
 import org.jboss.dna.graph.properties.Path;
 import org.jboss.dna.graph.properties.Property;
 import org.junit.Before;
+import org.junit.Test;
 
 /**
  * @author Randall Hauch
@@ -84,4 +87,20 @@
     protected Name createName( String name ) {
         return context.getValueFactories().getNameFactory().create(name);
     }
+
+    protected abstract Request createRequest();
+
+    @Test
+    public void shouldNotBeCancelledByDefault() {
+        Request request = createRequest();
+        assertThat(request.isCancelled(), is(false));
+    }
+
+    @Test
+    public void shouldBeCancelledAfterCallingCancel() {
+        Request request = createRequest();
+        assertThat(request.isCancelled(), is(false));
+        request.cancel();
+        assertThat(request.isCancelled(), is(true));
+    }
 }

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CompositeRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -53,6 +53,39 @@
         requestList = Arrays.asList(requests);
     }
 
+    @Override
+    protected Request createRequest() {
+        return CompositeRequest.with(requests);
+    }
+
+    @Test
+    public void shouldCancelAllNestedRequestsAndCompositeAfterCallingCancel() {
+        Request composite = CompositeRequest.with(requests);
+        assertThat(composite.isCancelled(), is(false));
+        for (Request request : requests) {
+            assertThat(request.isCancelled(), is(false));
+        }
+        composite.cancel();
+        assertThat(composite.isCancelled(), is(true));
+        for (Request request : requests) {
+            assertThat(request.isCancelled(), is(true));
+        }
+    }
+
+    @Test
+    public void shouldCancelAllNestedRequestsAndCompositeAfterCallingCancelOnNestedRequest() {
+        Request composite = CompositeRequest.with(requests);
+        assertThat(composite.isCancelled(), is(false));
+        for (Request request : requests) {
+            assertThat(request.isCancelled(), is(false));
+        }
+        requests[0].cancel();
+        assertThat(composite.isCancelled(), is(true));
+        for (Request request : requests) {
+            assertThat(request.isCancelled(), is(true));
+        }
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingCompositeRequestWithNullRequest() {
         CompositeRequest.with((Request)null);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/CopyBranchRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -41,6 +41,11 @@
         super.beforeEach();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new CopyBranchRequest(validPathLocation1, validPathLocation2);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
         new CopyBranchRequest(null, validPathLocation);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/DeleteBranchRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -41,14 +41,14 @@
         super.beforeEach();
     }
 
-    @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+    @Override
+    protected Request createRequest() {
+        return new DeleteBranchRequest(validPathLocation1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+        new DeleteBranchRequest(null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/MoveBranchRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -41,14 +41,19 @@
         super.beforeEach();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new MoveBranchRequest(validPathLocation1, validPathLocation2);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+        new MoveBranchRequest(null, validPathLocation);
     }
 
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+        new MoveBranchRequest(validPathLocation, null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllChildrenRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -42,14 +42,14 @@
         super.beforeEach();
     }
 
-    @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+    @Override
+    protected Request createRequest() {
+        return new ReadAllChildrenRequest(validPathLocation1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+        new ReadAllChildrenRequest(null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadAllPropertiesRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -42,14 +42,14 @@
         super.beforeEach();
     }
 
-    @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+    @Override
+    protected Request createRequest() {
+        return new ReadAllPropertiesRequest(validPathLocation1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+        new ReadAllPropertiesRequest(null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBlockOfChildrenRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -41,16 +41,26 @@
         super.beforeEach();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new ReadBlockOfChildrenRequest(validPathLocation1, 2, 10);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+        new ReadBlockOfChildrenRequest(null, 0, 1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNegativeStartingIndex() {
+        new ReadBlockOfChildrenRequest(validPathLocation1, -1, 1);
     }
 
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithNegativeCount() {
+        new ReadBlockOfChildrenRequest(validPathLocation1, 1, -1);
+    }
+
     @Test
     public void shouldCreateValidRequestWithValidLocation() {
         request = new ReadBlockOfChildrenRequest(validPathLocation1, 2, 10);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadBranchRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -41,14 +41,14 @@
         super.beforeEach();
     }
 
-    @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+    @Override
+    protected Request createRequest() {
+        return new ReadBranchRequest(validPathLocation1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
+        new ReadBranchRequest(null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadNodeRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -42,6 +42,11 @@
         super.beforeEach();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new ReadNodeRequest(validPathLocation1);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
         new CopyBranchRequest(null, validPathLocation);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/ReadPropertyRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -47,13 +47,18 @@
         validPropertyName = validProperty.getName();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new ReadPropertyRequest(validPathLocation1, validPropertyName);
+    }
+
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+    public void shouldNotAllowCreatingRequestWithNullLocation() {
+        new ReadPropertyRequest(null, validPropertyName);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
+    public void shouldNotAllowCreatingRequestWithNullPropertyName() {
         new CopyBranchRequest(validPathLocation, null);
     }
 

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RemovePropertiesRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -27,6 +27,7 @@
 import static org.junit.Assert.assertThat;
 import static org.junit.matchers.JUnitMatchers.hasItems;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import org.jboss.dna.graph.properties.Name;
 import org.junit.Before;
@@ -51,16 +52,46 @@
         validPropertyName3 = createName("foo3");
     }
 
+    @Override
+    protected Request createRequest() {
+        return new RemovePropertiesRequest(validPathLocation1, validPropertyName1);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+        new RemovePropertiesRequest(null, validPropertyName1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullPropertyName() {
+        new RemovePropertiesRequest(validPathLocation, (Name[])null);
     }
 
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameArray() {
+        new RemovePropertiesRequest(validPathLocation, new Name[] {});
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithNullPropertyNameIterator() {
+        new RemovePropertiesRequest(validPathLocation, (Iterator<Name>)null);
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameIterator() {
+        new RemovePropertiesRequest(validPathLocation, new ArrayList<Name>().iterator());
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithNullPropertyNameIterable() {
+        new RemovePropertiesRequest(validPathLocation, (Iterable<Name>)null);
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameIterable() {
+        new RemovePropertiesRequest(validPathLocation, new ArrayList<Name>());
+    }
+
     @Test
     public void shouldCreateValidRequestWithValidLocationAndValidPropertyName() {
         request = new RemovePropertiesRequest(validPathLocation1, validPropertyName1);

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/RenameNodeRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -44,14 +44,19 @@
         newName = createName("SomethingElse");
     }
 
+    @Override
+    protected Request createRequest() {
+        return new RenameNodeRequest(validPathLocation1, newName);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+        new RenameNodeRequest(null, newName);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullNewName() {
+        new RenameNodeRequest(validPathLocation1, null);
     }
 
     @Test

Modified: 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	2008-11-10 20:21:55 UTC (rev 617)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/UpdatePropertiesRequestTest.java	2008-11-10 23:57:53 UTC (rev 618)
@@ -27,6 +27,7 @@
 import static org.junit.Assert.assertThat;
 import static org.junit.matchers.JUnitMatchers.hasItems;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import org.jboss.dna.graph.properties.Property;
 import org.junit.Before;
@@ -45,16 +46,46 @@
         super.beforeEach();
     }
 
+    @Override
+    protected Request createRequest() {
+        return new UpdatePropertiesRequest(validPathLocation1, validProperty1);
+    }
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCreatingRequestWithNullFromLocation() {
-        new CopyBranchRequest(null, validPathLocation);
+        new UpdatePropertiesRequest(null, validProperty1);
     }
 
     @Test( expected = IllegalArgumentException.class )
-    public void shouldNotAllowCreatingRequestWithNullToLocation() {
-        new CopyBranchRequest(validPathLocation, null);
+    public void shouldNotAllowCreatingRequestWithNullPropertyName() {
+        new UpdatePropertiesRequest(validPathLocation, (Property[])null);
     }
 
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameArray() {
+        new UpdatePropertiesRequest(validPathLocation, new Property[] {});
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithNullPropertyNameIterator() {
+        new UpdatePropertiesRequest(validPathLocation, (Iterator<Property>)null);
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameIterator() {
+        new UpdatePropertiesRequest(validPathLocation, new ArrayList<Property>().iterator());
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithNullPropertyNameIterable() {
+        new UpdatePropertiesRequest(validPathLocation, (Iterable<Property>)null);
+    }
+
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowCreatingRequestWithEmptyPropertyNameIterable() {
+        new UpdatePropertiesRequest(validPathLocation, new ArrayList<Property>());
+    }
+
     @Test
     public void shouldCreateValidRequestWithValidLocationAndValidProperty() {
         request = new UpdatePropertiesRequest(validPathLocation1, validProperty1);




More information about the dna-commits mailing list