Author: hrabago
Date: Sat Apr  2 12:03:36 2005
New Revision: 159810

URL: http://svn.apache.org/viewcvs?view=rev&rev=159810
Log:
Tests for config inheritance changes.

Added:
    struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java   
(with props)
    struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java 
  (with props)
    
struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java 
  (with props)
    struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java  
 (with props)

Added: struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java?view=auto&rev=159810
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java 
(added)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java 
Sat Apr  2 12:03:36 2005
@@ -0,0 +1,306 @@
+/*
+ * $Id$ 
+ *
+ * Copyright 1999-2004 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.config;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Unit tests for the <code>org.apache.struts.config.ActionConfig</code> 
+ * class.  Currently only contains code to test the methods that support
+ * configuration inheritance.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TestActionConfig 
+        extends TestCase {
+    
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * The ModuleConfig we'll use.
+     */
+    protected ModuleConfig config = null;
+
+
+    /**
+     * The common base we'll use.
+     */ 
+    protected ActionConfig baseConfig = null;
+    
+    
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public TestActionConfig(String name) {
+
+        super(name);
+
+    }
+
+
+    // --------------------------------------------------------- Public Methods
+
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+        
+        ModuleConfigFactory factoryObject =
+            ModuleConfigFactory.createFactory();
+        config = factoryObject.createModuleConfig("");
+
+        // setup the base form
+        baseConfig = new ActionConfig();
+        baseConfig.setPath("/base");
+        baseConfig.setType("org.apache.struts.actions.DummyAction");        
+        
+        // set up success and failure forward
+        ForwardConfig forward = new 
ForwardConfig("success","/success.jsp",false);
+        baseConfig.addForwardConfig(forward);
+        
+        forward = new ForwardConfig("failure","/failure.jsp",false);
+        baseConfig.addForwardConfig(forward);
+        
+        // setup an exception handler
+        ExceptionConfig exceptionConfig = new ExceptionConfig();
+        exceptionConfig.setType("java.sql.SQLException");
+        exceptionConfig.setKey("msg.exception.sql");
+        baseConfig.addExceptionConfig(exceptionConfig);
+        
+        // register it to our config
+        config.addActionConfig(baseConfig);
+    }
+
+
+    /**
+     * Return the tests included in this test suite.
+     */
+    public static Test suite() {
+
+        return (new TestSuite(TestActionConfig.class));
+
+    }
+
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+
+        config = null;
+        baseConfig = null;
+        
+    }
+
+    
+    
+    // ------------------------------------------------------- Individual Tests
+
+    
+    /**
+     * Basic check that shouldn't detect circular inheritance.
+     */ 
+    public void testCheckCircularInheritance() {
+        ActionConfig child = new ActionConfig();
+        child.setPath("/child");
+        child.setExtends("/base");
+        
+        ActionConfig grandChild = new ActionConfig();
+        grandChild.setPath("/grandChild");
+        grandChild.setExtends("/child");
+        
+        config.addActionConfig(child);
+        config.addActionConfig(grandChild);
+        
+        assertTrue("Circular inheritance shouldn't have been detected",
+                !grandChild.checkCircularInheritance(config));
+    }
+    
+    
+    /**
+     * Basic check that should detect circular inheritance.
+     */ 
+    public void testCheckCircularInheritanceError() {
+        ActionConfig child = new ActionConfig();
+        child.setPath("/child");
+        child.setExtends("/base");
+        
+        ActionConfig grandChild = new ActionConfig();
+        grandChild.setPath("/grandChild");
+        grandChild.setExtends("/child");
+
+        // establish the circular relationship with base
+        baseConfig.setExtends("/grandChild");
+        
+        config.addActionConfig(child);
+        config.addActionConfig(grandChild);
+        
+        assertTrue("Circular inheritance should've been detected",
+                grandChild.checkCircularInheritance(config));
+    }
+    
+    
+    /**
+     * Test that processExtends() makes sure that a base action's own
+     * extension has been processed.
+     */ 
+    public void testProcessExtendsActionExtends() 
+            throws Exception {
+        
+        CustomActionConfig first = new CustomActionConfig();
+        first.setPath("/first");
+        
+        CustomActionConfig second = new CustomActionConfig();
+        second.setPath("/second");
+        second.setExtends("/first");
+        
+        config.addActionConfig(first);
+        config.addActionConfig(second);
+        
+        // set baseConfig to extend second
+        baseConfig.setExtends("/second");
+        
+        baseConfig.processExtends(config);
+        
+        assertTrue("The first action's processExtends() wasn't called",
+                first.processExtendsCalled);
+        assertTrue("The second action's processExtends() wasn't called",
+                second.processExtendsCalled);
+    }
+    
+    
+    /**
+     * Make sure that correct exception is thrown if a base action can't be
+     * found.
+     */ 
+    public void testProcessExtendsMissingAction() 
+            throws Exception {
+        
+        baseConfig.setExtends("/someMissingAction");
+        try {
+            baseConfig.processExtends(config);
+            fail("An exception should be thrown if a super form can't be 
found.");
+        } catch (NullPointerException e) {
+            // succeed
+        } catch (InstantiationException e) {
+            fail("Unrecognized exception thrown.");
+        }
+    
+    }
+    
+    
+    /**
+     * Test a typical form bean configuration extension where various
+     * forwards and exception handlers should be inherited from a base form.  
+     * This method checks all the subelements.
+     */ 
+    public void testInheritFrom() 
+            throws Exception {
+        
+        // create a basic subform
+        ActionConfig subConfig = new ActionConfig();
+        String subConfigPath = "subConfig";
+        subConfig.setPath(subConfigPath);
+        subConfig.setExtends("/base");
+        
+        // override success
+        ForwardConfig forward = new ForwardConfig();
+        forward.setName("success");
+        forward.setPath("/newSuccess.jsp");
+        forward.setRedirect(true);
+        subConfig.addForwardConfig(forward);
+        
+        // add an exception handler
+        ExceptionConfig handler = new ExceptionConfig();
+        handler.setType("java.lang.NullPointerException");
+        handler.setKey("msg.exception.npe");
+        subConfig.addExceptionConfig(handler);
+        
+        config.addActionConfig(subConfig);
+        
+        subConfig.inheritFrom(baseConfig);
+        
+        // check that our subConfig is still the one in the config
+        assertSame("subConfig no longer in ModuleConfig",
+                subConfig, config.findActionConfig("subConfig"));
+        
+        // check our configured sub config
+        assertNotNull("Action type was not inherited", subConfig.getType());
+        assertEquals("Wrong config path", subConfigPath, subConfig.getPath());
+        assertEquals("Wrong config type", baseConfig.getType(), 
subConfig.getType());
+        
+        // check our forwards
+        ForwardConfig[] forwards = subConfig.findForwardConfigs();
+        assertEquals("Wrong forwards count", 2, forwards.length);
+    
+        forward = subConfig.findForwardConfig("success");
+        assertNotNull("'success' forward was not found", forward);
+        assertEquals("Wrong path for success", "/newSuccess.jsp", 
+                forward.getPath());
+        
+        forward = subConfig.findForwardConfig("failure");
+        ForwardConfig origForward = baseConfig.findForwardConfig("failure");
+        assertNotNull("'failure' forward was not inherited", forward);
+        assertEquals("Wrong type for 'failure'", origForward.getPath(), 
+                forward.getPath());
+        
+        // check our exceptions 
+        ExceptionConfig[] handlers = subConfig.findExceptionConfigs();
+        assertEquals("Wrong exception config count", 2, handlers.length);
+    
+        handler = subConfig.findExceptionConfig("java.sql.SQLException");
+        ExceptionConfig origHandler = 
subConfig.findExceptionConfig("java.sql.SQLException"); 
+        assertNotNull("'SQLException' handler was not found", handler);
+        assertEquals("Wrong key for 'SQLException'", origHandler.getKey(), 
+                handler.getKey());
+        
+        handler = 
subConfig.findExceptionConfig("java.lang.NullPointerException");
+        assertNotNull("'NullPointerException' handler disappeared",
+                handler);
+    }
+    
+    
+    /**
+     * Used to detect that ActionConfig is making the right calls.
+     */ 
+    public static class CustomActionConfig
+            extends ActionConfig {
+        
+        boolean processExtendsCalled = false;
+
+        public void processExtends(ModuleConfig moduleConfig) 
+                throws ClassNotFoundException, IllegalAccessException, 
InstantiationException, InvocationTargetException {
+            super.processExtends(moduleConfig);
+            processExtendsCalled = true;
+        }
+    }
+
+    
+}

