Search in sources :

Example 31 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder 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 32 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder 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 33 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder 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 34 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class DefaultResultMapBuilderTest method testResultPath.

public void testResultPath() throws Exception {
    ServletContext context = mockServletContext("/class-level");
    // Test with a result path
    PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
    this.conventionsService = new ConventionsServiceImpl("/not-used");
    DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
    Map<String, ResultConfig> results = builder.build(ClassLevelResultPathAction.class, null, "action", packageConfig);
    verify(context, "/class-level", results, false);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 35 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder 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

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