use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testActionLevelMultipleResultNamesAnnotationNoName.
public void testActionLevelMultipleResultNamesAnnotationNoName() 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(ActionLevelResultsNamesAction.class, getAnnotation(ActionLevelResultsNamesAction.class, "noname", Action.class), "action-level-results", packageConfig);
assertEquals(1, results.size());
assertEquals("success", results.get("success").getName());
assertEquals(3, results.get("success").getParams().size());
assertEquals("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").getParams().get("key1"));
assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testClassPath.
public void testClassPath() throws Exception {
ServletContext context = EasyMock.createNiceMock(ServletContext.class);
ResultTypeConfig resultType = new ResultTypeConfig.Builder("freemarker", "org.apache.struts2.result.ServletDispatcherResult").defaultResultParam("location").build();
PackageConfig packageConfig = new PackageConfig.Builder("package").defaultResultType("dispatcher").addResultTypeConfig(resultType).build();
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/component");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "no-annotation", packageConfig);
assertEquals(4, results.size());
assertEquals("input", results.get("input").getName());
assertEquals("error", results.get("error").getName());
assertEquals("success", results.get("success").getName());
assertEquals("foo", results.get("foo").getName());
assertEquals(1, results.get("success").getParams().size());
assertEquals("/WEB-INF/component/no-annotation.ftl", results.get("success").getParams().get("location"));
assertEquals(1, results.get("input").getParams().size());
assertEquals("/WEB-INF/component/no-annotation.ftl", results.get("input").getParams().get("location"));
assertEquals(1, results.get("error").getParams().size());
assertEquals("/WEB-INF/component/no-annotation.ftl", results.get("error").getParams().get("location"));
assertEquals(1, results.get("foo").getParams().size());
assertEquals("/WEB-INF/component/no-annotation-foo.ftl", results.get("foo").getParams().get("location"));
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testGlobalResult.
public void testGlobalResult() throws Exception {
ServletContext context = mockServletContext("/WEB-INF/location");
this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName()).addParam("key", "value").addParam("key1", "value1").defaultResultParam("location").build();
ResultConfig globalError = new ResultConfig.Builder("error", ServletDispatcherResult.class.getName()).addParam("location", "/globalError.jsp").build();
PackageConfig packageConfig = new PackageConfig.Builder("package").namespace("/namespace").defaultResultType("dispatcher").addResultTypeConfig(resultType).addGlobalResultConfig(globalError).build();
Map<String, ResultConfig> results = builder.build(GlobalResultAction.class, null, "action", packageConfig);
ResultConfig result = results.get("error");
assertNotNull(result);
assertEquals("/globalError.jsp", result.getParams().get("location"));
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testFromServletContextNotFlat.
public void testFromServletContextNotFlat() 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/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.result.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.result.ServletDispatcherResult", results.get("success").getClassName());
assertEquals("/WEB-INF/location/namespace/no-annotation/failure.jsp", results.get("failure").getParams().get("location"));
EasyMock.verify(context);
}
use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.
the class DefaultResultMapBuilderTest method testActionLevelMultipleResultAnnotation.
public void testActionLevelMultipleResultAnnotation() 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(ActionLevelResultsAction.class, getAnnotation(ActionLevelResultsAction.class, "execute", Action.class), "action-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("value", results.get("success").getParams().get("key"));
assertEquals("value1", results.get("success").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(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());
EasyMock.verify(context);
}
Aggregations