Search in sources :

Example 16 with Builder

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);
}
Also used : ClassLevelResultPathAction(org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction) NoAnnotationAction(org.apache.struts2.convention.actions.NoAnnotationAction) Action(org.apache.struts2.convention.annotation.Action) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Example 17 with Builder

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"));
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 18 with Builder

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"));
}
Also used : ServletDispatcherResult(org.apache.struts2.result.ServletDispatcherResult) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 19 with Builder

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);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Example 20 with Builder

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);
}
Also used : ClassLevelResultPathAction(org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction) NoAnnotationAction(org.apache.struts2.convention.actions.NoAnnotationAction) Action(org.apache.struts2.convention.annotation.Action) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Aggregations

PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)23 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)21 ServletContext (javax.servlet.ServletContext)21 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)19 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)18 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)17 HashSet (java.util.HashSet)14 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)10 NoAnnotationAction (org.apache.struts2.convention.actions.NoAnnotationAction)7 ClassLevelResultPathAction (org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction)6 Action (org.apache.struts2.convention.annotation.Action)6 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)4 Configuration (com.opensymphony.xwork2.config.Configuration)4 Container (com.opensymphony.xwork2.inject.Container)4 Context (com.opensymphony.xwork2.inject.Context)4 ArrayList (java.util.ArrayList)4 ActionContext (com.opensymphony.xwork2.ActionContext)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)3 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)3 StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)3