You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2006/02/09 02:10:35 UTC

svn commit: r376140 - in /struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock: MockFacesContext.java MockPropertyResolver.java MockServlet.java MockValueBinding.java

Author: craigmcc
Date: Wed Feb  8 17:10:34 2006
New Revision: 376140

URL: http://svn.apache.org/viewcvs?rev=376140&view=rev
Log:
Clean up several more unsupported operations on the mock classes.  In
particular, the isReadonly() and getType() calls on property resolver now
work, so they will work on value bindings and method bindings as well.

Modified:
    struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockFacesContext.java
    struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockPropertyResolver.java
    struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServlet.java
    struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockValueBinding.java

Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockFacesContext.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockFacesContext.java?rev=376140&r1=376139&r2=376140&view=diff
==============================================================================
--- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockFacesContext.java (original)
+++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockFacesContext.java Wed Feb  8 17:10:34 2006
@@ -120,8 +120,18 @@
 
 
     public Severity getMaximumSeverity() {
-  
-        throw new UnsupportedOperationException();
+
+        Severity severity = null;
+        Iterator messages = getMessages();
+        while (messages.hasNext()) {
+            FacesMessage message = (FacesMessage) messages.next();
+            if (severity == null) {
+                severity = message.getSeverity();
+            } else if (message.getSeverity().getOrdinal() > severity.getOrdinal()) {
+                severity = message.getSeverity();
+            }
+        }
+        return severity;
 
     }
 

Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockPropertyResolver.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockPropertyResolver.java?rev=376140&r1=376139&r2=376140&view=diff
==============================================================================
--- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockPropertyResolver.java (original)
+++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockPropertyResolver.java Wed Feb  8 17:10:34 2006
@@ -16,6 +16,7 @@
 
 package org.apache.shale.test.mock;
 
+import java.beans.PropertyDescriptor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 
@@ -28,10 +29,6 @@
 /**
  * <p>Mock implementation of <code>PropertyResolver</code>.</p>
  *
- * <p>This implementation supports only getValue() and setValue(), to the
- * extent that <code>PropertyUtils.getSimpleProperty()</code> and
- * <code>PropertyUtils.setSimpleProperty()</code> execute correctly.</p>
- *
  * $Id$
  */
 
@@ -89,7 +86,7 @@
     public Object getValue(Object base, int index)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        return getValue(base, "" + index);
 
     }
 
@@ -121,7 +118,7 @@
     public void setValue(Object base, int index, Object value)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        setValue(base, "" + index, value);
 
     }
 
@@ -129,7 +126,11 @@
     public boolean isReadOnly(Object base, Object property)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        if (base == null) {
+            throw new NullPointerException();
+        }
+	String name = property.toString();
+        return !PropertyUtils.isWriteable(base, name);
 
     }
 
@@ -137,7 +138,7 @@
     public boolean isReadOnly(Object base, int index)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        return isReadOnly(base, "" + index);
 
     }
 
@@ -145,7 +146,19 @@
     public Class getType(Object base, Object property)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        if (base == null) {
+            throw new NullPointerException();
+        }
+	String name = property.toString();
+        try {
+            return PropertyUtils.getPropertyType(base, name);
+        } catch (IllegalAccessException e) {
+            throw new EvaluationException(e);
+        } catch (InvocationTargetException e) {
+            throw new EvaluationException(e.getTargetException());
+        } catch (NoSuchMethodException e) {
+            throw new PropertyNotFoundException(name);
+        }
 
     }
 
@@ -153,7 +166,7 @@
     public Class getType(Object base, int index)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        return getType(base, "" + index);
 
     }
 

Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServlet.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServlet.java?rev=376140&r1=376139&r2=376140&view=diff
==============================================================================
--- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServlet.java (original)
+++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockServlet.java Wed Feb  8 17:10:34 2006
@@ -93,7 +93,7 @@
     public void service(ServletRequest request, ServletResponse response)
       throws IOException, ServletException {
 
-        throw new UnsupportedOperationException();
+        ; // Do nothing by default
 
     }
 

Modified: struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockValueBinding.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockValueBinding.java?rev=376140&r1=376139&r2=376140&view=diff
==============================================================================
--- struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockValueBinding.java (original)
+++ struts/shale/trunk/test-framework/src/java/org/apache/shale/test/mock/MockValueBinding.java Wed Feb  8 17:10:34 2006
@@ -34,15 +34,6 @@
 
 /**
  * <p>Mock implementation of <code>ValueBinding</code>.</p>
- *
- * <p>This implementation is subject to the following restrictions:</p>
- * <ul>
- * <li>Looking up the first name via the configured <code>VariableResolver</code>
- *     (which is also limited in capability).</li>
- * <li>Resolving the "." operator via the configured
- *     <code>PropertyResolver</code>.</li>
- * <li>Supports only <code>getValue()</code> and <code>setValue()</code>.</li>
- * </ul>
  */
 
 public class MockValueBinding extends ValueBinding implements StateHolder {
@@ -173,7 +164,27 @@
     public boolean isReadOnly(FacesContext context)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        if (context == null) {
+            throw new NullPointerException();
+        }
+        List names = parse(ref);
+
+        // Resolve the variable name
+        VariableResolver vr = application().getVariableResolver();
+        String name = (String) names.get(0);
+        Object base = vr.resolveVariable(context, name);
+        if (names.size() < 2) {
+            return true;
+        }
+
+        // Resolve the property names
+        PropertyResolver pr = application().getPropertyResolver();
+        for (int i = 1; i < names.size() - 1; i++) {
+            base = pr.getValue(base, (String) names.get(i));
+        }
+
+        // Return the read only state of the final property
+        return pr.isReadOnly(base, (String) names.get(names.size() - 1));
 
     }
 
@@ -181,7 +192,27 @@
     public Class getType(FacesContext context)
         throws PropertyNotFoundException {
 
-        throw new UnsupportedOperationException();
+        if (context == null) {
+            throw new NullPointerException();
+        }
+        List names = parse(ref);
+
+        // Resolve the variable name
+        VariableResolver vr = application().getVariableResolver();
+        String name = (String) names.get(0);
+        Object base = vr.resolveVariable(context, name);
+        if (names.size() < 2) {
+            return base.getClass();
+        }
+
+        // Resolve the property names
+        PropertyResolver pr = application().getPropertyResolver();
+        for (int i = 1; i < names.size() - 1; i++) {
+            base = pr.getValue(base, (String) names.get(i));
+        }
+
+        // Return the type of the final property
+        return pr.getType(base, (String) names.get(names.size() - 1));
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org