Propchange: 
struts/core/trunk/src/test/org/apache/struts/config/TestActionConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java?view=auto&rev=159810
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java 
(added)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java 
Sat Apr  2 12:03:36 2005
@@ -0,0 +1,421 @@
+/*
+ * $Id$ 
+ *
+ * Copyright 1999-2004 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.config;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Unit tests for the <code>org.apache.struts.config.FormBeanConfig</code> 
+ * class.  Currently only contains code to test the methods that support
+ * configuration inheritance.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TestFormBeanConfig 
+        extends TestCase {
+    
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * The ModuleConfig we'll use.
+     */
+    protected ModuleConfig config = null;
+
+
+    /**
+     * The common base we'll use.
+     */ 
+    protected FormBeanConfig baseForm = null;
+    
+    
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public TestFormBeanConfig(String name) {
+
+        super(name);
+
+    }
+
+
+    // --------------------------------------------------------- Public Methods
+
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+        
+        ModuleConfigFactory factoryObject =
+            ModuleConfigFactory.createFactory();
+        config = factoryObject.createModuleConfig("");
+
+        // setup the base form
+        baseForm = new FormBeanConfig();
+        baseForm.setName("baseForm");
+        baseForm.setType("org.apache.struts.action.DynaActionForm");
+        
+        // set up id, name, and score
+        FormPropertyConfig property = new FormPropertyConfig();
+        property.setName("id");
+        property.setType("java.lang.String");
+        baseForm.addFormPropertyConfig(property);
+
+        property = new FormPropertyConfig();
+        property.setName("name");
+        property.setType("java.lang.String");
+        baseForm.addFormPropertyConfig(property);
+        
+        property = new FormPropertyConfig();
+        property.setName("score");
+        property.setType("java.lang.String");
+        baseForm.addFormPropertyConfig(property);
+        
+        property = new FormPropertyConfig();
+        property.setName("message");
+        property.setType("java.lang.String");
+        baseForm.addFormPropertyConfig(property);
+        
+        // register it to our config
+        config.addFormBeanConfig(baseForm);
+    }
+
+
+    /**
+     * Return the tests included in this test suite.
+     */
+    public static Test suite() {
+
+        return (new TestSuite(TestFormBeanConfig.class));
+
+    }
+
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+
+        config = null;
+        baseForm = null;
+        
+    }
+
+    
+    
+    // ------------------------------------------------------- Individual Tests
+
+    
+    /**
+     * Basic check that shouldn't detect an error.
+     */ 
+    public void testCheckCircularInheritance() {
+        FormBeanConfig child = new FormBeanConfig();
+        child.setName("child");
+        child.setExtends("baseForm");
+        
+        FormBeanConfig grandChild = new FormBeanConfig();
+        grandChild.setName("grandChild");
+        grandChild.setExtends("child");
+        
+        config.addFormBeanConfig(child);
+        config.addFormBeanConfig(grandChild);
+        
+        assertTrue("Circular inheritance shouldn't have been detected",
+                !grandChild.checkCircularInheritance(config));
+    }
+    
+    
+    /**
+     * Basic check that SHOULD detect an error.
+     */ 
+    public void testCheckCircularInheritanceError() {
+        FormBeanConfig child = new FormBeanConfig();
+        child.setName("child");
+        child.setExtends("baseForm");
+        
+        FormBeanConfig grandChild = new FormBeanConfig();
+        grandChild.setName("grandChild");
+        grandChild.setExtends("child");
+        
+        // establish the circular relationship with base
+        baseForm.setExtends("grandChild");
+        
+        config.addFormBeanConfig(child);
+        config.addFormBeanConfig(grandChild);
+        
+        assertTrue("Circular inheritance should've been detected",
+                grandChild.checkCircularInheritance(config));
+    }
+    
+    
+    /**
+     * Test that processExtends() makes sure that a base form's own
+     * extension has been processed.
+     */ 
+    public void testProcessExtendsBaseFormExtends() 
+            throws Exception {
+        
+        CustomFormBeanConfig first = new CustomFormBeanConfig();
+        first.setName("first");
+        
+        CustomFormBeanConfig second = new CustomFormBeanConfig();
+        second.setName("second");
+        second.setExtends("first");
+        
+        config.addFormBeanConfig(first);
+        config.addFormBeanConfig(second);
+        
+        // set baseForm to extend second
+        baseForm.setExtends("second");
+        
+        baseForm.processExtends(config);
+        
+        assertTrue("The first form's processExtends() wasn't called",
+                first.processExtendsCalled);
+        assertTrue("The second form's processExtends() wasn't called",
+                second.processExtendsCalled);
+    }
+    
+    
+    /**
+     * Make sure that correct exception is thrown if a base form can't be
+     * found.
+     */ 
+    public void testProcessExtendsMissingBaseForm() 
+            throws Exception {
+        
+        baseForm.setExtends("someMissingForm");
+        try {
+            baseForm.processExtends(config);
+            fail("An exception should be thrown if a super form can't be 
found.");
+        } catch (NullPointerException e) {
+            // succeed
+        } catch (InstantiationException e) {
+            fail("Unrecognized exception thrown.");
+        }
+
+    }
+    
+    
+    /**
+     * Test a typical form bean configuration extension where various
+     * properties should be inherited from a base form.  This method checks
+     * all the properties.
+     */ 
+    public void testInheritFrom() 
+            throws Exception {
+        
+        // create a basic subform
+        FormBeanConfig subForm = new FormBeanConfig();
+        String subFormName = "subForm";
+        subForm.setName(subFormName);
+        subForm.setExtends("baseForm");
+        
+        // override score
+        FormPropertyConfig property = new FormPropertyConfig();
+        property.setName("score");
+        property.setType("java.lang.Integer");
+        subForm.addFormPropertyConfig(property);
+        
+        // ... and id 
+        property = new FormPropertyConfig();
+        property.setName("id");
+        property.setType("java.lang.String");
+        property.setInitial("unknown");
+        subForm.addFormPropertyConfig(property);
+        
+        // ... and message
+        property = new FormPropertyConfig();
+        property.setName("message");
+        property.setType("java.lang.String");
+        property.setSize(10);
+        subForm.addFormPropertyConfig(property);
+        
+
+        config.addFormBeanConfig(subForm);
+        
+        subForm.inheritFrom(baseForm);
+        
+        // check that our subForm is still the one in the config
+        assertSame("subForm no longer in ModuleConfig",
+                subForm, config.findFormBeanConfig("subForm"));
+        
+        // check our configured sub form
+        assertNotNull("Form bean type was not inherited", subForm.getType());
+        assertEquals("Wrong form bean name", subFormName, subForm.getName());
+        assertEquals("Wrong form bean type", baseForm.getType(), 
subForm.getType());
+        assertEquals("Wrong restricted value", 
+                baseForm.isRestricted(), subForm.isRestricted());
+        
+        FormPropertyConfig[] formPropertyConfigs = 
subForm.findFormPropertyConfigs();
+        assertEquals("Wrong prop count", 4, formPropertyConfigs.length);
+
+        // we want to check that the form is EXACTLY as we want it, so
+        //  here are some fine grain checks
+        property = subForm.findFormPropertyConfig("name");
+        FormPropertyConfig original = baseForm.findFormPropertyConfig("name");
+        assertNotNull("'name' property was not inherited", property);
+        assertEquals("Wrong type for name", original.getType(), 
+                property.getType());
+        assertEquals("Wrong initial value for name", original.getInitial(),
+                property.getInitial());
+        assertEquals("Wrong size value for name", original.getSize(),
+                property.getSize());
+        
+        property = subForm.findFormPropertyConfig("id");
+        original = baseForm.findFormPropertyConfig("id");
+        assertNotNull("'id' property was not found", property);
+        assertEquals("Wrong type for id", original.getType(), 
+                property.getType());
+        assertEquals("Wrong initial value for id", "unknown",
+                property.getInitial());
+        assertEquals("Wrong size value for id", original.getSize(),
+                property.getSize());
+        
+        property = subForm.findFormPropertyConfig("score");
+        original = baseForm.findFormPropertyConfig("score");
+        assertNotNull("'score' property was not found", property);
+        assertEquals("Wrong type for score", "java.lang.Integer", 
+                property.getType());
+        assertEquals("Wrong initial value for score", original.getInitial(),
+                property.getInitial());
+        assertEquals("Wrong size value for score", original.getSize(),
+                property.getSize());
+        
+        property = subForm.findFormPropertyConfig("message");
+        original = baseForm.findFormPropertyConfig("message");
+        assertNotNull("'message' property was not found", property);
+        assertEquals("Wrong type for message", original.getType(), 
+                property.getType());
+        assertEquals("Wrong initial value for message", original.getInitial(),
+                property.getInitial());
+        assertEquals("Wrong size value for message", 10, property.getSize());
+    }
+    
+    
+    ///**
+    // * Test that a subform's property is changed to use the correct 
+    // * FormPropertyConfig subclass if a superform's prop class is overridden.
+    // * Also test that the subclass' inheritFrom() gets called, and that
+    // * overridden values are retained, even when a prop's class is changed.
+    // */ 
+    //public void testInheritFromCustomFormProperty() 
+    //        throws Exception {
+    //
+    //
+    //    // Modify baseForm, changing 2 props to use a custom config object
+    //    FormPropertyConfig id = baseForm.findFormPropertyConfig("id");
+    //    CustomFormPropertyConfig customId = new CustomFormPropertyConfig();
+    //    customId.setName(id.getName());
+    //    customId.setType(id.getType());
+    //    customId.setInitial(id.getInitial());
+    //    customId.setSize(id.getSize());
+    //    customId.integer = 12;
+    //    baseForm.removeFormPropertyConfig(id);
+    //    baseForm.addFormPropertyConfig(customId);
+    //    
+    //    FormPropertyConfig name = baseForm.findFormPropertyConfig("name");
+    //    CustomFormPropertyConfig customName = new CustomFormPropertyConfig();
+    //    customName.setName(name.getName());
+    //    customName.setType(name.getType());
+    //    customName.setInitial(name.getInitial());
+    //    customName.setSize(name.getSize());
+    //    baseForm.removeFormPropertyConfig(name);
+    //    baseForm.addFormPropertyConfig(customName);
+    //    
+    //    // Create our subform
+    //    FormBeanConfig subForm = new FormBeanConfig();
+    //    String subFormName = "subForm";
+    //    subForm.setName(subFormName);
+    //    subForm.setExtends("baseForm");
+    //    
+    //    // Add an "id" prop with some overridden values
+    //    FormPropertyConfig property = new FormPropertyConfig();
+    //    property.setName("id");
+    //    property.setType("java.lang.Integer");  
+    //    subForm.addFormPropertyConfig(property);
+    //    
+    //    // The "name" property isn't overridden and won't be configured
+    //    
+    //    // now let's run this thing
+    //    subForm.inheritFrom(baseForm);
+    //    
+    //    // Let's see what we have
+    //    
+    //    FormPropertyConfig subId = subForm.findFormPropertyConfig("id");
+    //    assertTrue("Incorrect form property class",
+    //            subId instanceof CustomFormPropertyConfig);
+    //    
+    //    assertEquals("An overridden value was lost", 
+    //            "java.lang.Integer", subId.getType());
+    //    
+    //    assertEquals("Custom class' inheritFrom() was not called.", 12, 
+    //            ((CustomFormPropertyConfig) subId).integer);
+    //
+    //    FormPropertyConfig subName = subForm.findFormPropertyConfig("name");
+    //    assertTrue("Incorrect form property class",
+    //            subName instanceof CustomFormPropertyConfig);
+    //}
+    
+    
+    /**
+     * Used to detect that FormBeanConfig is making the right calls.
+     */ 
+    public static class CustomFormBeanConfig 
+            extends FormBeanConfig {
+        
+        boolean processExtendsCalled = false;
+
+        public void processExtends(ModuleConfig moduleConfig) 
+                throws ClassNotFoundException, IllegalAccessException, 
InstantiationException, InvocationTargetException {
+            super.processExtends(moduleConfig);
+            processExtendsCalled = true;
+        }
+    }
+
+    
+    ///**
+    // * Used to test custom FormPropertyConfig classes.
+    // */ 
+    //public static class CustomFormPropertyConfig 
+    //        extends FormPropertyConfig {
+    //    
+    //    int integer = 0;
+    //
+    //    public void inheritFrom(FormPropertyConfig config) {
+    //        super.inheritFrom(config);
+    //        if (config instanceof CustomFormPropertyConfig) {
+    //            this.integer = ((CustomFormPropertyConfig) config).integer;
+    //        }
+    //    }
+    //
+    //}
+    
+}

