Author: niallp
Date: Sun Nov 27 11:28:37 2005
New Revision: 349285

URL: http://svn.apache.org/viewcvs?rev=349285&view=rev
Log:
Add JUnit test for CGLib enhanced DynaActionForm

Added:
    
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
   (with props)
Modified:
    
struts/action/trunk/src/test/org/apache/struts/action/TestDynaActionFormClass.java

Added: 
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
URL: 
http://svn.apache.org/viewcvs/struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java?rev=349285&view=auto
==============================================================================
--- 
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
 (added)
+++ 
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
 Sun Nov 27 11:28:37 2005
@@ -0,0 +1,245 @@
+/*
+ * $Id$ 
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts.action;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Suite of unit tests for the
+ * <code>org.apache.struts.action.DynaActionForm</code> class.
+ */
+public class TestCGLibDynaActionForm extends TestDynaActionForm {
+
+
+    /**
+     * Defines the testcase name for JUnit.
+     *
+     * @param theName the testcase's name.
+     */
+    public TestCGLibDynaActionForm(String theName)
+    {
+        super(theName);
+    }
+
+
+    /**
+     * Start the tests.
+     *
+     * @param theArgs the arguments. Not used
+     */
+    public static void main(String[] theArgs)
+    {
+        junit.awtui.TestRunner.main
+            (new String[] {TestCGLibDynaActionForm.class.getName()});
+    }
+
+
+    /**
+     * @return a test suite (<code>TestSuite</code>) that includes all methods
+     *         starting with "test"
+     */
+    public static Test suite()
+    {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(TestCGLibDynaActionForm.class);
+    }
+
+
+    // ----------------------------------------------------- Setup and Teardown
+
+
+    public void setUp() {
+        enhanced = true;
+
+        super.setUp();
+
+    }
+
+
+    public void tearDown() {
+
+        super.tearDown();
+    }
+
+
+    // --------------------------------------------- Create New DynaActionForms
+
+
+    /**
+     * Test simple read property
+     */
+    public void testSimpleRead() {
+
+        String property   = "floatProperty";
+        String methodName = getMethodName(property, true);
+        Class[] types = null;
+        Object[] args = null;
+
+
+        Object expected = dynaForm.get(property);
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            Object result = method.invoke(dynaForm, args);
+            assertEquals(expected, result);
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+    }
+
+    /**
+     * Test simple write property
+     */
+    public void testSimpleWrite() {
+
+        String property   = "floatProperty";
+        String methodName = getMethodName(property, false);
+        Object expected = new Float("5.4321");
+        Class[] types = new Class[]{Float.TYPE};
+        Object[] args = new Object[] {expected};
+
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            method.invoke(dynaForm, args);
+            assertEquals(expected, dynaForm.get(property));
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+    }
+
+    /**
+     * Test simple write property
+     */
+    public void testIndexedRead() {
+
+        String property   = "stringArray";
+        String methodName = getMethodName(property, true);
+        Integer idx = new Integer(1);
+        Class[] types = new Class[] {Integer.TYPE};
+        Object[] args = new Object[] {idx};
+
+        Object expected = dynaForm.get(property, idx.intValue());
+        
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            Object result = method.invoke(dynaForm, args);
+            assertEquals(expected, result);
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+        
+
+    }
+
+    /**
+     * Test indexed write property
+     */
+    public void testIndexedWrite() {
+
+        String property   = "stringArray";
+        String methodName = getMethodName(property, false);
+        Integer idx = new Integer(1);
+        Object expected = "some new value";
+        Class[] types = new Class[] {Integer.TYPE, String.class};
+        Object[] args = new Object[] {idx, expected};
+
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            method.invoke(dynaForm, args);
+            assertEquals(expected, dynaForm.get(property, idx.intValue()));
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+        
+
+    }
+
+    /**
+     * Test simple write property
+     */
+    public void testIndexedReadInt() {
+
+        String property   = "intIndexed";
+        String methodName = getMethodName(property, true);
+        Integer idx = new Integer(1);
+        Class[] types = new Class[] {Integer.TYPE};
+        Object[] args = new Object[] {idx};
+
+        Object expected = dynaForm.get(property, idx.intValue());
+        
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            Object result = method.invoke(dynaForm, args);
+            assertEquals(expected, result);
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+        
+
+    }
+
+    /**
+     * Test indexed write property
+     */
+    public void testIndexedWriteInt() {
+
+        String property   = "intIndexed";
+        String methodName = getMethodName(property, false);
+        Integer idx = new Integer(1);
+        Object expected = new Integer(54321);
+        Class[] types = new Class[] {Integer.TYPE, Integer.TYPE};
+        Object[] args = new Object[] {idx, expected};
+
+        try {
+            Method method = dynaForm.getClass().getMethod(methodName, types);
+            method.invoke(dynaForm, args);
+            assertEquals(expected, dynaForm.get(property, idx.intValue()));
+        } catch(InvocationTargetException e) {
+            fail("InvocationTargetException thrown " + e.getCause());
+        } catch(Exception e) {
+            fail("Exception thrown " + e);
+        }
+
+    }
+
+    private String getMethodName(String property, boolean getter) {
+        String methodName = (getter ? "get" : "set") +
+                             property.substring(0, 1).toUpperCase() +
+                             property.substring(1);
+        return methodName;
+    }
+
+    
+
+
+}
+
+

Propchange: 
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
struts/action/trunk/src/test/org/apache/struts/action/TestCGLibDynaActionForm.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
struts/action/trunk/src/test/org/apache/struts/action/TestDynaActionFormClass.java
URL: 
http://svn.apache.org/viewcvs/struts/action/trunk/src/test/org/apache/struts/action/TestDynaActionFormClass.java?rev=349285&r1=349284&r2=349285&view=diff
==============================================================================
--- 
struts/action/trunk/src/test/org/apache/struts/action/TestDynaActionFormClass.java
 (original)
+++ 
struts/action/trunk/src/test/org/apache/struts/action/TestDynaActionFormClass.java
 Sun Nov 27 11:28:37 2005
@@ -1,7 +1,7 @@
 /*
  * $Id$ 
  *
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -79,6 +79,10 @@
      */
     protected DynaActionFormClass dynaClass = null;
 
+    /**
+     * Whether an "Enhanced" DynaActionForm is created.
+     */
+    protected boolean enhanced = false;
 
     /**
      * The set of <code>FormPropertyConfig</code> objects to use when
@@ -118,6 +122,7 @@
         beanConfig = new FormBeanConfig();
         beanConfig.setName("dynaForm");
         beanConfig.setType("org.apache.struts.action.DynaActionForm");
+        beanConfig.setEnhanced(enhanced);
 
         // Add relevant property definitions
         for (int i = 0; i < dynaProperties.length; i++) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to