use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class DefaultResultMapBuilderTest method testClassLevelMultipleResultAnnotation.
public void testClassLevelMultipleResultAnnotation() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).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");
Map<String, ResultConfig> results = builder.build(ClassLevelResultsAction.class, null, "class-level-results", packageConfig);
assertEquals(4, results.size());
assertEquals("error", results.get("error").getName());
assertEquals("input", results.get("input").getName());
assertEquals("success", results.get("success").getName());
assertEquals("failure", results.get("failure").getName());
assertEquals(3, results.get("error").getParams().size());
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
assertEquals("ann-value", results.get("error").getParams().get("key"));
assertEquals("ann-value1", results.get("error").getParams().get("key1"));
assertEquals(1, results.get("input").getParams().size());
assertEquals("foo.action", results.get("input").getParams().get("actionName"));
assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName());
assertEquals(3, results.get("failure").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName());
assertEquals("value", results.get("failure").getParams().get("key"));
assertEquals("value1", results.get("failure").getParams().get("key1"));
assertEquals(3, results.get("success").getParams().size());
assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").getParams().get("key1"));
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class DefaultResultMapBuilderTest method testActionLevelSingleResultAnnotation.
public void testActionLevelSingleResultAnnotation() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).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");
Map<String, ResultConfig> results = builder.build(ActionLevelResultAction.class, getAnnotation(ActionLevelResultAction.class, "execute", Action.class), "action-level-result", packageConfig);
assertEquals(1, results.size());
assertEquals("success", results.get("success").getName());
assertEquals(3, results.get("success").getParams().size());
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
assertEquals("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").getParams().get("key1"));
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class DefaultResultMapBuilderTest method testClassLevelSingleResultAnnotation.
public void testClassLevelSingleResultAnnotation() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).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");
Map<String, ResultConfig> results = builder.build(ClassLevelResultAction.class, null, "class-level-result", packageConfig);
assertEquals(1, results.size());
assertEquals("error", results.get("error").getName());
assertEquals(3, results.get("error").getParams().size());
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
assertEquals("value", results.get("error").getParams().get("key"));
assertEquals("value1", results.get("error").getParams().get("key1"));
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class DefaultResultMapBuilderTest method testResultOverrride.
public void testResultOverrride() throws Exception {
ServletContext context = mockServletContext("/WEB-INF/location");
// Test with a slash
PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Action actionAnn = OverrideResultAction.class.getMethod("execute").getAnnotation(Action.class);
Map<String, ResultConfig> results = builder.build(OverrideResultAction.class, actionAnn, "action100", packageConfig);
ResultConfig result = results.get("error");
assertNotNull(result);
assertEquals("/WEB-INF/location/namespace/error-overriden.jsp", result.getParams().get("location"));
}
use of com.opensymphony.xwork2.util.location.Location in project struts by apache.
the class DefaultResultMapBuilderTest method testIgnoreFilesWithoutName.
public void testIgnoreFilesWithoutName() throws Exception {
ServletContext context = EasyMock.createStrictMock(ServletContext.class);
// Setup some mock jsps
Set<String> resources = new HashSet<>();
resources.add("/WEB-INF/location/namespace/no-annotation/.svn");
resources.add("/WEB-INF/location/namespace/no-annotation-success.jsp");
EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).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");
Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "no-annotation", packageConfig);
assertEquals(1, results.size());
assertEquals("success", results.get("success").getName());
assertEquals(3, results.get("success").getParams().size());
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("/WEB-INF/location/namespace/no-annotation-success.jsp", results.get("success").getParams().get("location"));
EasyMock.verify(context);
}
Aggregations