Skip to content

Commit

Permalink
WW-3832 Solves problem when not using flat layout with Convention plugin
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1535364 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lukaszlenart committed Oct 24, 2013
1 parent a305897 commit 11228e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);

Expand Down

0 comments on commit 11228e6

Please sign in to comment.