struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mart...@apache.org
Subject svn commit: r894087 [29/46] - in /struts/xwork/trunk: ./ assembly/ assembly/src/ assembly/src/main/ assembly/src/main/assembly/ assembly/src/main/resources/ core/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/com/ core/src/main/java/c...
Date Sun, 27 Dec 2009 18:01:09 GMT
Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.config.providers;
+
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.RuntimeConfiguration;
+import com.opensymphony.xwork2.config.impl.MockConfiguration;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.FileManager;
+import com.opensymphony.xwork2.ObjectFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.w3c.dom.Document;
+
+
+public class XmlConfigurationProviderTest extends ConfigurationTestBase {
+
+    public void testLoadOrder() throws Exception {
+        configuration = new MockConfiguration();
+        ((MockConfiguration)configuration).selfRegister();
+        container = configuration.getContainer();
+
+        XmlConfigurationProvider prov = new XmlConfigurationProvider("xwork-test-load-order.xml", true) {
+            @Override
+            protected Iterator<URL> getConfigurationUrls(String fileName) throws IOException {
+                List<URL> urls = new ArrayList<URL>();
+                urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder1/xwork-test-load-order.xml", XmlConfigurationProvider.class));
+                urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder2/xwork-test-load-order.xml", XmlConfigurationProvider.class));
+                urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder3/xwork-test-load-order.xml", XmlConfigurationProvider.class));
+                return urls.iterator();
+            }
+        };
+        prov.setObjectFactory(container.getInstance(ObjectFactory.class));
+        prov.init(configuration);
+        List<Document> docs = prov.getDocuments();
+        assertEquals(3, docs.size() );
+
+        assertEquals(1, XmlHelper.getLoadOrder(docs.get(0)).intValue());
+        assertEquals(2, XmlHelper.getLoadOrder(docs.get(1)).intValue());
+        assertEquals(3, XmlHelper.getLoadOrder(docs.get(2)).intValue());
+    }
+
+    public void testNeedsReload() throws Exception {
+        FileManager.setReloadingConfigs(true);
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+
+        assertTrue(!provider.needsReload());
+
+        File file = new File(getClass().getResource("/"+filename).getFile());
+        assertTrue(file.exists());
+        file.setLastModified(System.currentTimeMillis());
+
+        assertTrue(provider.needsReload());
+    }
+
+    public void testInheritence() throws Exception {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-include-parent.xml";
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+
+        provider.init(configuration);
+        provider.loadPackages();
+
+        // test expectations
+        assertEquals(6, configuration.getPackageConfigs().size());
+
+
+        PackageConfig defaultPackage = configuration.getPackageConfig("default");
+        assertNotNull(defaultPackage);
+        assertEquals("default", defaultPackage.getName());
+
+
+        PackageConfig namespace1 = configuration.getPackageConfig("namespace1");
+        assertNotNull(namespace1);
+        assertEquals("namespace1", namespace1.getName());
+        assertEquals(defaultPackage, namespace1.getParents().get(0));
+
+        PackageConfig namespace2 = configuration.getPackageConfig("namespace2");
+        assertNotNull(namespace2);
+        assertEquals("namespace2", namespace2.getName());
+        assertEquals(1, namespace2.getParents().size());
+        assertEquals(namespace1, namespace2.getParents().get(0));
+
+
+        PackageConfig namespace4 = configuration.getPackageConfig("namespace4");
+        assertNotNull(namespace4);
+        assertEquals("namespace4", namespace4.getName());
+        assertEquals(1, namespace4.getParents().size());
+        assertEquals(namespace1, namespace4.getParents().get(0));
+
+
+        PackageConfig namespace5 = configuration.getPackageConfig("namespace5");
+        assertNotNull(namespace5);
+        assertEquals("namespace5", namespace5.getName());
+        assertEquals(1, namespace5.getParents().size());
+        assertEquals(namespace4, namespace5.getParents().get(0));
+
+        configurationManager.addConfigurationProvider(provider);
+        configurationManager.reload();
+
+        RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
+        assertNotNull(runtimeConfiguration.getActionConfig("/namespace1", "action1"));
+        assertNotNull(runtimeConfiguration.getActionConfig("/namespace2", "action2"));
+        assertNotNull(runtimeConfiguration.getActionConfig("/namespace4", "action4"));
+        assertNotNull(runtimeConfiguration.getActionConfig("/namespace5", "action5"));
+    }
+
+    public void testGuessResultType() {
+        XmlConfigurationProvider prov = new XmlConfigurationProvider();
+
+        assertEquals(null, prov.guessResultType(null));
+        assertEquals("foo", prov.guessResultType("foo"));
+        assertEquals("foo", prov.guessResultType("foo-"));
+        assertEquals("fooBar", prov.guessResultType("foo-bar"));
+        assertEquals("fooBarBaz", prov.guessResultType("foo-bar-baz"));
+    }
+
+    public void testEmptySpaces() throws Exception {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
+        FileManager.setReloadingConfigs(true);
+
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+        assertTrue(!provider.needsReload());
+
+        URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
+
+        File file = new File(uri);
+
+        assertTrue(file.exists());
+        file.setLastModified(System.currentTimeMillis());
+
+        assertTrue(provider.needsReload());
+    }
+
+    public void testConfigsInJarFiles() throws Exception {
+        FileManager.setReloadingConfigs(true);
+        testProvider("xwork-jar.xml");
+        testProvider("xwork-zip.xml");
+        testProvider("xwork - jar.xml");
+        testProvider("xwork - zip.xml");
+
+        testProvider("xwork-jar2.xml");
+        testProvider("xwork-zip2.xml");
+        testProvider("xwork - jar2.xml");
+        testProvider("xwork - zip2.xml");
+    }
+
+    private void testProvider(String configFile) throws Exception {
+        ConfigurationProvider provider = buildConfigurationProvider(configFile);
+        assertTrue(!provider.needsReload());
+
+        String fullPath = ClassLoaderUtil.getResource(configFile, ConfigurationProvider.class).toString();
+
+        int startIndex = fullPath.indexOf(":file:/");
+        int endIndex = fullPath.indexOf("!/");
+
+        String jar = fullPath.substring(startIndex + (":file:/".length() -1 ), endIndex).replaceAll("%20", " ");
+
+        File file = new File(jar);
+        
+        assertTrue("File [" + file + "] doesn't exist!", file.exists());
+        file.setLastModified(System.currentTimeMillis());
+
+        assertTrue(!provider.needsReload());
+    }
+         
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,40 @@
+package com.opensymphony.xwork2.config.providers;
+
+import com.opensymphony.xwork2.UnknownHandlerManager;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.entities.UnknownHandlerConfig;
+import com.opensymphony.xwork2.DefaultUnknownHandlerManager;
+
+import java.util.List;
+
+public class XmlConfigurationProviderUnknownHandlerStackTest extends ConfigurationTestBase {
+
+    public void testStackWithElements() throws ConfigurationException {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack.xml";
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+        loadConfigurationProviders(provider);
+        configurationManager.reload();
+
+        List<UnknownHandlerConfig> unknownHandlerStack = configuration.getUnknownHandlerStack();
+        assertNotNull(unknownHandlerStack);
+        assertEquals(2, unknownHandlerStack.size());
+
+        assertEquals("uh1", unknownHandlerStack.get(0).getName());
+        assertEquals("uh2", unknownHandlerStack.get(1).getName());
+
+        UnknownHandlerManager unknownHandlerManager = new DefaultUnknownHandlerManager();
+        container.inject(unknownHandlerManager);
+        assertTrue(unknownHandlerManager.hasUnknownHandlers());
+    }
+
+    public void testEmptyStack() throws ConfigurationException {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack-empty.xml";
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+        loadConfigurationProviders(provider);
+        configurationManager.reload();
+
+        List<UnknownHandlerConfig> unknownHandlerStack = configuration.getUnknownHandlerStack();
+        assertNull(unknownHandlerStack);
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderUnknownHandlerStackTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.config.providers;
+
+import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+
+public class XmlConfigurationProviderWildCardIncludeTest extends ConfigurationTestBase {
+
+    
+    public void testWildCardInclude() throws Exception {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-wildcard-include.xml";
+        ConfigurationProvider provider = buildConfigurationProvider(filename);
+
+        provider.init(configuration);
+        provider.loadPackages();
+
+        PackageConfig defaultWildcardPackage = configuration.getPackageConfig("default-wildcard");
+        assertNotNull(defaultWildcardPackage);
+        assertEquals("default-wildcard", defaultWildcardPackage.getName());
+
+
+        PackageConfig defaultOnePackage = configuration.getPackageConfig("default-1");
+        assertNotNull(defaultOnePackage);
+        assertEquals("default-1", defaultOnePackage.getName());
+        
+        PackageConfig defaultTwoPackage = configuration.getPackageConfig("default-2");
+        assertNotNull(defaultTwoPackage);
+        assertEquals("default-2", defaultTwoPackage.getName());       
+
+        configurationManager.addConfigurationProvider(provider);
+        configurationManager.reload();
+
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderWildCardIncludeTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,255 @@
+package com.opensymphony.xwork2.config.providers;
+
+import com.opensymphony.xwork2.XWorkTestCase;
+import org.easymock.MockControl;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.Map;
+
+/**
+ * <code>XmlHelperTest</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public class XmlHelperTest extends XWorkTestCase {
+
+    public void testGetContent1() throws Exception {
+        // set up Node
+        MockControl nodeControl = MockControl.createControl(Node.class);
+        Node mockNode = (Node) nodeControl.getMock();
+
+        nodeControl.expectAndDefaultReturn(mockNode.getNodeValue(), "testing testing 123");
+        nodeControl.expectAndDefaultReturn(mockNode.getNodeType(), Node.TEXT_NODE);
+
+
+        // set up NodeList
+        MockControl nodeListControl = MockControl.createControl(NodeList.class);
+        NodeList mockNodeList = (NodeList) nodeListControl.getMock();
+
+        nodeListControl.expectAndDefaultReturn(mockNodeList.getLength(), 1);
+        nodeListControl.expectAndDefaultReturn(mockNodeList.item(0), mockNode);
+
+
+        // set up Element
+        MockControl elementControl = MockControl.createControl(Element.class);
+        Element mockElement = (Element) elementControl.getMock();
+
+        elementControl.expectAndDefaultReturn(mockElement.getChildNodes(), mockNodeList);
+
+        nodeControl.replay();
+        nodeListControl.replay();
+        elementControl.replay();
+
+        String result = XmlHelper.getContent(mockElement);
+
+        nodeControl.verify();
+        nodeListControl.verify();
+        elementControl.verify();
+
+        assertEquals(result, "testing testing 123");
+    }
+
+
+    public void testGetContent2() throws Exception {
+        // set up Node
+        MockControl nodeControl1 = MockControl.createControl(Node.class);
+        Node mockNode1 = (Node) nodeControl1.getMock();
+
+        nodeControl1.expectAndDefaultReturn(mockNode1.getNodeValue(), "testing testing 123");
+        nodeControl1.expectAndDefaultReturn(mockNode1.getNodeType(), Node.TEXT_NODE);
+
+        MockControl nodeControl2 = MockControl.createControl(Node.class);
+        Node mockNode2 = (Node) nodeControl2.getMock();
+
+        nodeControl2.expectAndDefaultReturn(mockNode2.getNodeValue(), "comment 1");
+        nodeControl2.expectAndDefaultReturn(mockNode2.getNodeType(), Node.COMMENT_NODE);
+
+        MockControl nodeControl3 = MockControl.createControl(Node.class);
+        Node mockNode3 = (Node) nodeControl3.getMock();
+
+        nodeControl3.expectAndDefaultReturn(mockNode3.getNodeValue(), " tmjee ");
+        nodeControl3.expectAndDefaultReturn(mockNode3.getNodeType(), Node.TEXT_NODE);
+
+        MockControl nodeControl4 = MockControl.createControl(Node.class);
+        Node mockNode4 = (Node) nodeControl4.getMock();
+
+        nodeControl4.expectAndDefaultReturn(mockNode4.getNodeValue(), " phil ");
+        nodeControl4.expectAndDefaultReturn(mockNode4.getNodeType(), Node.TEXT_NODE);
+
+        MockControl nodeControl5 = MockControl.createControl(Node.class);
+        Node mockNode5 = (Node) nodeControl5.getMock();
+
+        nodeControl5.expectAndDefaultReturn(mockNode5.getNodeValue(), "comment 2");
+        nodeControl5.expectAndDefaultReturn(mockNode5.getNodeType(), Node.COMMENT_NODE);
+
+        MockControl nodeControl6 = MockControl.createControl(Node.class);
+        Node mockNode6 = (Node) nodeControl6.getMock();
+
+        nodeControl6.expectAndDefaultReturn(mockNode6.getNodeValue(), "comment 3");
+        nodeControl6.expectAndDefaultReturn(mockNode6.getNodeType(), Node.COMMENT_NODE);
+
+
+        // set up NodeList
+        MockControl nodeListControl = MockControl.createControl(NodeList.class);
+        NodeList mockNodeList = (NodeList) nodeListControl.getMock();
+
+        nodeListControl.expectAndDefaultReturn(mockNodeList.getLength(), 6);
+        mockNodeList.item(0);
+        nodeListControl.setReturnValue(mockNode1);
+        mockNodeList.item(1);
+        nodeListControl.setReturnValue(mockNode2);
+        mockNodeList.item(2);
+        nodeListControl.setDefaultReturnValue(mockNode3);
+        mockNodeList.item(3);
+        nodeListControl.setReturnValue(mockNode4);
+        mockNodeList.item(4);
+        nodeListControl.setReturnValue(mockNode5);
+        mockNodeList.item(5);
+        nodeListControl.setReturnValue(mockNode6);
+
+
+        // set up Element
+        MockControl elementControl = MockControl.createControl(Element.class);
+        Element mockElement = (Element) elementControl.getMock();
+
+        elementControl.expectAndDefaultReturn(mockElement.getChildNodes(), mockNodeList);
+
+        nodeControl1.replay();
+        nodeControl2.replay();
+        nodeControl3.replay();
+        nodeControl4.replay();
+        nodeControl5.replay();
+        nodeControl6.replay();
+        nodeListControl.replay();
+        elementControl.replay();
+
+        String result = XmlHelper.getContent(mockElement);
+
+        nodeControl1.verify();
+        nodeControl2.verify();
+        nodeControl3.verify();
+        nodeControl4.verify();
+        nodeControl5.verify();
+        nodeControl6.verify();
+        nodeListControl.verify();
+        elementControl.verify();
+
+        assertEquals(result, "testing testing 123tmjeephil");
+    }
+
+
+
+    public void testGetParams() throws Exception {
+        // <param name="param1">value1</param>
+            MockControl nodeControl1 = MockControl.createControl(Node.class);
+            Node mockNode1 = (Node) nodeControl1.getMock();
+
+            nodeControl1.expectAndDefaultReturn(mockNode1.getNodeValue(), "value1");
+            nodeControl1.expectAndDefaultReturn(mockNode1.getNodeType(), Node.TEXT_NODE);
+
+
+            MockControl nodeListControl1 = MockControl.createControl(NodeList.class);
+            NodeList mockNodeList1 = (NodeList) nodeListControl1.getMock();
+
+            nodeListControl1.expectAndDefaultReturn(mockNodeList1.getLength(), 1);
+            nodeListControl1.expectAndDefaultReturn(mockNodeList1.item(0), mockNode1);
+
+            MockControl paramControl1 = MockControl.createControl(Element.class);
+            Element mockParamElement1 = (Element) paramControl1.getMock();
+            mockParamElement1.getNodeName();
+            paramControl1.setReturnValue("param");
+
+            mockParamElement1.getNodeType();
+            paramControl1.setReturnValue(Node.ELEMENT_NODE);
+
+            mockParamElement1.getAttribute("name");
+            paramControl1.setReturnValue("param1");
+
+            mockParamElement1.getChildNodes();
+            paramControl1.setReturnValue(mockNodeList1);
+
+            nodeControl1.replay();
+            nodeListControl1.replay();
+            paramControl1.replay();
+
+        // <param name="param2">value2</param>
+            MockControl nodeControl2 = MockControl.createControl(Node.class);
+            Node mockNode2 = (Node) nodeControl2.getMock();
+
+            nodeControl2.expectAndDefaultReturn(mockNode2.getNodeValue(), "value2");
+            nodeControl2.expectAndDefaultReturn(mockNode2.getNodeType(), Node.TEXT_NODE);
+
+
+            MockControl nodeListControl2 = MockControl.createControl(NodeList.class);
+            NodeList mockNodeList2 = (NodeList) nodeListControl2.getMock();
+
+            nodeListControl2.expectAndDefaultReturn(mockNodeList2.getLength(), 1);
+            nodeListControl2.expectAndDefaultReturn(mockNodeList2.item(0), mockNode2);
+
+            MockControl paramControl2 = MockControl.createControl(Element.class);
+            Element mockParamElement2 = (Element) paramControl2.getMock();
+            mockParamElement2.getNodeName();
+            paramControl2.setReturnValue("param");
+
+            mockParamElement2.getNodeType();
+            paramControl2.setReturnValue(Node.ELEMENT_NODE);
+
+            mockParamElement2.getAttribute("name");
+            paramControl2.setReturnValue("param2");
+
+            mockParamElement2.getChildNodes();
+            paramControl2.setReturnValue(mockNodeList2);
+
+            nodeControl2.replay();
+            nodeListControl2.replay();
+            paramControl2.replay();
+
+
+        // <some_element>
+        //   ...
+        // </some_element>
+        MockControl elementNodeListControl = MockControl.createControl(NodeList.class);
+        NodeList mockElementNodeList = (NodeList) elementNodeListControl.getMock();
+
+        elementNodeListControl.expectAndDefaultReturn(mockElementNodeList.getLength(), 2);
+        mockElementNodeList.item(0);
+        elementNodeListControl.setReturnValue(mockParamElement2);
+        mockElementNodeList.item(1);
+        elementNodeListControl.setReturnValue(mockParamElement1);
+
+        MockControl elementControl = MockControl.createControl(Element.class);
+        Element element = (Element) elementControl.getMock();
+
+        elementControl.expectAndDefaultReturn(element.getChildNodes(), mockElementNodeList);
+
+
+        elementNodeListControl.replay();
+        elementControl.replay();
+
+
+
+        Map params = XmlHelper.getParams(element);
+
+        nodeControl1.verify();
+            nodeListControl1.verify();
+            paramControl1.verify();
+
+
+        nodeControl2.verify();
+            nodeListControl2.verify();
+            paramControl2.verify();
+
+
+        elementNodeListControl.verify();
+        elementControl.verify();
+
+
+        assertNotNull(params);
+        assertEquals(params.size(), 2);
+        assertEquals(params.get("param1"), "value1");
+        assertEquals(params.get("param2"), "value2");
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/config/providers/XmlHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.conversion;
+
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.conversion.annotations.Conversion;
+import com.opensymphony.xwork2.conversion.annotations.ConversionRule;
+import com.opensymphony.xwork2.conversion.annotations.ConversionType;
+import com.opensymphony.xwork2.conversion.annotations.TypeConversion;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * <code>ConversionTestAction</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+@Conversion()
+public class ConversionTestAction implements Action {
+
+
+
+    private String convertInt;
+
+    private String convertDouble;
+
+    private List users = null;
+
+
+    private HashMap keyValues = null;
+
+
+    public String getConvertInt() {
+        return convertInt;
+    }
+
+    @TypeConversion(type = ConversionType.APPLICATION, converter = "com.opensymphony.xwork2.util.XWorkBasicConverter")
+    public void setConvertInt( String convertInt ) {
+        this.convertInt = convertInt;
+    }
+
+    public String getConvertDouble() {
+        return convertDouble;
+    }
+
+    @TypeConversion(converter = "com.opensymphony.xwork2.util.XWorkBasicConverter")
+    public void setConvertDouble( String convertDouble ) {
+        this.convertDouble = convertDouble;
+    }
+
+    public List getUsers() {
+        return users;
+    }
+
+    @TypeConversion(rule = ConversionRule.COLLECTION, converter = "java.lang.String")
+    public void setUsers( List users ) {
+        this.users = users;
+    }
+
+    public HashMap getKeyValues() {
+        return keyValues;
+    }
+
+    @TypeConversion(rule = ConversionRule.MAP, converter = "java.math.BigInteger")
+    public void setKeyValues( HashMap keyValues ) {
+        this.keyValues = keyValues;
+    }
+
+    /**
+     * Where the logic of the action is executed.
+     *
+     * @return a string representing the logical result of the execution.
+     *         See constants in this interface for a list of standard result values.
+     * @throws Exception thrown if a system level exception occurs.
+     *                   Application level exceptions should be handled by returning
+     *                   an error value, such as Action.ERROR.
+     */
+    @TypeConversion(type = ConversionType.APPLICATION, key = "java.util.Date", converter = "com.opensymphony.xwork2.util.XWorkBasicConverter")
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/ConversionTestAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.conversion.impl;
+
+import com.opensymphony.xwork2.*;
+import com.opensymphony.xwork2.test.AnnotationUser;
+import com.opensymphony.xwork2.test.ModelDrivenAnnotationAction2;
+import com.opensymphony.xwork2.util.Bar;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+import ognl.OgnlException;
+import ognl.OgnlRuntime;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+
+/**
+ * @author $Author$
+ * @author Rainer Hermanns
+ * @version $Revision$
+ */
+public class AnnotationXWorkConverterTest extends XWorkTestCase {
+
+    ActionContext ac;
+    Map<String, Object> context;
+    XWorkConverter converter;
+
+//    public void testConversionToSetKeepsOriginalSetAndReplacesContents() {
+//        ValueStack stack = ValueStackFactory.getFactory().createValueStack();
+//
+//        Map stackContext = stack.getContext();
+//        stackContext.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.TRUE);
+//        stackContext.put(XWorkMethodAccessor.DENY_METHOD_EXECUTION, Boolean.TRUE);
+//        stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+//
+//        String[] param = new String[] {"abc", "def", "ghi"};
+//        List paramList = Arrays.asList(param);
+//
+//        List originalList = new ArrayList();
+//        originalList.add("jkl");
+//        originalList.add("mno");
+//
+//        AnnotationUser user = new AnnotationUser();
+//        user.setList(originalList);
+//        stack.push(user);
+//
+//        stack.setValue("list", param);
+//
+//        List userList = user.getList();
+//        assertEquals(3,userList.size());
+//        assertEquals(paramList,userList);
+//        assertSame(originalList,userList);
+//    }
+
+    public void testArrayToNumberConversion() {
+        String[] value = new String[]{"12345"};
+        assertEquals(new Integer(12345), converter.convertValue(context, null, null, null, value, Integer.class));
+        assertEquals(new Long(12345), converter.convertValue(context, null, null, null, value, Long.class));
+        value[0] = "123.45";
+        assertEquals(new Float(123.45), converter.convertValue(context, null, null, null, value, Float.class));
+        assertEquals(new Double(123.45), converter.convertValue(context, null, null, null, value, Double.class));
+        value[0] = "1234567890123456789012345678901234567890";
+        assertEquals(new BigInteger(value[0]), converter.convertValue(context, null, null, null, value, BigInteger.class));
+        value[0] = "1234567890123456789.012345678901234567890";
+        assertEquals(new BigDecimal(value[0]), converter.convertValue(context, null, null, null, value, BigDecimal.class));
+    }
+
+    public void testDateConversion() throws ParseException {
+        java.sql.Date sqlDate = new java.sql.Date(System.currentTimeMillis());
+        assertEquals(sqlDate, converter.convertValue(context, null, null, null, sqlDate, Date.class));
+
+        SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy hh:mm:ss");
+        Date date = format.parse("01/10/2001 00:00:00");
+        String dateStr = (String) converter.convertValue(context, null, null, null, date, String.class);
+        Date date2 = (Date) converter.convertValue(context, null, null, null, dateStr, Date.class);
+        assertEquals(date, date2);
+    }
+
+    public void testFieldErrorMessageAddedForComplexProperty() {
+        SimpleAnnotationAction action = new SimpleAnnotationAction();
+        action.setBean(new AnnotatedTestBean());
+
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(action);
+
+        Map<String, Object> ognlStackContext = stack.getContext();
+        ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+        ognlStackContext.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, "bean.birth");
+
+        String[] value = new String[]{"invalid date"};
+        assertEquals("Conversion should have failed.", OgnlRuntime.NoConversionPossible, converter.convertValue(ognlStackContext, action.getBean(), null, "birth", value, Date.class));
+        stack.pop();
+
+        Map conversionErrors = (Map) stack.getContext().get(ActionContext.CONVERSION_ERRORS);
+        assertNotNull(conversionErrors);
+        assertTrue(conversionErrors.size() == 1);
+        assertEquals(value, conversionErrors.get("bean.birth"));
+    }
+
+    public void testFieldErrorMessageAddedWhenConversionFails() {
+        SimpleAnnotationAction action = new SimpleAnnotationAction();
+        action.setDate(null);
+
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(action);
+
+        Map<String, Object> ognlStackContext = stack.getContext();
+        ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        String[] value = new String[]{"invalid date"};
+        assertEquals("Conversion should have failed.", OgnlRuntime.NoConversionPossible, converter.convertValue(ognlStackContext, action, null, "date", value, Date.class));
+        stack.pop();
+
+        Map conversionErrors = (Map) ognlStackContext.get(ActionContext.CONVERSION_ERRORS);
+        assertNotNull(conversionErrors);
+        assertEquals(1, conversionErrors.size());
+        assertNotNull(conversionErrors.get("date"));
+        assertEquals(value, conversionErrors.get("date"));
+    }
+
+    public void testFieldErrorMessageAddedWhenConversionFailsOnModelDriven() {
+        ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction();
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(action);
+        stack.push(action.getModel());
+
+        Map<String, Object> ognlStackContext = stack.getContext();
+        ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        String[] value = new String[]{"invalid date"};
+        assertEquals("Conversion should have failed.", OgnlRuntime.NoConversionPossible, converter.convertValue(ognlStackContext, action, null, "birth", value, Date.class));
+        stack.pop();
+        stack.pop();
+
+        Map conversionErrors = (Map) ognlStackContext.get(ActionContext.CONVERSION_ERRORS);
+        assertNotNull(conversionErrors);
+        assertEquals(1, conversionErrors.size());
+        assertNotNull(conversionErrors.get("birth"));
+        assertEquals(value, conversionErrors.get("birth"));
+    }
+
+    public void testFindConversionErrorMessage() {
+        ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction();
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(action);
+        stack.push(action.getModel());
+
+        String message = XWorkConverter.getConversionErrorMessage("birth", stack);
+        assertNotNull(message);
+        assertEquals("Invalid date for birth.", message);
+
+        message = XWorkConverter.getConversionErrorMessage("foo", stack);
+        assertNotNull(message);
+        assertEquals("Invalid field value for field \"foo\".", message);
+    }
+
+    public void testFindConversionMappingForInterface() {
+        ModelDrivenAnnotationAction2 action = new ModelDrivenAnnotationAction2();
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(action);
+        stack.push(action.getModel());
+
+        Map<String, Object> ognlStackContext = stack.getContext();
+        ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        String value = "asdf:123";
+        Object o = converter.convertValue(ognlStackContext, action.getModel(), null, "barObj", value, Bar.class);
+        assertNotNull(o);
+        assertTrue("class is: " + o.getClass(), o instanceof Bar);
+
+        Bar b = (Bar) o;
+        assertEquals(value, b.getTitle() + ":" + b.getSomethingElse());
+    }
+
+    public void testLocalizedDateConversion() throws Exception {
+        Date date = new Date(System.currentTimeMillis());
+        Locale locale = Locale.GERMANY;
+        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        String dateString = df.format(date);
+        context.put(ActionContext.LOCALE, locale);
+        assertEquals(dateString, converter.convertValue(context, null, null, null, date, String.class));
+    }
+
+    public void testStringArrayToCollection() {
+        List<String> list = new ArrayList<String>();
+        list.add("foo");
+        list.add("bar");
+        list.add("baz");
+        assertEquals(list, converter.convertValue(context, null, null, null, new String[]{
+                "foo", "bar", "baz"
+        }, Collection.class));
+    }
+
+    public void testStringArrayToList() {
+        List<String> list = new ArrayList<String>();
+        list.add("foo");
+        list.add("bar");
+        list.add("baz");
+        assertEquals(list, converter.convertValue(context, null, null, null, new String[]{
+                "foo", "bar", "baz"
+        }, List.class));
+    }
+
+    public void testStringArrayToPrimitiveWrappers() {
+        Long[] longs = (Long[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, Long[].class);
+        assertNotNull(longs);
+        assertTrue(Arrays.equals(new Long[]{new Long(123), new Long(456)}, longs));
+
+        Integer[] ints = (Integer[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, Integer[].class);
+        assertNotNull(ints);
+        assertTrue(Arrays.equals(new Integer[]{
+                new Integer(123), new Integer(456)
+        }, ints));
+
+        Double[] doubles = (Double[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, Double[].class);
+        assertNotNull(doubles);
+        assertTrue(Arrays.equals(new Double[]{new Double(123), new Double(456)}, doubles));
+
+        Float[] floats = (Float[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, Float[].class);
+        assertNotNull(floats);
+        assertTrue(Arrays.equals(new Float[]{new Float(123), new Float(456)}, floats));
+
+        Boolean[] booleans = (Boolean[]) converter.convertValue(context, null, null, null, new String[]{
+                "true", "false"
+        }, Boolean[].class);
+        assertNotNull(booleans);
+        assertTrue(Arrays.equals(new Boolean[]{Boolean.TRUE, Boolean.FALSE}, booleans));
+    }
+
+    public void testStringArrayToPrimitives() throws OgnlException {
+        long[] longs = (long[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, long[].class);
+        assertNotNull(longs);
+        assertTrue(Arrays.equals(new long[]{123, 456}, longs));
+
+        int[] ints = (int[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, int[].class);
+        assertNotNull(ints);
+        assertTrue(Arrays.equals(new int[]{123, 456}, ints));
+
+        double[] doubles = (double[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, double[].class);
+        assertNotNull(doubles);
+        assertTrue(Arrays.equals(new double[]{123, 456}, doubles));
+
+        float[] floats = (float[]) converter.convertValue(context, null, null, null, new String[]{
+                "123", "456"
+        }, float[].class);
+        assertNotNull(floats);
+        assertTrue(Arrays.equals(new float[]{123, 456}, floats));
+
+        boolean[] booleans = (boolean[]) converter.convertValue(context, null, null, null, new String[]{
+                "true", "false"
+        }, boolean[].class);
+        assertNotNull(booleans);
+        assertTrue(Arrays.equals(new boolean[]{true, false}, booleans));
+    }
+
+    public void testStringArrayToSet() {
+        Set<String> list = new HashSet<String>();
+        list.add("foo");
+        list.add("bar");
+        list.add("baz");
+        assertEquals(list, converter.convertValue(context, null, null, null, new String[]{
+                "foo", "bar", "bar", "baz"
+        }, Set.class));
+    }
+
+    // TODO: Fixme... This test does not work with GenericsObjectDeterminer!
+    public void testStringToCollectionConversion() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        Map<String, Object> stackContext = stack.getContext();
+        stackContext.put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
+        stackContext.put(ReflectionContextState.DENY_METHOD_EXECUTION, Boolean.TRUE);
+        stackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
+
+        AnnotationUser user = new AnnotationUser();
+        stack.push(user);
+
+        stack.setValue("list", "asdf");
+        assertNotNull(user.getList());
+        assertEquals(1, user.getList().size());
+        assertEquals(String.class, user.getList().get(0).getClass());
+        assertEquals("asdf", user.getList().get(0));
+    }
+
+    public void testStringToCustomTypeUsingCustomConverter() {
+        // the converter needs to be registered as the Bar.class converter
+        // it won't be detected from the Foo-conversion.properties
+        // because the Foo-conversion.properties file is only used when converting a property of Foo
+        converter.registerConverter(Bar.class.getName(), new FooBarConverter());
+
+        Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
+        assertNotNull("conversion failed", bar);
+        assertEquals(123, bar.getSomethingElse());
+        assertEquals("blah", bar.getTitle());
+    }
+
+    public void testStringToPrimitiveWrappers() {
+        assertEquals(new Long(123), converter.convertValue(context, null, null, null, "123", Long.class));
+        assertEquals(new Integer(123), converter.convertValue(context, null, null, null, "123", Integer.class));
+        assertEquals(new Double(123.5), converter.convertValue(context, null, null, null, "123.5", Double.class));
+        assertEquals(new Float(123.5), converter.convertValue(context, null, null, null, "123.5", float.class));
+        assertEquals(new Boolean(false), converter.convertValue(context, null, null, null, "false", Boolean.class));
+        assertEquals(new Boolean(true), converter.convertValue(context, null, null, null, "true", Boolean.class));
+    }
+
+    public void testStringToPrimitives() {
+        assertEquals(new Long(123), converter.convertValue(context, null, null, null, "123", long.class));
+        assertEquals(new Integer(123), converter.convertValue(context, null, null, null, "123", int.class));
+        assertEquals(new Double(123.5), converter.convertValue(context, null, null, null, "123.5", double.class));
+        assertEquals(new Float(123.5), converter.convertValue(context, null, null, null, "123.5", float.class));
+        assertEquals(new Boolean(false), converter.convertValue(context, null, null, null, "false", boolean.class));
+        assertEquals(new Boolean(true), converter.convertValue(context, null, null, null, "true", boolean.class));
+        assertEquals(new BigDecimal(123.5), converter.convertValue(context, null, null, null, "123.5", BigDecimal.class));
+        assertEquals(new BigInteger("123"), converter.convertValue(context, null, null, null, "123", BigInteger.class));
+    }
+
+    public void testValueStackWithTypeParameter() {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(new Foo1());
+        Bar1 bar = (Bar1) stack.findValue("bar", Bar1.class);
+        assertNotNull(bar);
+    }
+
+    public void testGenericProperties() {
+        GenericsBean gb = new GenericsBean();
+        ValueStack stack = ac.getValueStack();
+        stack.push(gb);
+
+        String[] value = new String[] {"123.12", "123.45"};
+        stack.setValue("doubles", value);
+        assertEquals(2, gb.getDoubles().size());
+        assertEquals(Double.class, gb.getDoubles().get(0).getClass());
+        assertEquals(new Double(123.12), gb.getDoubles().get(0));
+        assertEquals(new Double(123.45), gb.getDoubles().get(1));
+    }
+
+    public void testGenericPropertiesFromField() {
+        GenericsBean gb = new GenericsBean();
+        ValueStack stack = ac.getValueStack();
+        stack.push(gb);
+
+        stack.setValue("genericMap[123.12]", "66");
+        stack.setValue("genericMap[456.12]", "42");
+
+        assertEquals(2, gb.getGenericMap().size());
+        assertEquals(Integer.class, stack.findValue("genericMap.get(123.12).class"));
+        assertEquals(Integer.class, stack.findValue("genericMap.get(456.12).class"));
+        assertEquals(66, stack.findValue("genericMap.get(123.12)"));
+        assertEquals(42, stack.findValue("genericMap.get(456.12)"));
+        assertEquals(true, stack.findValue("genericMap.containsValue(66)"));
+        assertEquals(true, stack.findValue("genericMap.containsValue(42)"));
+        assertEquals(true, stack.findValue("genericMap.containsKey(123.12)"));
+        assertEquals(true, stack.findValue("genericMap.containsKey(456.12)"));
+    }
+
+    public void testGenericPropertiesFromSetter() {
+        GenericsBean gb = new GenericsBean();
+        ValueStack stack = ac.getValueStack();
+        stack.push(gb);
+
+        stack.setValue("genericMap[123.12]", "66");
+        stack.setValue("genericMap[456.12]", "42");
+
+        assertEquals(2, gb.getGenericMap().size());
+        assertEquals(Integer.class, stack.findValue("genericMap.get(123.12).class"));
+        assertEquals(Integer.class, stack.findValue("genericMap.get(456.12).class"));
+        assertEquals(66, stack.findValue("genericMap.get(123.12)"));
+        assertEquals(42, stack.findValue("genericMap.get(456.12)"));
+        assertEquals(true, stack.findValue("genericMap.containsValue(66)"));
+        assertEquals(true, stack.findValue("genericMap.containsValue(42)"));
+        assertEquals(true, stack.findValue("genericMap.containsKey(123.12)"));
+        assertEquals(true, stack.findValue("genericMap.containsKey(456.12)"));
+    }
+
+    public void testGenericPropertiesFromGetter() {
+        GenericsBean gb = new GenericsBean();
+        ValueStack stack = ac.getValueStack();
+        stack.push(gb);
+
+        assertEquals(1, gb.getGetterList().size());
+        assertEquals(Double.class, stack.findValue("getterList.get(0).class"));
+        assertEquals(new Double(42.42), stack.findValue("getterList.get(0)"));
+        assertEquals(new Double(42.42), gb.getGetterList().get(0));
+
+    }
+
+
+    // FIXME: Implement nested Generics such as: List of Generics List, Map of Generic keys/values, etc...
+    public void no_testGenericPropertiesWithNestedGenerics() {
+        GenericsBean gb = new GenericsBean();
+        ValueStack stack = ac.getValueStack();
+        stack.push(gb);
+
+        stack.setValue("extendedMap[123.12]", new String[] {"1", "2", "3", "4"});
+        stack.setValue("extendedMap[456.12]", new String[] {"5", "6", "7", "8", "9"});
+
+        System.out.println("gb.getExtendedMap(): " + gb.getExtendedMap());
+
+        assertEquals(2, gb.getExtendedMap().size());
+        System.out.println(stack.findValue("extendedMap"));
+        assertEquals(4, stack.findValue("extendedMap.get(123.12).size"));
+        assertEquals(5, stack.findValue("extendedMap.get(456.12).size"));
+
+        assertEquals("1", stack.findValue("extendedMap.get(123.12).get(0)"));
+        assertEquals("5", stack.findValue("extendedMap.get(456.12).get(0)"));
+        assertEquals(Integer.class, stack.findValue("extendedMap.get(123.12).get(0).class"));
+        assertEquals(Integer.class, stack.findValue("extendedMap.get(456.12).get(0).class"));
+
+        assertEquals(List.class, stack.findValue("extendedMap.get(123.12).class"));
+        assertEquals(List.class, stack.findValue("extendedMap.get(456.12).class"));
+
+    }
+
+    public static class Foo1 {
+        public Bar1 getBar() {
+            return new Bar1Impl();
+        }
+    }
+
+    public interface Bar1 {
+    }
+
+    public static class Bar1Impl implements Bar1 {
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        converter = container.getInstance(XWorkConverter.class);
+
+        ac = ActionContext.getContext();
+        ac.setLocale(Locale.US);
+        context = ac.getContextMap();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        ActionContext.setContext(null);
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.conversion.impl;
+
+import com.opensymphony.xwork2.util.AnnotatedCat;
+import com.opensymphony.xwork2.util.Bar;
+import com.opensymphony.xwork2.util.Cat;
+
+import java.lang.reflect.Member;
+import java.util.Map;
+
+
+/**
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class FooBarConverter extends DefaultTypeConverter {
+
+    @Override
+    public Object convertValue(Map<String, Object> context, Object value, Class toType) {
+        if (toType == String.class) {
+            Bar bar = (Bar) value;
+
+            return bar.getTitle() + ":" + bar.getSomethingElse();
+        } else if (toType == Bar.class) {
+            String valueStr = (String) value;
+            int loc = valueStr.indexOf(":");
+            String title = valueStr.substring(0, loc);
+            String rest = valueStr.substring(loc + 1);
+
+            Bar bar = new Bar();
+            bar.setTitle(title);
+            bar.setSomethingElse(Integer.parseInt(rest));
+
+            return bar;
+        } else if (toType == Cat.class) {
+            Cat cat = new Cat();
+            cat.setName((String) value);
+
+            return cat;
+        } else if (toType == AnnotatedCat.class) {
+            AnnotatedCat cat = new AnnotatedCat();
+            cat.setName((String) value);
+
+            return cat;
+        } else {
+            System.out.println("Don't know how to convert between " + value.getClass().getName() +
+                    " and " + toType.getName());
+        }
+
+        return null;
+    }
+
+    @Override
+    public Object convertValue(Map<String, Object> context, Object source, Member member, String property, Object value, Class toClass) {
+        return convertValue(context, value, toClass);
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooBarConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,18 @@
+package com.opensymphony.xwork2.conversion.impl;
+
+import java.util.Map;
+
+public class FooNumberConverter extends DefaultTypeConverter {
+    @Override
+    public Object convertValue(Map<String, Object> map, Object object, Class aClass) {
+        String s = (String) object;
+
+        int length = s.length();
+        StringBuilder r = new StringBuilder();
+        for (int i = length; i > 0; i--) {
+            r.append(s.charAt(i - 1));
+        }
+
+        return super.convertValue(map, r.toString(), aClass);
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/FooNumberConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.conversion.impl;
+
+import junit.framework.TestCase;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class InstantiatingNullHandlerTest extends TestCase {
+
+    public void testBlank() {
+
+    }
+    /*public void testInheritance() {
+        Tiger t = new Tiger();
+        CompoundRoot root = new CompoundRoot();
+        root.add(t);
+
+        Map context = new OgnlContext();
+        context.put(InstantiatingNullHandler.CREATE_NULL_OBJECTS, Boolean.TRUE);
+
+        InstantiatingNullHandler nh = new InstantiatingNullHandler();
+
+        Object dogList = nh.nullPropertyValue(context, root, "dogs");
+        Class clazz = nh.getCollectionType(Tiger.class, "dogs");
+        assertEquals(Dog.class, clazz);
+        assertNotNull(dogList);
+        assertTrue(dogList instanceof List);
+
+        Object kittenList = nh.nullPropertyValue(context, root, "kittens");
+        clazz = nh.getCollectionType(Tiger.class, "kittens");
+        assertEquals(Cat.class, clazz);
+        assertNotNull(kittenList);
+        assertTrue(kittenList instanceof List);
+    }*/
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/InstantiatingNullHandlerTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,27 @@
+package com.opensymphony.xwork2.conversion.impl;
+
+/**
+ * <code>ParentClass</code>
+ *
+ * @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
+ * @version $Id$
+ */
+public class ParentClass {
+
+    public enum NestedEnum {
+        TEST,
+        TEST2,
+        TEST3
+    }
+
+
+    private NestedEnum value;
+
+    public void setValue(NestedEnum value) {
+        this.value = value;
+    }
+
+    public NestedEnum getValue() {
+        return value;
+    }
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/ParentClass.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
URL: http://svn.apache.org/viewvc/struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java?rev=894087&view=auto
==============================================================================
--- struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java (added)
+++ struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java Sun Dec 27 18:00:13 2009
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.conversion.impl;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.XWorkException;
+import com.opensymphony.xwork2.test.annotations.Person;
+import junit.framework.TestCase;
+
+import java.text.DateFormat;
+import java.util.*;
+import java.lang.reflect.Member;
+
+/**
+ * Test case for XWorkBasicConverter
+ *
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class XWorkBasicConverterTest extends TestCase {
+
+    // TODO: test for every possible conversion
+    // take into account of empty string
+    // primitive -> conversion error when empty string is passed
+    // object -> return null when empty string is passed
+
+    public void testDateConversionWithEmptyValue() {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue(new HashMap<String, Object>(), null, null, null, "", Date.class);
+        // we must not get XWorkException as that will caused a conversion error
+        assertNull(convertedObject);
+    }
+
+    public void testDateConversionWithInvalidValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        try {
+            Object convertedObject = basicConverter.convertValue(new HashMap<String, Object>(), null, null, null, "asdsd", Date.class);
+            fail("XWorkException expected - conversion error occurred");
+        } catch (XWorkException e) {
+            // we MUST get this exception as this is a conversion error
+        }
+    }
+
+    public void testDateWithLocalePoland() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        Locale locale = new Locale("pl", "PL");
+        map.put(ActionContext.LOCALE, locale);
+
+        String reference = "2009-01-09";
+        Object convertedObject = basicConverter.convertValue(map, null, null, null, reference, Date.class);
+
+        assertNotNull(convertedObject);
+
+        compareDates(locale, convertedObject);
+    }
+
+    public void testDateWithLocaleFrance() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        Locale locale = new Locale("fr", "FR");
+        map.put(ActionContext.LOCALE, locale);
+
+        String reference = "09/01/2009";
+        Object convertedObject = basicConverter.convertValue(map, null, null, null, reference, Date.class);
+
+        assertNotNull(convertedObject);
+
+        compareDates(locale, convertedObject);
+    }
+
+    public void testDateWithLocaleUK() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        Locale locale = new Locale("en", "US");
+        map.put(ActionContext.LOCALE, locale);
+
+        String reference = "01/09/2009";
+        Object convertedObject = basicConverter.convertValue(map, null, null, null, reference, Date.class);
+
+        assertNotNull(convertedObject);
+
+        compareDates(locale, convertedObject);
+    }
+
+    private void compareDates(Locale locale, Object convertedObject) {
+        Calendar cal = Calendar.getInstance(locale);
+        cal.set(Calendar.YEAR, 2009);
+        cal.set(Calendar.MONTH, Calendar.JANUARY);
+        cal.set(Calendar.DATE, 9);
+
+        Calendar cal1 = Calendar.getInstance(locale);
+        cal1.setTime((Date) convertedObject);
+
+        assertEquals(cal.get(Calendar.YEAR), cal1.get(Calendar.YEAR));
+        assertEquals(cal.get(Calendar.MONTH), cal1.get(Calendar.MONTH));
+        assertEquals(cal.get(Calendar.DATE), cal1.get(Calendar.DATE));
+
+        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        assertEquals(df.format(cal.getTime()), df.format(convertedObject));
+    }
+
+    public void testEmptyArrayConversion() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue(new HashMap<String, Object>(), null, null, null, new Object[]{}, Object[].class);
+        // we must not get XWorkException as that will caused a conversion error
+        assertEquals(Object[].class, convertedObject.getClass());
+        Object[] obj = (Object[]) convertedObject;
+        assertEquals(0, obj.length);
+    }
+
+    public void testNullArrayConversion() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue(new HashMap<String, Object>(), null, null, null, null, Object[].class);
+        // we must not get XWorkException as that will caused a conversion error
+        assertNull(convertedObject);
+    }
+
+    /* the code below has been disabled as it causes sideffects in Strtus2 (XW-512)
+    public void testXW490ConvertStringToDouble() throws Exception {
+        Locale locale = new Locale("DA"); // let's use a not common locale such as Denmark
+
+        Map ctx = new HashMap();
+        ctx.put(ActionContext.LOCALE, locale);
+
+        XWorkBasicConverter conv = new XWorkBasicConverter();
+        // decimal seperator is , in Denmark so we should write 123,99 as input
+        Double value = (Double) conv.convertValue(ctx, null, null, null, "123,99", Double.class);
+        assertNotNull(value);
+
+        // output is as expected a real double value converted using Denmark as locale
+        assertEquals(123.99d, value.doubleValue(), 0.001d);
+    }
+
+    public void testXW49ConvertDoubleToString() throws Exception {
+        Locale locale = new Locale("DA"); // let's use a not common locale such as Denmark
+
+        Map ctx = new HashMap();
+        ctx.put(ActionContext.LOCALE, locale);
+
+        XWorkBasicConverter conv = new XWorkBasicConverter();
+        // decimal seperator is , in Denmark so we should write 123,99 as input
+        String value = (String) conv.convertValue(ctx, null, null, null, new Double("123.99"), String.class);
+        assertNotNull(value);
+
+        // output should be formatted according to Danish locale using , as decimal seperator
+        assertEquals("123,99", value);
+    }    
+    */
+
+    public void testDoubleValues() {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        assertTrue(basicConverter.isInRange(-1.2, "-1.2", Double.class));
+        assertTrue(basicConverter.isInRange(1.5, "1.5", Double.class));
+
+        Object value = basicConverter.convertValue("-1.3", double.class);
+        assertNotNull(value);
+        assertEquals(-1.3, value);
+
+        value = basicConverter.convertValue("1.8", double.class);
+        assertNotNull(value);
+        assertEquals(1.8, value);
+
+        value = basicConverter.convertValue("-1.9", double.class);
+        assertNotNull(value);
+        assertEquals(-1.9, value);
+
+        value = basicConverter.convertValue("1.7", Double.class);
+        assertNotNull(value);
+        assertEquals(1.7, value);
+
+        value = basicConverter.convertValue("0.0", Double.class);
+        assertNotNull(value);
+        assertEquals(0.0, value);
+
+        value = basicConverter.convertValue("0.0", double.class);
+        assertNotNull(value);
+        assertEquals(0.0, value);
+    }
+
+    public void testFloatValues() {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+
+        assertTrue(basicConverter.isInRange(-1.65, "-1.65", Float.class));
+        assertTrue(basicConverter.isInRange(1.9876, "1.9876", float.class));
+
+        Float value = (Float) basicConverter.convertValue("-1.444401", Float.class);
+        assertNotNull(value);
+        assertEquals(Float.valueOf("-1.444401"), value);
+
+        value = (Float) basicConverter.convertValue("1.46464989", Float.class);
+        assertNotNull(value);
+        assertEquals(Float.valueOf(1.46464989f), value);
+    }
+
+    public void testNegativeFloatValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("-94.1231233", Float.class);
+        assertTrue(convertedObject instanceof Float);
+        assertEquals(-94.1231233f, ((Float) convertedObject).floatValue(), 0.0001);
+    }
+
+    public void testPositiveFloatValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("94.1231233", Float.class);
+        assertTrue(convertedObject instanceof Float);
+        assertEquals(94.1231233f, ((Float) convertedObject).floatValue(), 0.0001);
+    }
+
+
+    public void testNegativeDoubleValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("-94.1231233", Double.class);
+        assertTrue(convertedObject instanceof Double);
+        assertEquals(-94.1231233d, ((Double) convertedObject).doubleValue(), 0.0001);
+    }
+
+    public void testPositiveDoubleValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue("94.1231233", Double.class);
+        assertTrue(convertedObject instanceof Double);
+        assertEquals(94.1231233d, ((Double) convertedObject).doubleValue(), 0.0001);
+    }
+
+    public void testNestedEnumValue() throws Exception {
+        XWorkBasicConverter basicConverter = new XWorkBasicConverter();
+        Object convertedObject = basicConverter.convertValue(ParentClass.NestedEnum.TEST.name(), ParentClass.NestedEnum.class);
+        assertTrue(convertedObject instanceof ParentClass.NestedEnum);
+        assertEquals(ParentClass.NestedEnum.TEST, convertedObject);
+    }
+
+
+    public void testConvert() {
+        XWorkBasicConverter converter = new XWorkBasicConverter();
+        Map context = new HashMap();
+        Person o = new Person();
+        Member member = null;
+        String s = "names";
+        Object value = new Person[0];
+        Class toType = String.class;
+        converter.convertValue(context, value, member, s, value, toType);
+    }     
+
+}

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/xwork/trunk/core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message