Author: schof
Date: Wed Nov  9 11:53:29 2005
New Revision: 332129

URL: http://svn.apache.org/viewcvs?rev=332129&view=rev
Log:
Added test case for solution to Bug #36439 (allow user to configure additional 
properties in dialog-config.xml)

Added:
    struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/
    
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/ConfigurationParserTestCase.java
Modified:
    
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml

Added: 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/ConfigurationParserTestCase.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/ConfigurationParserTestCase.java?rev=332129&view=auto
==============================================================================
--- 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/ConfigurationParserTestCase.java
 (added)
+++ 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/config/ConfigurationParserTestCase.java
 Wed Nov  9 11:53:29 2005
@@ -0,0 +1,141 @@
+/*
+ * 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.shale.dialog.config;
+
+import java.util.Map;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.shale.dialog.Dialog;
+import org.apache.shale.dialog.Globals;
+import org.apache.shale.dialog.config.ConfigurationInit;
+import org.apache.shale.dialog.impl.DialogImpl;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+/**
+ * <p>Test case for <code>org.apache.shale.dialog.config.
+ * ConfigurationParser</code>.</p>
+ *
+ * $Id: ImplClassesTestCase.java 293010 2005-10-01 17:58:52Z wsmoak $
+ */
+
+public class ConfigurationParserTestCase extends AbstractJsfTestCase {
+
+
+    // ------------------------------------------------------------ 
Constructors
+
+
+    // Construct a new instance of this test case.
+    public ConfigurationParserTestCase(String name) {
+        super(name);
+    }
+
+    // ---------------------------------------------------- Overall Test 
Methods
+
+
+    // Set up instance variables required by this test case.
+    public void setUp() {
+
+        super.setUp();
+
+        // Configure the test dialogs we will be using
+        servletContext.addInitParameter
+            (Globals.CONFIGURATION_PARAM,
+             "/org/apache/shale/dialog/faces/dialog-config.xml");
+        Context context = new ContextBase();
+        context.put("context", servletContext);
+        Command command = new ConfigurationInit();
+        try {
+            command.execute(context);
+        }
+        catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        dialogMap = (Map) externalContext.getApplicationMap().get(Globals.
+            DIALOGS);
+
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite() {
+
+        return (new TestSuite(ConfigurationParserTestCase.class));
+
+    }
+
+    // Tear down instance variables required by this test case.
+    public void tearDown() {
+
+        dialogMap = null;
+        super.tearDown();
+
+    }
+
+    // ------------------------------------------------------ Instance 
Variables
+
+
+    // Map of configured Dialog instances for this test case,
+    // keyed by dialog id
+    Map dialogMap = null;
+
+    // ------------------------------------------------------------ Test 
Methods
+
+    // Test that the correct class instance was created for the 
+    // "testClassName" dialog
+    public void testClassName() {
+        Dialog dialog = (Dialog) dialogMap.get("testClassName");
+        assertNotNull(dialog);
+        assertTrue(dialog instanceof FooDialogImpl);
+    }
+
+
+    // Test that additional properties can be specified  through the 
+    // dialog-config
+    public void testAdditionalProps() {
+        Dialog dialog = (Dialog) dialogMap.get("testAdditionalProps");
+        assertNotNull(dialog);
+        assertTrue(dialog instanceof FooDialogImpl);
+        assertEquals("testAdditionalProps", dialog.getName());        
+        
+        FooDialogImpl fooDialog = (FooDialogImpl)dialog;
+        assertEquals(fooDialog.getFoo(), "bar");
+        
+        // FIXME
+        // still need to test inside state and transition 
+        // requires a custom configuration class to create specialized classes
+    }
+
+    // --------------------------------------------------------- Support 
Methods
+
+
+    // ----------------------------------------------------------- Inner 
Classes
+
+    // Inner class used to test className attribute
+    public static final class FooDialogImpl extends DialogImpl {
+        private String foo;
+        
+        public void setFoo(String foo) {
+            this.foo = foo;
+        }
+        
+        public String getFoo() {
+            return foo;
+        }
+    }
+}

Modified: 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml?rev=332129&r1=332128&r2=332129&view=diff
==============================================================================
--- 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml
 (original)
+++ 
struts/shale/trunk/core-library/src/test/org/apache/shale/dialog/faces/dialog-config.xml
 Wed Nov  9 11:53:29 2005
@@ -198,5 +198,35 @@
 
   </dialog>
 
+  <dialog                name="testClassName"
+                                                                       
className="org.apache.shale.dialog.config.ConfigurationParserTestCase$FooDialogImpl"
 
+                        start="first">
+
+    <action              name="first"
+                       method="#{test.first}">
+      <transition     outcome="first"
+                       target="end"/>
+    </action>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
+  <dialog                name="testAdditionalProps"
+                                                                       
className="org.apache.shale.dialog.config.ConfigurationParserTestCase$FooDialogImpl"
 
+                        start="first">
+
+               <property name="foo" value="bar"/>
+
+    <action              name="first"
+                       method="#{test.first}">
+      <transition     outcome="first"
+                       target="end"/>
+    </action>
+
+    <end                 name="finish"/>
+
+  </dialog>
+
 
 </dialogs>



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

Reply via email to