use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class StrutsJavaConfigurationProviderTest method testRegister.
@Test
public void testRegister() throws Exception {
final ConstantConfig constantConfig = new ConstantConfig();
constantConfig.setDevMode(true);
final String expectedUnknownHandler = "expectedUnknownHandler";
StrutsJavaConfiguration javaConfig = new StrutsJavaConfiguration() {
@Override
public List<String> unknownHandlerStack() {
return Collections.singletonList(expectedUnknownHandler);
}
@Override
public List<ConstantConfig> constants() {
return Collections.singletonList(constantConfig);
}
@Override
public List<BeanConfig> beans() {
return Arrays.asList(new BeanConfig(TestBean.class, "struts"), new BeanConfig(TestBean.class, "struts.static", TestBean.class, Scope.PROTOTYPE, true, true), new BeanConfig(TestBean.class, "struts.test.bean", TestBean.class));
}
@Override
public Optional<BeanSelectionConfig> beanSelection() {
return Optional.of(new BeanSelectionConfig(TestBeanSelectionProvider.class, "testBeans"));
}
};
StrutsJavaConfigurationProvider provider = new StrutsJavaConfigurationProvider(javaConfig);
Configuration configuration = new MockConfiguration();
provider.init(configuration);
ContainerBuilder builder = new ContainerBuilder();
LocatableProperties props = new LocatableProperties();
provider.register(builder, props);
// constant
Assert.assertEquals(String.valueOf(constantConfig.getDevMode()), props.get(StrutsConstants.STRUTS_DEVMODE));
// unknown-handler-stack
Assert.assertNotNull(configuration.getUnknownHandlerStack());
Assert.assertEquals(1, configuration.getUnknownHandlerStack().size());
Assert.assertEquals(expectedUnknownHandler, configuration.getUnknownHandlerStack().get(0).getName());
// bean
Container container = builder.create(true);
TestBean testBean = container.getInstance(TestBean.class);
Assert.assertNotNull(testBean);
testBean = container.getInstance(TestBean.class, "struts");
Assert.assertNotNull(testBean);
// bean selection
Set<String> names = container.getInstanceNames(TestBean.class);
Assert.assertTrue(names.contains("struts"));
Assert.assertTrue(names.contains("struts.test.bean"));
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class BeanConfigTest method testConstructor2.
@Test
public void testConstructor2() throws Exception {
Class<TestBean> expectedClass = TestBean.class;
String expectedName = "expectedBeanName";
Class<Object> expectedType = Object.class;
Scope expectedScope = Scope.PROTOTYPE;
boolean expectedOnlyStatic = true;
boolean expectedOptional = true;
BeanConfig beanConfig = new BeanConfig(expectedClass, expectedName, expectedType, expectedScope, expectedOnlyStatic, expectedOptional);
Assert.assertEquals(expectedClass, beanConfig.getClazz());
Assert.assertEquals(expectedName, beanConfig.getName());
Assert.assertEquals(expectedScope, beanConfig.getScope());
Assert.assertEquals(expectedType, beanConfig.getType());
Assert.assertEquals(expectedOnlyStatic, beanConfig.isOnlyStatic());
Assert.assertEquals(expectedOptional, beanConfig.isOptional());
}
use of com.opensymphony.xwork2.TestBean in project struts by apache.
the class ValidateAction method testModelDrivenParameters.
public void testModelDrivenParameters() throws Exception {
Map<String, Object> params = new HashMap<>();
final String fooVal = "com.opensymphony.xwork2.interceptor.ParametersInterceptorTest.foo";
params.put("foo", fooVal);
final String nameVal = "com.opensymphony.xwork2.interceptor.ParametersInterceptorTest.name";
params.put("name", nameVal);
params.put("count", "15");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.MODEL_DRIVEN_PARAM_TEST, null, extraContext);
assertEquals(Action.SUCCESS, proxy.execute());
ModelDrivenAction action = (ModelDrivenAction) proxy.getAction();
TestBean model = (TestBean) action.getModel();
assertEquals(nameVal, model.getName());
assertEquals(15, model.getCount());
assertEquals(fooVal, action.getFoo());
}
Aggregations