diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java b/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java index adb26306f3..a9f44bde4c 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/DefaultResultMapBuilder.java @@ -359,7 +359,7 @@ protected void makeResults(Class actionClass, String path, String resultPrefi 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" + diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java index c1c1b2f4bd..de7ab16393 100644 --- a/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java @@ -229,6 +229,42 @@ public void testFromServletContext() throws Exception { } + public void testFromServletContextNotFlat() throws Exception { + ServletContext context = EasyMock.createStrictMock(ServletContext.class); + + // Setup some mock jsps + Set resources = new HashSet(); + 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 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);