use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class SetPropertiesTest method testAddingToCollectionBasedOnPermission.
public void testAddingToCollectionBasedOnPermission() {
final MockObjectTypeDeterminer determiner = new MockObjectTypeDeterminer(Long.class, Bar.class, "id", true);
loadConfigurationProviders(new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ObjectTypeDeterminer.class, new Factory() {
public Object create(Context context) throws Exception {
return determiner;
}
@Override
public Class type() {
return determiner.getClass();
}
}, Scope.SINGLETON);
}
});
Collection barColl = new HashSet();
ValueStack vs = ActionContext.getContext().getValueStack();
ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
ReflectionContextState.setReportingConversionErrors(vs.getContext(), true);
Foo foo = new Foo();
foo.setBarCollection(barColl);
vs.push(foo);
String bar1Title = "title";
vs.setValue("barCollection(11).title", bar1Title);
assertEquals(1, barColl.size());
Object bar = barColl.iterator().next();
assertTrue(bar instanceof Bar);
assertEquals(((Bar) bar).getTitle(), bar1Title);
assertEquals(((Bar) bar).getId(), new Long(11));
// now test where there is no permission
determiner.setShouldCreateIfNew(false);
String bar2Title = "another title";
vs.setValue("barCollection(22).title", bar1Title);
assertEquals(1, barColl.size());
bar = barColl.iterator().next();
assertTrue(bar instanceof Bar);
assertEquals(((Bar) bar).getTitle(), bar1Title);
assertEquals(((Bar) bar).getId(), new Long(11));
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlUtilTest method testCopyUnevenObjects.
public void testCopyUnevenObjects() {
Foo foo = new Foo();
Bar bar = new Bar();
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 12);
cal.set(Calendar.YEAR, 1982);
foo.setTitle("blah");
foo.setNumber(1);
foo.setPoints(new long[] { 1, 2, 3 });
foo.setBirthday(cal.getTime());
foo.setUseful(false);
ognlUtil.copy(foo, bar, context);
assertEquals(foo.getTitle(), bar.getTitle());
assertEquals(0, bar.getSomethingElse());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class ListAction method testFindConversionMappingForInterface.
public void testFindConversionMappingForInterface() {
ModelDrivenAction2 action = new ModelDrivenAction2();
stack.push(action);
stack.push(action.getModel());
Map<String, Object> ognlStackContext = stack.getContext();
ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
String value = "asdf:123";
Object o = converter.convertValue(ognlStackContext, action.getModel(), null, "barObj", value, Bar.class);
assertNotNull(o);
assertTrue(o instanceof Bar);
Bar b = (Bar) o;
assertEquals(value, b.getTitle() + ":" + b.getSomethingElse());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class XmlConfigurationProviderActionsTest method testPackageDefaultClassRef.
public void testPackageDefaultClassRef() throws Exception {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions-packagedefaultclassref.xml";
final String testDefaultClassName = "com.opensymphony.xwork2.UserSpecifiedDefaultAction";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// setup expectations
params.put("foo", "17");
params.put("bar", "23");
ActionConfig barWithPackageDefaultClassRefConfig = new ActionConfig.Builder("", "Bar", "").addParams(params).build();
// execute the configuration
provider.init(configuration);
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(1, actionConfigs.size());
assertEquals(barWithPackageDefaultClassRefConfig, actionConfigs.get("Bar"));
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class XmlConfigurationProviderAllowedMethodsTest method testDefaultAllowedMethods.
public void testDefaultAllowedMethods() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-allowed-methods.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(5, actionConfigs.size());
ActionConfig action = (ActionConfig) actionConfigs.get("Default");
assertEquals(1, action.getAllowedMethods().size());
assertTrue(action.isAllowedMethod("execute"));
assertTrue(action.isAllowedMethod("input"));
assertTrue(action.isAllowedMethod("cancel"));
assertTrue(action.isAllowedMethod("foo"));
assertTrue(action.isAllowedMethod("bar"));
assertTrue(action.isAllowedMethod("baz"));
assertTrue(action.isAllowedMethod("xyz"));
action = (ActionConfig) actionConfigs.get("Boring");
assertEquals(2, action.getAllowedMethods().size());
assertTrue(action.isAllowedMethod("execute"));
assertTrue(action.isAllowedMethod("input"));
assertTrue(action.isAllowedMethod("cancel"));
assertFalse(action.isAllowedMethod("foo"));
assertFalse(action.isAllowedMethod("bar"));
assertFalse(action.isAllowedMethod("baz"));
assertFalse(action.isAllowedMethod("xyz"));
action = (ActionConfig) actionConfigs.get("Foo");
assertEquals(3, action.getAllowedMethods().size());
assertTrue(action.isAllowedMethod("execute"));
assertTrue(action.isAllowedMethod("input"));
assertTrue(action.isAllowedMethod("cancel"));
assertTrue(action.isAllowedMethod("foo"));
assertFalse(action.isAllowedMethod("bar"));
assertFalse(action.isAllowedMethod("baz"));
assertFalse(action.isAllowedMethod("xyz"));
action = (ActionConfig) actionConfigs.get("Bar");
assertEquals(4, action.getAllowedMethods().size());
assertTrue(action.isAllowedMethod("execute"));
assertTrue(action.isAllowedMethod("input"));
assertTrue(action.isAllowedMethod("cancel"));
assertTrue(action.isAllowedMethod("foo"));
assertTrue(action.isAllowedMethod("bar"));
assertFalse(action.isAllowedMethod("baz"));
assertFalse(action.isAllowedMethod("xyz"));
action = (ActionConfig) actionConfigs.get("Baz");
assertEquals(5, action.getAllowedMethods().size());
assertFalse(action.isAllowedMethod("execute"));
assertTrue(action.isAllowedMethod("input"));
assertTrue(action.isAllowedMethod("cancel"));
assertTrue(action.isAllowedMethod("foo"));
assertTrue(action.isAllowedMethod("bar"));
assertTrue(action.isAllowedMethod("baz"));
assertFalse(action.isAllowedMethod("xyz"));
}
Aggregations