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