Propchange: 
struts/core/trunk/src/test/org/apache/struts/config/TestFormBeanConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java?view=auto&rev=159810
==============================================================================
--- 
struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java 
(added)
+++ 
struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java 
Sat Apr  2 12:03:36 2005
@@ -0,0 +1,99 @@
+package org.apache.struts.config;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the <code>org.apache.struts.config.FormPropertyConfig</code> 
+ * class.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TestFormPropertyConfig 
+        extends TestCase {
+    
+    
+    public void testBasicInherit() {
+        FormPropertyConfig base = 
+                new FormPropertyConfig("base", "java.lang.String[]", "", 10);
+        
+        FormPropertyConfig sub = new FormPropertyConfig();
+        sub.setName("base");
+        
+        sub.inheritFrom(base);
+        
+        assertEquals("Type was not inherited", base.getType(), sub.getType());
+        assertEquals("Initial is incorrect", 
+                base.getInitial(), sub.getInitial());
+        assertEquals("Size was not inherited", base.getSize(), sub.getSize()); 
       
+    }
+    
+    public void testInheritWithInitialOverride() {
+        FormPropertyConfig base = 
+                new FormPropertyConfig("base", "java.lang.String", "value");
+        
+        FormPropertyConfig sub = new FormPropertyConfig();
+        sub.setName("base");
+        String initial = "otherValue";
+        sub.setInitial(initial);
+        
+        sub.inheritFrom(base);
+        
+        assertEquals("Type was not inherited", base.getType(), sub.getType());
+        assertEquals("Initial is incorrect", 
+                initial, sub.getInitial());
+        assertEquals("Size is incorrect", base.getSize(), sub.getSize());      
  
+    }
+                
+    public void testInheritWithTypeOverride() {
+        FormPropertyConfig base = 
+                new FormPropertyConfig("base", "java.lang.String", "");
+        
+        FormPropertyConfig sub = new FormPropertyConfig();
+        sub.setName("base");
+        sub.setType("java.lang.Integer");
+        
+        sub.inheritFrom(base);
+        
+        assertEquals("Type is incorrect", "java.lang.Integer", sub.getType());
+        assertEquals("Initial is incorrect", 
+                base.getInitial(), sub.getInitial());
+        assertEquals("Size is incorrect", base.getSize(), sub.getSize());      
  
+    }
+    
+    public void testInheritWithTypeOverride2() {
+        FormPropertyConfig base = 
+                new FormPropertyConfig("base", "java.lang.String", "");
+        
+        FormPropertyConfig sub = new FormPropertyConfig();
+        sub.setName("base");
+        String type = "java.lang.Integer[]";
+        int size = 10;
+        sub.setType(type);
+        sub.setSize(size);
+        
+        sub.inheritFrom(base);
+        
+        assertEquals("Type is incorrect", type, sub.getType());
+        assertEquals("Initial is incorrect", 
+                base.getInitial(), sub.getInitial());
+        assertEquals("Size is incorrect", size, sub.getSize());        
+    }
+    
+    public void testInheritWithSizeOverride() {
+        FormPropertyConfig base = 
+                new FormPropertyConfig("base", "java.lang.String[]", "", 20);
+        
+        FormPropertyConfig sub = new FormPropertyConfig();
+        sub.setName("base");
+        int size = 50;
+        sub.setSize(size);
+        
+        sub.inheritFrom(base);
+        
+        assertEquals("Type was not inherited", base.getType(), sub.getType());
+        assertEquals("Initial is incorrect", 
+                base.getInitial(), sub.getInitial());
+        assertEquals("Size is incorrect", size, sub.getSize());        
+    }
+    
+}

