mirror of
https://github.com/apache/struts.git
synced 2026-09-14 01:45:12 +00:00
Moving zero config code into codebehind plugin, minor fix to showcase
WW-2247 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@584166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+8
-1
@@ -22,6 +22,7 @@ package org.apache.struts2.codebehind;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -34,9 +35,11 @@ import com.mockobjects.dynamic.C;
|
||||
import com.mockobjects.dynamic.Mock;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxyFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
|
||||
|
||||
public class CodebehindUnknownHandlerTest extends StrutsTestCase {
|
||||
|
||||
@@ -44,7 +47,11 @@ public class CodebehindUnknownHandlerTest extends StrutsTestCase {
|
||||
Mock mockServletContext;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
configurationManager = XWorkTestCaseHelper.setUp();
|
||||
configuration = configurationManager.getConfiguration();
|
||||
container = configuration.getContainer();
|
||||
actionProxyFactory = container.getInstance(ActionProxyFactory.class);
|
||||
initDispatcher(Collections.singletonMap("actionPackages", "foo.bar"));
|
||||
mockServletContext = new Mock(ServletContext.class);
|
||||
handler = new CodebehindUnknownHandler("codebehind-default", configuration);
|
||||
handler.setPathPrefix("/");
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* $Id: ClasspathPackageProviderTest.java 501717 2007-01-31 03:51:11Z mrdon $
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.dispatcher.ServletDispatcherResult;
|
||||
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ClasspathPackageProviderTest extends TestCase {
|
||||
|
||||
ClasspathPackageProvider provider;
|
||||
Configuration config;
|
||||
|
||||
public void setUp() {
|
||||
provider = new ClasspathPackageProvider();
|
||||
provider.setActionPackages("org.apache.struts2.config");
|
||||
config = new DefaultConfiguration();
|
||||
PackageConfig strutsDefault = new PackageConfig("struts-default");
|
||||
strutsDefault.addResultTypeConfig(new ResultTypeConfig("dispatcher", ServletDispatcherResult.class.getName(), "location"));
|
||||
strutsDefault.setDefaultResultType("dispatcher");
|
||||
config.addPackageConfig("struts-default", strutsDefault);
|
||||
PackageConfig customPackage = new PackageConfig("custom-package");
|
||||
customPackage.setNamespace("/custom");
|
||||
config.addPackageConfig("custom-package", customPackage);
|
||||
provider.init(config);
|
||||
provider.loadPackages();
|
||||
}
|
||||
|
||||
public void testFoundRootPackages() {
|
||||
assertEquals(5, config.getPackageConfigs().size());
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
|
||||
assertNotNull(pkg);
|
||||
Map configs = pkg.getActionConfigs();
|
||||
assertNotNull(configs);
|
||||
// assertEquals(1, configs.size());
|
||||
ActionConfig actionConfig = (ActionConfig) configs.get("customParentPackage");
|
||||
assertNotNull(actionConfig);
|
||||
}
|
||||
|
||||
public void testParentPackage() {
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
|
||||
// assertEquals(2, pkg.getParents().size());
|
||||
Map configs = pkg.getActionConfigs();
|
||||
ActionConfig config = (ActionConfig) configs.get("customParentPackage");
|
||||
assertNotNull(config);
|
||||
assertEquals("/custom", pkg.getNamespace());
|
||||
}
|
||||
|
||||
public void testCustomNamespace() {
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.CustomNamespaceAction");
|
||||
Map configs = pkg.getAllActionConfigs();
|
||||
// assertEquals(2, configs.size());
|
||||
ActionConfig config = (ActionConfig) configs.get("customNamespace");
|
||||
assertEquals(config.getPackageName(), pkg.getName());
|
||||
assertEquals(1, pkg.getParents().size());
|
||||
assertNotNull(config);
|
||||
assertEquals("/mynamespace", pkg.getNamespace());
|
||||
ActionConfig ac = (ActionConfig) configs.get("customParentPackage");
|
||||
assertNotNull(ac);
|
||||
}
|
||||
|
||||
public void testResultAnnotations() {
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.cltest");
|
||||
assertEquals("/cltest", pkg.getNamespace());
|
||||
ActionConfig acfg = pkg.getActionConfigs().get("twoResult");
|
||||
assertNotNull(acfg);
|
||||
assertEquals(3, acfg.getResults().size());
|
||||
}
|
||||
|
||||
public void testActionImplementation() {
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config.cltest");
|
||||
assertEquals("/cltest", pkg.getNamespace());
|
||||
ActionConfig acfg = pkg.getActionConfigs().get("actionImpl");
|
||||
assertNotNull(acfg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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;
|
||||
|
||||
@Namespace("/mynamespace")
|
||||
public class CustomNamespaceAction {
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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;
|
||||
|
||||
@ParentPackage("custom-package")
|
||||
public class CustomParentPackageAction {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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.cltest;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
|
||||
public class ActionImpl implements Action {
|
||||
|
||||
public String execute() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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.cltest;
|
||||
|
||||
import org.apache.struts2.config.Result;
|
||||
|
||||
@Result("foo.jsp")
|
||||
public class OneResultAction {
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* 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.cltest;
|
||||
|
||||
import org.apache.struts2.config.Result;
|
||||
import org.apache.struts2.config.Results;
|
||||
import org.apache.struts2.dispatcher.ServletDispatcherResult;
|
||||
|
||||
|
||||
@Results({
|
||||
@Result(name="chain", value="bob", type=ServletDispatcherResult.class),
|
||||
@Result(name="input", value="input.jsp")
|
||||
})
|
||||
public class TwoResultAction extends OneResultAction {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user