WW-3832 Solves problem when not using flat layout with Convention plugin

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1535364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lukasz Lenart
2013-10-24 12:50:37 +00:00
parent a305897c2b
commit 11228e643c
2 changed files with 37 additions and 1 deletions
@@ -359,7 +359,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
int indexOfDot = path.indexOf('.', resultPrefix.length());
// This case is when the path doesn't contain a result code
if (indexOfDot == resultPrefix.length() || !flatResultLayout) {
if (indexOfDot == resultPrefix.length()) {
if (LOG.isTraceEnabled()) {
LOG.trace("The result file [#0] has no result code and therefore" +
" will be associated with success, input and error by default. This might" +
@@ -229,6 +229,42 @@ public class DefaultResultMapBuilderTest extends TestCase {
}
public void testFromServletContextNotFlat() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<String>();
resources.add("/WEB-INF/location/namespace/no-annotation/index.ftl");
resources.add("/WEB-INF/location/namespace/no-annotation/success.jsp");
resources.add("/WEB-INF/location/namespace/no-annotation/failure.jsp");
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/no-annotation")).andReturn(resources);
EasyMock.replay(context);
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
builder.setFlatResultLayout("false");
Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "no-annotation", packageConfig);
assertEquals(3, results.size());
assertEquals("success", results.get("success").getName());
assertEquals(3, results.get("success").getParams().size());
assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("/WEB-INF/location/namespace/no-annotation/success.jsp", results.get("success").getParams().get("location"));
assertEquals(1, results.get("index").getParams().size());
assertEquals("org.apache.struts2.views.freemarker.FreemarkerResult", results.get("index").getClassName());
assertEquals("/WEB-INF/location/namespace/no-annotation/index.ftl", results.get("index").getParams().get("location"));
assertEquals(3, results.get("failure").getParams().size());
assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("/WEB-INF/location/namespace/no-annotation/failure.jsp", results.get("failure").getParams().get("location"));
EasyMock.verify(context);
}
public void testIgnoreFilesWithoutName() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);