Propchange: 
struts/core/trunk/src/test/org/apache/struts/config/TestFormPropertyConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java
URL: 
http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java?view=auto&rev=159810
==============================================================================
--- struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java 
(added)
+++ struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java 
Sat Apr  2 12:03:36 2005
@@ -0,0 +1,440 @@
+package org.apache.struts.config;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Unit tests for ForwardConfig.  Currently contains tests for methods 
+ * supporting configuration inheritance.
+ */
+public class TestForwardConfig 
+        extends TestCase {
+    
+    
+    // ----------------------------------------------------- Instance Variables
+
+
+    /**
+     * The ModuleConfig we'll use.
+     */
+    protected ModuleConfig moduleConfig = null;
+
+
+    /**
+     * The common base we'll use.
+     */ 
+    protected ForwardConfig baseConfig = null;
+
+    
+    /**
+     * The common subForward we'll use.
+     */ 
+    protected ForwardConfig subConfig = null;
+    
+    
+    /**
+     * A ForwardConfig we'll use to test cases where a ForwardConfig declared
+     * for an action extends a ForwardConfig declared globally, with both
+     * ForwardConfigs using the same name.
+     */ 
+    protected ForwardConfig actionBaseConfig = null; 
+    
+    
+    /**
+     * An action mapping we'll use within tests.
+     */
+    protected ActionConfig actionConfig = null;
+    
+    // ----------------------------------------------------------- Constructors
+
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public TestForwardConfig(String name) {
+
+        super(name);
+
+    }
+
+
+    // --------------------------------------------------------- Public Methods
+
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+        
+        ModuleConfigFactory factoryObject =
+            ModuleConfigFactory.createFactory();
+        moduleConfig = factoryObject.createModuleConfig("");
+
+        // Setup the base and sub forwards, with sub extending base
+        baseConfig = new ForwardConfig();
+        baseConfig.setName("baseConfig");
+        baseConfig.setPath("/somePage.jsp");
+        
+        subConfig = new ForwardConfig();
+        subConfig.setName("subConfig");
+        subConfig.setExtends("baseConfig");
+        subConfig.setRedirect(true);
+
+        actionBaseConfig = new ForwardConfig();
+        actionBaseConfig.setName("baseConfig");
+        actionBaseConfig.setExtends("baseConfig");
+        actionBaseConfig.setModule("/other");
+
+        // Setup the default action config
+        actionConfig = new ActionConfig();
+        actionConfig.setPath("/index");
+        moduleConfig.addActionConfig(actionConfig);
+        
+        // No forward configs are registered to either module or action 
configs.
+        // Each test will determine where it needs these configs, if at all.
+    }
+
+
+    /**
+     * Return the tests included in this test suite.
+     */
+    public static Test suite() {
+
+        return (new TestSuite(TestForwardConfig.class));
+
+    }
+
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+
+        moduleConfig = null;
+        baseConfig = null;
+        
+    }
+
+    
+    
+    // ------------------------------------------------------- Individual Tests
+
+    
+    /**
+     * Make sure checkCircularInheritance() works as expected where there is 
+     * no inheritance set up.
+     */ 
+    public void testCheckCircularInheritanceNoExtends() {
+        moduleConfig.addForwardConfig(baseConfig);
+        boolean result = baseConfig.checkCircularInheritance(moduleConfig, 
null);
+        
+        assertTrue("Incorrect result", !result);
+    }
+    
+    /**
+     * Test checkCircularInheritance() for when there is no circular 
+     * inheritance. 
+     */ 
+    public void testCheckCircularInheritanceNoConflicts() {
+        moduleConfig.addForwardConfig(baseConfig);
+        moduleConfig.addForwardConfig(subConfig);
+        
+        boolean result = subConfig.checkCircularInheritance(moduleConfig, 
null);
+        
+        assertTrue("Incorrect result", !result);
+    }
+    
+    /**
+     * Test checkCircularInheritance() for circular inheritance between
+     * global forwards.
+     */ 
+    public void testCheckCircularInheritanceBasicGlobal() {
+        moduleConfig.addForwardConfig(subConfig);
+        moduleConfig.addForwardConfig(baseConfig);
+        
+        // set the baseConfig to extend subConfig 
+        baseConfig.setExtends("subConfig");
+        
+        boolean result = subConfig.checkCircularInheritance(moduleConfig, 
null);
+        
+        assertTrue("Circular inheritance not detected.", result);
+    }
+    
+    /**
+     * Test checkCircularInheritance() for circular inheritance between
+     * global forwards.
+     */ 
+    public void testCheckCircularInheritanceGlobal2Levels() {
+        moduleConfig.addForwardConfig(baseConfig);
+        moduleConfig.addForwardConfig(subConfig);
+
+        ForwardConfig grand = new ForwardConfig();
+        grand.setName("grandConfig");
+        grand.setExtends("subConfig");
+        moduleConfig.addForwardConfig(grand);
+        
+        // set the baseConfig to extend grandConfig 
+        baseConfig.setExtends("grandConfig");
+        
+        boolean result = grand.checkCircularInheritance(moduleConfig, null);
+        
+        assertTrue("Circular inheritance not detected.", result);
+    }
+        
+    /**
+     * Test checkCircularInheritance() for circular inheritance between 
+     * forwards in an action.
+     */
+    public void testCheckCircularInheritanceActionForwardsNoConflict() {
+        actionConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(subConfig);
+        
+        boolean result = subConfig.checkCircularInheritance(moduleConfig, 
+                actionConfig);
+        
+        assertTrue("Incorrect result", !result);
+    }
+
+    
+    /**
+     * Test checkCircularInheritance() for circular inheritance between 
+     * forwards in an action.
+     */
+    public void testCheckCircularInheritanceActionForwardsBasic() {
+        actionConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(subConfig);
+        
+        // set base to extend sub
+        baseConfig.setExtends("subConfig");
+        
+        boolean result = subConfig.checkCircularInheritance(moduleConfig, 
+                actionConfig);
+        
+        assertTrue("Circular inheritance not detected.", result);
+    }
+
+    
+    /**
+     * Test checkCircularInheritance() for circular inheritance between 
+     * a forward declared in an action and a global forward.
+     */
+    public void testCheckCircularInheritanceActionForwardExtendGlobal() {
+        actionConfig.addForwardConfig(subConfig);
+        moduleConfig.addForwardConfig(baseConfig);
+        
+        boolean result = subConfig.checkCircularInheritance(moduleConfig,
+                actionConfig);
+        
+        assertTrue("Incorrect result", !result);
+    }
+
+    
+    /**
+     * Test checkCircularInheritance() for circular inheritance between 
+     * a forward declared in an action and a global forward and both forwards
+     * have the same name.
+     */
+    public void 
testCheckCircularInheritanceActionForwardExtendGlobalSameName() {
+        moduleConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(actionBaseConfig);
+        
+        boolean result = 
actionBaseConfig.checkCircularInheritance(moduleConfig,
+                actionConfig);
+        
+        assertTrue("Incorrect result", !result);
+    }
+    
+    
+    /**
+     * Make sure processExtends() throws an error when the config is already
+     * configured.
+     */
+    public void testProcessExtendsConfigured() 
+            throws Exception {
+        
+        baseConfig.configured = true;
+        moduleConfig.addForwardConfig(baseConfig);
+        try {
+            baseConfig.processExtends(moduleConfig, null);
+            fail("processExtends should not succeed when object is already 
configured");
+        } catch (IllegalStateException e) {
+            // success
+        }
+        
+    }
+
+    
+    /**
+     * Test processExtends() when nothing is extended.
+     */
+    public void testProcessExtendsNoExtension() 
+            throws Exception {
+
+        String path = baseConfig.getPath();
+        String module = baseConfig.getModule();
+        String name = baseConfig.getName();
+        String inherit = baseConfig.getExtends();
+        boolean redirect = baseConfig.getRedirect();
+        
+        moduleConfig.addForwardConfig(baseConfig);
+        baseConfig.processExtends(moduleConfig, null);
+        
+        assertEquals("Path shouldn't have changed", path, 
baseConfig.getPath());
+        assertEquals("Module shouldn't have changed", module, 
+                baseConfig.getModule());
+        assertEquals("Name shouldn't have changed", name, 
baseConfig.getName());
+        assertEquals("Extends shouldn't have changed", inherit,
+                baseConfig.getExtends());
+        assertEquals("Redirect shouldn't have changed", redirect,
+                baseConfig.getRedirect());
+    }
+    
+    /**
+     * Test processExtends() with a basic extension.
+     */
+    public void testProcessExtendsBasicExtension() 
+            throws Exception {
+
+        String path = baseConfig.getPath();
+        String module = baseConfig.getModule();
+        
+        String inherit = subConfig.getExtends();
+        String name = subConfig.getName();
+        boolean redirect = subConfig.getRedirect();
+        
+        moduleConfig.addForwardConfig(baseConfig);
+        moduleConfig.addForwardConfig(subConfig);
+        subConfig.processExtends(moduleConfig, null);
+        
+        assertEquals("Path wasn't inherited", path, subConfig.getPath());
+        assertEquals("Module wasn't inherited", module, 
+                subConfig.getModule());
+        assertEquals("Name shouldn't have changed", name, subConfig.getName());
+        assertEquals("Extends shouldn't have changed", inherit,
+                subConfig.getExtends());
+        assertEquals("Redirect shouldn't have changed", redirect,
+                subConfig.getRedirect());
+    }
+
+
+    /**
+     * Test processExtends() with a basic extension between an action config
+     * and a global config.
+     */
+    public void testProcessExtendsBasicGlobalExtension() 
+            throws Exception {
+
+        String path = baseConfig.getPath();
+        String module = baseConfig.getModule();
+
+        boolean redirect = subConfig.getRedirect();
+        String inherit = subConfig.getExtends();
+        String name = subConfig.getName();
+        
+        moduleConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(subConfig);
+        subConfig.processExtends(moduleConfig, actionConfig);
+        
+        assertEquals("Path wasn't inherited", path, subConfig.getPath());
+        assertEquals("Module wasn't inherited", module, 
+                subConfig.getModule());
+        assertEquals("Name shouldn't have changed", name, subConfig.getName());
+        assertEquals("Extends shouldn't have changed", inherit,
+                subConfig.getExtends());
+        assertEquals("Redirect shouldn't have changed", redirect,
+                subConfig.getRedirect());
+    }
+
+
+    /**
+     * Test processExtends() with an incorrect setup where a global config
+     * attempts to extend an action config.
+     */
+    public void testProcessExtendsGlobalExtendingAction() 
+            throws Exception {
+
+        moduleConfig.addForwardConfig(subConfig);
+        actionConfig.addForwardConfig(baseConfig);
+        
+        try {
+            subConfig.processExtends(moduleConfig, actionConfig);
+            fail("Should not find config from actionConfig when *this* is 
global");
+        } catch (NullPointerException npe) {
+            // succeed
+        }
+    }
+    
+    /**
+     * Test processExtends() with an action config that extends a global
+     * config with the same name.
+     */
+    public void testProcessExtendsSameNames() 
+            throws Exception {
+
+        String path = baseConfig.getPath();
+        boolean redirect = baseConfig.getRedirect();
+        
+        String module = actionBaseConfig.getModule();
+        String inherit = actionBaseConfig.getExtends();
+        String name = actionBaseConfig.getName();
+        
+        moduleConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(actionBaseConfig);
+
+        actionBaseConfig.processExtends(moduleConfig, actionConfig);
+        
+        assertEquals("Path wasn't inherited", path, 
+                actionBaseConfig.getPath());
+        assertEquals("Module shouldn't have changed", module, 
+                actionBaseConfig.getModule());
+        assertEquals("Name shouldn't have changed", name, 
+                actionBaseConfig.getName());
+        assertEquals("Extends shouldn't have changed", inherit,
+                actionBaseConfig.getExtends());
+        assertEquals("Redirect shouldn't have changed", redirect,
+                actionBaseConfig.getRedirect());
+    }
+    
+    /**
+     * Test processExtends() where an action ForwardConfig extends another 
+     * ForwardConfig, which in turn extends a global ForwardConfig with
+     * the same name.
+     */
+    public void 
testProcessExtendsActionExtendsActionExtendsGlobalWithSameName() 
+            throws Exception {
+
+        String path = baseConfig.getPath();
+        
+        String module = actionBaseConfig.getModule();
+        
+        boolean redirect = subConfig.getRedirect();
+        String inherit = subConfig.getExtends();
+        String name = subConfig.getName();
+        
+        moduleConfig.addForwardConfig(baseConfig);
+        actionConfig.addForwardConfig(actionBaseConfig);
+        actionConfig.addForwardConfig(subConfig);
+        
+        subConfig.processExtends(moduleConfig, actionConfig);
+        
+        assertTrue("baseConfig's processExtends() should've been called",
+                baseConfig.extensionProcessed);
+        assertTrue("actionBaseConfig's processExtends() should've been called",
+                actionBaseConfig.extensionProcessed);
+        
+        assertEquals("Path wasn't inherited", path, 
+                subConfig.getPath());
+        assertEquals("Module wasn't inherited", module, 
+                subConfig.getModule());
+        assertEquals("Name shouldn't have changed", name, 
+                subConfig.getName());
+        assertEquals("Extends shouldn't have changed", inherit,
+                subConfig.getExtends());
+        assertEquals("Redirect shouldn't have changed", redirect,
+                subConfig.getRedirect());        
+    }
+    
+}

Propchange: 
struts/core/trunk/src/test/org/apache/struts/config/TestForwardConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

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



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

Reply via email to