001: /*
002: * $Id: ConfigTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package example;
023:
024: import com.opensymphony.xwork2.ActionSupport;
025: import com.opensymphony.xwork2.config.RuntimeConfiguration;
026: import com.opensymphony.xwork2.config.entities.ActionConfig;
027: import com.opensymphony.xwork2.config.entities.ResultConfig;
028: import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
029:
030: import java.util.Map;
031: import java.util.List;
032:
033: import org.apache.struts2.StrutsTestCase;
034:
035: public class ConfigTest extends StrutsTestCase {
036:
037: protected void assertSuccess(String result) throws Exception {
038: assertTrue("Expected a success result!", ActionSupport.SUCCESS
039: .equals(result));
040: }
041:
042: protected void assertInput(String result) throws Exception {
043: assertTrue("Expected an input result!", ActionSupport.INPUT
044: .equals(result));
045: }
046:
047: protected Map assertFieldErrors(ActionSupport action)
048: throws Exception {
049: assertTrue(action.hasFieldErrors());
050: return action.getFieldErrors();
051: }
052:
053: protected void assertFieldError(Map field_errors,
054: String field_name, String error_message) {
055:
056: List errors = (List) field_errors.get(field_name);
057: assertNotNull("Expected errors for " + field_name, errors);
058: assertTrue("Expected errors for " + field_name,
059: errors.size() > 0);
060: // TODO: Should be a loop
061: assertEquals(error_message, errors.get(0));
062:
063: }
064:
065: protected void setUp() throws Exception {
066: super .setUp();
067: XmlConfigurationProvider c = new XmlConfigurationProvider(
068: "struts.xml");
069: configurationManager.addConfigurationProvider(c);
070: configurationManager.reload();
071: }
072:
073: protected ActionConfig assertClass(String namespace,
074: String action_name, String class_name) {
075: RuntimeConfiguration configuration = configurationManager
076: .getConfiguration().getRuntimeConfiguration();
077: ActionConfig config = configuration.getActionConfig(namespace,
078: action_name);
079: assertNotNull("Mssing action", config);
080: assertTrue("Wrong class name: [" + config.getClassName() + "]",
081: class_name.equals(config.getClassName()));
082: return config;
083: }
084:
085: protected ActionConfig assertClass(String action_name,
086: String class_name) {
087: return assertClass("", action_name, class_name);
088: }
089:
090: protected void assertResult(ActionConfig config,
091: String result_name, String result_value) {
092: Map results = config.getResults();
093: ResultConfig result = (ResultConfig) results.get(result_name);
094: Map params = result.getParams();
095: String value = (String) params.get("actionName");
096: if (value == null)
097: value = (String) params.get("location");
098: assertTrue("Wrong result value: [" + value + "]", result_value
099: .equals(value));
100: }
101:
102: public void testConfig() throws Exception {
103: assertNotNull(configurationManager);
104: }
105:
106: }
|