Author: fmeschbe
Date: Fri Feb 12 20:59:55 2010
New Revision: 909603

URL: http://svn.apache.org/viewvc?rev=909603&view=rev
Log:
SLING-1371 Apply patch by Simon Gaeremynck (thanks) adding more flesh to the 
mock bones

Modified:
    
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
    
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
    
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java

Modified: 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java?rev=909603&r1=909602&r2=909603&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
 (original)
+++ 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
 Fri Feb 12 20:59:55 2010
@@ -18,9 +18,13 @@
  */
 package org.apache.sling.commons.testing.jcr;
 
+import org.apache.jackrabbit.util.ChildrenCollectorFilter;
+
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Item;
@@ -49,6 +53,7 @@
     private Map <String, Property> properties = new HashMap <String, 
Property>();
 
     private NodeType nodeType;
+    private Session session;
 
     public MockNode(String path) {
         this(path, null);
@@ -173,8 +178,19 @@
         return new MockPropertyIterator(properties.values().iterator());
     }
 
-    public PropertyIterator getProperties(String namePattern) {
-        return null;
+    public PropertyIterator getProperties(String namePattern) throws 
RepositoryException {
+        PropertyIterator iterator = getProperties();
+        List<Property> properties = new ArrayList<Property>();
+    
+        while (iterator.hasNext()) {
+            Property p = iterator.nextProperty();
+            String name = p.getName();
+            if (ChildrenCollectorFilter.matches(name, namePattern)) {
+                properties.add(p);
+            }
+        }
+    
+        return new MockPropertyIterator(properties.iterator());
     }
 
     public Property getProperty(String relPath) {
@@ -251,12 +267,18 @@
     public void restoreByLabel(String versionLabel, boolean removeExisting) {
     }
 
-    public Property setProperty(String name, Value value) {
-        return null;
+    public Property setProperty(String name, Value value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
-    public Property setProperty(String name, Value[] values) {
-        return null;
+    public Property setProperty(String name, Value[] values) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(values);
+        properties.put(name, p);
+        return p;
     }
 
     public Property setProperty(String name, String[] values) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
@@ -273,24 +295,39 @@
         return p;
     }
 
-    public Property setProperty(String name, InputStream value) {
-        return null;
+    public Property setProperty(String name, InputStream value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
-    public Property setProperty(String name, boolean value) {
-        return null;
+    public Property setProperty(String name, boolean value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
-    public Property setProperty(String name, double value) {
-        return null;
+    public Property setProperty(String name, double value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
-    public Property setProperty(String name, long value) {
-        return null;
+    public Property setProperty(String name, long value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
-    public Property setProperty(String name, Calendar value) {
-        return null;
+    public Property setProperty(String name, Calendar value) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+        MockProperty p = new MockProperty(name);
+        p.setValue(value);
+        properties.put(name, p);
+        return p;
     }
 
     public Property setProperty(String name, Node value) {
@@ -331,7 +368,11 @@
     }
 
     public Session getSession() {
-        return null;
+        return this.session;
+    }
+    
+    public void setSession(Session session) {
+      this.session = session;
     }
 
     public boolean isModified() {

Modified: 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java?rev=909603&r1=909602&r2=909603&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
 (original)
+++ 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
 Fri Feb 12 20:59:55 2010
@@ -51,11 +51,17 @@
     }
     
     public boolean getBoolean() throws ValueFormatException, 
RepositoryException {
-        return false;
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0].getBoolean();
     }
 
     public Calendar getDate() throws ValueFormatException, RepositoryException 
{
-        return null;
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0].getDate();
     }
 
     public PropertyDefinition getDefinition() throws RepositoryException {
@@ -63,7 +69,10 @@
     }
 
     public double getDouble() throws ValueFormatException, RepositoryException 
{
-        return 0;
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0].getDouble();
     }
 
     public long getLength() throws ValueFormatException, RepositoryException {
@@ -75,7 +84,10 @@
     }
 
     public long getLong() throws ValueFormatException, RepositoryException {
-        return 0;
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0].getLong();
     }
 
     public Node getNode() throws ValueFormatException, RepositoryException {
@@ -83,7 +95,10 @@
     }
 
     public InputStream getStream() throws ValueFormatException, 
RepositoryException {
-        return null;
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0].getStream();
     }
 
     public String getString() throws ValueFormatException, RepositoryException 
{
@@ -96,7 +111,10 @@
     }
 
     public Value getValue() throws ValueFormatException, RepositoryException {
-        return new MockValue(getString());
+        if (values.length > 1) {
+            throw new ValueFormatException();
+        }
+        return values[0];
     }
 
     public Value[] getValues() throws ValueFormatException, 
RepositoryException {
@@ -105,22 +123,42 @@
 
     public void setValue(boolean value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      MockValue val = new MockValue();
+      val.setValue(value);
+      values = new MockValue[1];
+      values[0] = val;
     }
 
     public void setValue(Calendar value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      MockValue val = new MockValue();
+      val.setValue(value);
+      values = new MockValue[1];
+      values[0] = val;
     }
 
     public void setValue(double value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      MockValue val = new MockValue();
+      val.setValue(value);
+      values = new MockValue[1];
+      values[0] = val;
     }
 
     public void setValue(InputStream value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      MockValue val = new MockValue();
+      val.setValue(value);
+      values = new MockValue[1];
+      values[0] = val;
     }
 
     public void setValue(long value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      MockValue val = new MockValue();
+      val.setValue(value);
+      values = new MockValue[1];
+      values[0] = val;
     }
 
     public void setValue(Node value) throws ValueFormatException, 
VersionException, LockException,
@@ -129,13 +167,13 @@
 
     public void setValue(String value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
-        values =new Value[1];
+        values =new MockValue[1];
         values[0] = new MockValue(value);
     }
 
     public void setValue(String[] inputValues) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
-        this.values = new Value[inputValues.length];
+        this.values = new MockValue[inputValues.length];
         int i = 0;
         for(String str : inputValues) {
             values[i++] = new MockValue(str);
@@ -144,10 +182,13 @@
 
     public void setValue(Value value) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      values = new Value[1];
+      values[0] = value;
     }
 
     public void setValue(Value[] values) throws ValueFormatException, 
VersionException, LockException,
             ConstraintViolationException, RepositoryException {
+      this.values = values;
     }
 
     public void accept(ItemVisitor visitor) throws RepositoryException {

Modified: 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java?rev=909603&r1=909602&r2=909603&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
 (original)
+++ 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
 Fri Feb 12 20:59:55 2010
@@ -28,38 +28,72 @@
 
 public class MockValue implements Value {
 
-    private final String value;
+    private String stringValue;
+    private boolean booleanValue;
+    private Calendar calendarValue;
+    private double doubleValue;
+    private long longValue;
+    private InputStream stream;
+    private int propertyType;
+    
+    public MockValue() {
+    }
     
     public MockValue(String str) {
-        value = str;
+        stringValue = str;
+        propertyType = PropertyType.STRING;
     }
     
     public boolean getBoolean() throws ValueFormatException, 
IllegalStateException, RepositoryException {
-        return false;
+        return booleanValue;
     }
 
     public Calendar getDate() throws ValueFormatException, 
IllegalStateException, RepositoryException {
-        return null;
+        return calendarValue;
     }
 
     public double getDouble() throws ValueFormatException, 
IllegalStateException, RepositoryException {
-        return 0;
+        return doubleValue;
     }
 
     public long getLong() throws ValueFormatException, IllegalStateException, 
RepositoryException {
-        return 0;
+        return longValue;
     }
 
     public InputStream getStream() throws IllegalStateException, 
RepositoryException {
-        return null;
+        return stream;
     }
 
     public String getString() throws ValueFormatException, 
IllegalStateException, RepositoryException {
-        return value;
+        return stringValue;
     }
 
     public int getType() {
-        return PropertyType.STRING;
+        return propertyType;
+    }
+
+
+    public void setValue(String stringValue) {
+      this.stringValue = stringValue;
+    }
+
+    public void setValue(boolean booleanValue) {
+      this.booleanValue = booleanValue;
     }
 
+    public void setValue(Calendar calendarValue) {
+      this.calendarValue = calendarValue;
+    }
+
+    public void setValue(double doubleValue) {
+      this.doubleValue = doubleValue;
+    }
+
+    public void setValue(long longValue) {
+      this.longValue = longValue;
+    }
+
+    public void setValue(InputStream stream) {
+      this.stream = stream;
+    }
 }


Reply via email to