001: /*
002: * $Id: ClasspathConfigurationProviderTest.java 501717 2007-01-31 03:51:11Z mrdon $
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: package org.apache.struts2.config;
022:
023: import java.util.Map;
024:
025: import org.apache.struts2.dispatcher.ServletDispatcherResult;
026:
027: import com.opensymphony.xwork2.config.Configuration;
028: import com.opensymphony.xwork2.config.entities.ActionConfig;
029: import com.opensymphony.xwork2.config.entities.PackageConfig;
030: import com.opensymphony.xwork2.config.entities.ResultConfig;
031: import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
032: import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
033:
034: import junit.framework.TestCase;
035:
036: public class ClasspathConfigurationProviderTest extends TestCase {
037:
038: ClasspathConfigurationProvider provider;
039: Configuration config;
040:
041: public void setUp() {
042: provider = new ClasspathConfigurationProvider(
043: new String[] { "org.apache.struts2.config" });
044: config = new DefaultConfiguration();
045: PackageConfig strutsDefault = new PackageConfig(
046: "struts-default");
047: strutsDefault.addResultTypeConfig(new ResultTypeConfig(
048: "dispatcher", ServletDispatcherResult.class.getName(),
049: "location"));
050: strutsDefault.setDefaultResultType("dispatcher");
051: config.addPackageConfig("struts-default", strutsDefault);
052: PackageConfig customPackage = new PackageConfig(
053: "custom-package");
054: customPackage.setNamespace("/custom");
055: config.addPackageConfig("custom-package", customPackage);
056: provider.init(config);
057: provider.loadPackages();
058: }
059:
060: public void testFoundRootPackages() {
061: assertEquals(5, config.getPackageConfigs().size());
062: PackageConfig pkg = config
063: .getPackageConfig("org.apache.struts2.config");
064: assertNotNull(pkg);
065: Map configs = pkg.getActionConfigs();
066: assertNotNull(configs);
067: // assertEquals(1, configs.size());
068: ActionConfig actionConfig = (ActionConfig) configs
069: .get("customParentPackage");
070: assertNotNull(actionConfig);
071: }
072:
073: public void testParentPackage() {
074: PackageConfig pkg = config
075: .getPackageConfig("org.apache.struts2.config");
076: // assertEquals(2, pkg.getParents().size());
077: Map configs = pkg.getActionConfigs();
078: ActionConfig config = (ActionConfig) configs
079: .get("customParentPackage");
080: assertNotNull(config);
081: assertEquals("/custom", pkg.getNamespace());
082: }
083:
084: public void testCustomNamespace() {
085: PackageConfig pkg = config
086: .getPackageConfig("org.apache.struts2.config.CustomNamespaceAction");
087: Map configs = pkg.getAllActionConfigs();
088: // assertEquals(2, configs.size());
089: ActionConfig config = (ActionConfig) configs
090: .get("customNamespace");
091: assertEquals(config.getPackageName(), pkg.getName());
092: assertEquals(1, pkg.getParents().size());
093: assertNotNull(config);
094: assertEquals("/mynamespace", pkg.getNamespace());
095: ActionConfig ac = (ActionConfig) configs
096: .get("customParentPackage");
097: assertNotNull(ac);
098: }
099:
100: public void testResultAnnotations() {
101: PackageConfig pkg = config
102: .getPackageConfig("org.apache.struts2.config.cltest");
103: assertEquals("/cltest", pkg.getNamespace());
104: ActionConfig acfg = pkg.getActionConfigs().get("twoResult");
105: assertNotNull(acfg);
106: assertEquals(3, acfg.getResults().size());
107: }
108:
109: public void testActionImplementation() {
110: PackageConfig pkg = config
111: .getPackageConfig("org.apache.struts2.config.cltest");
112: assertEquals("/cltest", pkg.getNamespace());
113: ActionConfig acfg = pkg.getActionConfigs().get("actionImpl");
114: assertNotNull(acfg);
115: }
116: }
|