Search in sources :

Example 41 with Location

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);
}
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 42 with Location

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);
}
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 43 with Location

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);
}
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 44 with Location

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"));
}
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)

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

Aggregations

ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)32 ServletContext (javax.servlet.ServletContext)22 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)21 HashSet (java.util.HashSet)15 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)11 ActionContext (com.opensymphony.xwork2.ActionContext)10 ValueStack (com.opensymphony.xwork2.util.ValueStack)10 HashMap (java.util.HashMap)9 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)8 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)8 ServletActionContext (org.apache.struts2.ServletActionContext)8 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)7 Location (com.opensymphony.xwork2.util.location.Location)7 ArrayList (java.util.ArrayList)7 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 NodeList (org.w3c.dom.NodeList)6 ActionProxy (com.opensymphony.xwork2.ActionProxy)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5