Anonymous avatar Anonymous committed 0077db5

Issue number: added test case for XW-319

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@750 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderResultTypesTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.config.providers;
+
+import java.util.Map;
+
+import com.opensymphony.xwork.config.ConfigurationProvider;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+import com.opensymphony.xwork.config.entities.PackageConfig;
+import com.opensymphony.xwork.config.entities.ResultConfig;
+import com.opensymphony.xwork.config.entities.ResultTypeConfig;
+import com.opensymphony.xwork.mock.MockResult;
+
+
+/**
+ * Test XmlConfigurationProvider's <result-types> ... </result-types>
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class XmlConfigurationProviderResultTypesTest extends ConfigurationTestBase {
+
+	public void testPlainResultTypesParams() throws Exception {
+		ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-result-types.xml");
+		
+		configurationProvider.init(configuration);
+		
+		PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage1");
+		Map resultTypesConfigMap = packageConfig.getResultTypeConfigs();
+		
+		assertEquals(resultTypesConfigMap.size(), 2);
+		assertTrue(resultTypesConfigMap.containsKey("result1"));
+		assertTrue(resultTypesConfigMap.containsKey("result2"));
+		assertFalse(resultTypesConfigMap.containsKey("result3"));
+		
+		ResultTypeConfig result1ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result1");
+		Map result1ParamsMap = result1ResultTypeConfig.getParams();
+		ResultTypeConfig result2ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result2");
+		Map result2ParamsMap = result2ResultTypeConfig.getParams();
+		
+		assertEquals(result1ResultTypeConfig.getName(), "result1");
+		assertEquals(result1ResultTypeConfig.getClazz(), MockResult.class);
+		assertEquals(result2ResultTypeConfig.getName(), "result2");
+		assertEquals(result2ResultTypeConfig.getClazz(), MockResult.class);
+		assertEquals(result1ParamsMap.size(), 3);
+		assertEquals(result2ParamsMap.size(), 2);
+		assertTrue(result1ParamsMap.containsKey("param1"));
+		assertTrue(result1ParamsMap.containsKey("param2"));
+		assertTrue(result1ParamsMap.containsKey("param3"));
+		assertFalse(result1ParamsMap.containsKey("param4"));
+		assertTrue(result2ParamsMap.containsKey("paramA"));
+		assertTrue(result2ParamsMap.containsKey("paramB"));
+		assertFalse(result2ParamsMap.containsKey("paramC"));
+		assertEquals(result1ParamsMap.get("param1"), "value1");
+		assertEquals(result1ParamsMap.get("param2"), "value2");
+		assertEquals(result1ParamsMap.get("param3"), "value3");
+		assertEquals(result2ParamsMap.get("paramA"), "valueA");
+		assertEquals(result2ParamsMap.get("paramB"), "valueB");
+	}
+	
+	public void testInheritedResultTypesParams() throws Exception {
+		ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-result-types.xml");
+		
+		configurationProvider.init(configuration);
+		
+		PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage2");
+		Map actionConfigMap = packageConfig.getActionConfigs();
+		
+		
+		ActionConfig action1ActionConfig = (ActionConfig) actionConfigMap.get("action1");
+		ActionConfig action2ActionConfig = (ActionConfig) actionConfigMap.get("action2");
+		
+		ResultConfig action1Result = (ResultConfig) action1ActionConfig.getResults().get("success");
+		ResultConfig action2Result = (ResultConfig) action2ActionConfig.getResults().get("success");
+		
+		assertEquals(action1Result.getName(), "success");
+		assertEquals(action1Result.getClassName(), "com.opensymphony.xwork.mock.MockResult");
+		assertEquals(action1Result.getName(), "success");
+		assertEquals(action1Result.getClassName(), "com.opensymphony.xwork.mock.MockResult");
+		
+		Map action1ResultMap = action1Result.getParams();
+		Map action2ResultMap = action2Result.getParams();
+		
+		assertEquals(action1ResultMap.size(), 5);
+		assertTrue(action1ResultMap.containsKey("param1"));
+		assertTrue(action1ResultMap.containsKey("param2"));
+		assertTrue(action1ResultMap.containsKey("param3"));
+		assertTrue(action1ResultMap.containsKey("param10"));
+		assertTrue(action1ResultMap.containsKey("param11"));
+		assertFalse(action1ResultMap.containsKey("param12"));
+		assertEquals(action1ResultMap.get("param1"), "newValue1");
+		assertEquals(action1ResultMap.get("param2"), "value2");
+		assertEquals(action1ResultMap.get("param3"), "newValue3");
+		assertEquals(action1ResultMap.get("param10"), "value10");
+		assertEquals(action1ResultMap.get("param11"), "value11");
+		
+		assertEquals(action2ResultMap.size(), 3);
+		assertTrue(action2ResultMap.containsKey("paramA"));
+		assertTrue(action2ResultMap.containsKey("paramB"));
+		assertTrue(action2ResultMap.containsKey("paramZ"));
+		assertFalse(action2ResultMap.containsKey("paramY"));
+		assertEquals(action2ResultMap.get("paramA"), "valueA");
+		assertEquals(action2ResultMap.get("paramB"), "newValueB");
+		assertEquals(action2ResultMap.get("paramZ"), "valueZ");
+		
+		
+	}
+}
+
+

src/test/com/opensymphony/xwork/config/providers/xwork-test-result-types.xml

+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE xwork PUBLIC 
+	"-//OpenSymphony Group//XWork 1.0//EN" 
+	"http://www.opensymphony.com/xwork/xwork-1.1.dtd">
+ 
+<xwork>
+	<package name="xworkResultTypesTestPackage1">
+		<result-types>
+			<result-type name="result1" class="com.opensymphony.xwork.mock.MockResult" >
+				<param name="param1">value1</param>
+				<param name="param2">value2</param>
+				<param name="param3">value3</param>
+			</result-type>
+			<result-type name="result2" class="com.opensymphony.xwork.mock.MockResult">
+				<param name="paramA">valueA</param>
+				<param name="paramB">valueB</param>
+			</result-type>
+		</result-types>
+	</package>
+	
+	
+	<package name="xworkResultTypesTestPackage2">
+		<result-types>
+			<result-type name="result1" class="com.opensymphony.xwork.mock.MockResult" >
+				<param name="param1">value1</param>
+				<param name="param2">value2</param>
+				<param name="param3">value3</param>
+			</result-type>
+			<result-type name="result2" class="com.opensymphony.xwork.mock.MockResult">
+				<param name="paramA">valueA</param>
+				<param name="paramB">valueB</param>
+			</result-type>
+		</result-types>
+		
+		<action name="action1">
+			<result name="success" type="result1">
+				<param name="param1">newValue1</param>
+				<param name="param3">newValue3</param>
+				<param name="param10">value10</param>
+				<param name="param11">value11</param>
+			</result>
+		</action>
+		
+		<action name="action2">
+			<result name="success" type="result2">
+				<param name="paramB">newValueB</param>
+				<param name="paramZ">valueZ</param>
+			</result>
+		</action>
+	</package>
+	
+</xwork>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.