Adding support for multiple parent packages to be defined at the package level, adding more

restrictions on the namespace, parentpackage, and results annotations


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@667742 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2008-06-14 04:20:22 +00:00
parent 5030b89b33
commit 873d150890
7 changed files with 129 additions and 17 deletions
@@ -39,7 +39,13 @@ public class ClasspathPackageProviderTest extends TestCase {
public void setUp() throws Exception {
provider = new ClasspathPackageProvider();
provider.setActionPackages("org.apache.struts2.config");
config = new DefaultConfiguration();
config = createNewConfiguration();
provider.init(config);
provider.loadPackages();
}
private Configuration createNewConfiguration() {
Configuration config = new DefaultConfiguration();
PackageConfig strutsDefault = new PackageConfig.Builder("struts-default")
.addResultTypeConfig(new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName())
.defaultResultParam("location")
@@ -51,17 +57,16 @@ public class ClasspathPackageProviderTest extends TestCase {
.namespace("/custom")
.build();
config.addPackageConfig("custom-package", customPackage);
provider.init(config);
provider.loadPackages();
return config;
}
public void tearDown() throws Exception {
provider = null;
config = null;
}
public void testFoundRootPackages() {
assertEquals(6, config.getPackageConfigs().size());
assertEquals(7, config.getPackageConfigs().size());
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
assertNotNull(pkg);
Map configs = pkg.getActionConfigs();
@@ -91,6 +96,23 @@ public class ClasspathPackageProviderTest extends TestCase {
assertEquals("/custom", pkg.getNamespace());
}
public void testParentPackageOnPackage() {
provider = new ClasspathPackageProvider();
provider.setActionPackages("org.apache.struts2.config.parenttest");
provider.init(createNewConfiguration());
provider.loadPackages();
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.parenttest");
// assertEquals(2, pkg.getParents().size());
assertNotNull(pkg);
assertEquals("custom-package", pkg.getParents().get(0).getName());
Map configs = pkg.getActionConfigs();
ActionConfig config = (ActionConfig) configs.get("some");
assertNotNull(config);
}
public void testCustomNamespace() {
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.CustomNamespaceAction");
Map configs = pkg.getAllActionConfigs();
@@ -0,0 +1,30 @@
/*
* $Id: ParentPackage.java 651946 2008-04-27 13:41:38Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.struts2.config.parenttest;
import com.opensymphony.xwork2.Action;
public class SomeAction implements Action {
public String execute() throws Exception {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,24 @@
/*
* $Id: ParentPackage.java 651946 2008-04-27 13:41:38Z apetrelli $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
@ParentPackage("custom-package")
package org.apache.struts2.config.parenttest;
import org.apache.struts2.config.ParentPackage;