Search in sources :

Example 21 with Builder

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

the class DefaultResultMapBuilderTest method testBuild.

public void testBuild() 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");
    Map<String, ResultConfig> results = builder.build(NoAnnotationAction.class, null, "action", packageConfig);
    verify(context, "/WEB-INF/location", results, false);
    // Test without a slash
    context = mockServletContext("/WEB-INF/location");
    packageConfig = createPackageConfigBuilder("namespace");
    this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
    builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
    results = builder.build(NoAnnotationAction.class, null, "action", packageConfig);
    verify(context, "/WEB-INF/location", results, false);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) NoAnnotationAction(org.apache.struts2.convention.actions.NoAnnotationAction) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 22 with Builder

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

the class DefaultResultMapBuilderTest method testGlobalResultOverride.

public void testGlobalResultOverride() throws Exception {
    ServletContext context = EasyMock.createStrictMock(ServletContext.class);
    String resultPath = "/WEB-INF/location";
    // Setup some mock jsps
    Set<String> resources = new HashSet<>();
    resources.add(resultPath + "/namespace/action.jsp");
    resources.add(resultPath + "/namespace/action-success.jsp");
    resources.add(resultPath + "/namespace/action-error.jsp");
    EasyMock.expect(context.getResourcePaths(resultPath + "/namespace/")).andReturn(resources);
    EasyMock.replay(context);
    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(GlobalResultOverrideAction.class, null, "action", packageConfig);
    ResultConfig result = results.get("error");
    assertNotNull(result);
    assertEquals(resultPath + "/namespace/action-error.jsp", result.getParams().get("location"));
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) ServletDispatcherResult(org.apache.struts2.result.ServletDispatcherResult) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) ServletContext(javax.servlet.ServletContext) HashSet(java.util.HashSet)

Example 23 with Builder

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

the class DefaultResultMapBuilderTest method testFromServletContext.

public void testFromServletContext() 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.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/")).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(4, 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("input").getParams().size());
    assertEquals("org.apache.struts2.views.freemarker.FreemarkerResult", results.get("input").getClassName());
    assertEquals("/WEB-INF/location/namespace/no-annotation.ftl", results.get("input").getParams().get("location"));
    assertEquals(1, results.get("error").getParams().size());
    assertEquals("org.apache.struts2.views.freemarker.FreemarkerResult", results.get("error").getClassName());
    assertEquals("/WEB-INF/location/namespace/no-annotation.ftl", results.get("error").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 24 with Builder

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

the class SpringObjectFactoryTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    sac = new StaticApplicationContext();
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            // No registered beans during initialization; They will be registered in each test, runtime.
            props.setProperty("applicationContextPath", "com/opensymphony/xwork2/spring/emptyContext-spring.xml");
            builder.factory(TextProvider.class, DummyTextProvider.class);
            builder.factory(ObjectFactory.class, SpringObjectFactory.class);
        }
    });
    objectFactory = (SpringObjectFactory) container.getInstance(ObjectFactory.class);
    objectFactory.setApplicationContext(sac);
    objectFactory.setAlwaysRespectAutowireStrategy(false);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) DummyTextProvider(com.opensymphony.xwork2.mock.DummyTextProvider) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) DummyTextProvider(com.opensymphony.xwork2.mock.DummyTextProvider) TextProvider(com.opensymphony.xwork2.TextProvider)

Example 25 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project entando-core by entando.

the class ApsAdminBaseTestCase method createContainer.

protected Container createContainer() {
    ContainerBuilder builder = new ContainerBuilder();
    builder.constant("devMode", "false");
    return builder.create(true);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder)

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