use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class XmlConfigurationProviderResultsTest method testActions.
public void testActions() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-results.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
HashMap<String, String> parameters = new HashMap<>();
HashMap<String, ResultConfig> results = new HashMap<>();
results.put("chainDefaultTypedResult", new ResultConfig.Builder("chainDefaultTypedResult", ActionChainResult.class.getName()).build());
results.put("mockTypedResult", new ResultConfig.Builder("mockTypedResult", MockResult.class.getName()).build());
Map<String, String> resultParams = new HashMap<>();
resultParams.put("actionName", "bar.vm");
results.put("specificLocationResult", new ResultConfig.Builder("specificLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
resultParams = new HashMap<>();
resultParams.put("actionName", "foo.vm");
results.put("defaultLocationResult", new ResultConfig.Builder("defaultLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
resultParams = new HashMap<>();
resultParams.put("foo", "bar");
results.put("noDefaultLocationResult", new ResultConfig.Builder("noDefaultLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
ActionConfig expectedAction = new ActionConfig.Builder("default", "Bar", SimpleAction.class.getName()).addParams(parameters).addResultConfigs(results).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map<String, ActionConfig> actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(1, actionConfigs.size());
ActionConfig action = actionConfigs.get("Bar");
assertEquals(expectedAction, action);
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class AnnotationXWorkConverterTest method testValueStackWithTypeParameter.
public void testValueStackWithTypeParameter() {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(new Foo1());
Bar1 bar = (Bar1) stack.findValue("bar", Bar1.class);
assertNotNull(bar);
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlUtilTest method testDeepSetting.
public void testDeepSetting() {
Foo foo = new Foo();
foo.setBar(new Bar());
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
Map<String, Object> props = new HashMap<>();
props.put("bar.title", "i am barbaz");
ognlUtil.setProperties(props, foo, context);
assertEquals(foo.getBar().getTitle(), "i am barbaz");
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class SetPropertiesTest method testValueStackSetValueEmptyStringAsLong.
public void testValueStackSetValueEmptyStringAsLong() {
Bar bar = new Bar();
ValueStack vs = ActionContext.getContext().getValueStack();
vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
vs.push(bar);
vs.setValue("id", "");
assertNull(bar.getId());
assertEquals(0, bar.getFieldErrors().size());
bar.setId(null);
vs.setValue("id", new String[] { "" });
assertNull(bar.getId());
assertEquals(0, bar.getFieldErrors().size());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class SetPropertiesTest method doTestAddingAndModifyingCollectionWithObjects.
public void doTestAddingAndModifyingCollectionWithObjects(Collection barColl) {
ValueStack vs = ActionContext.getContext().getValueStack();
Foo foo = new Foo();
foo.setBarCollection(barColl);
Bar bar1 = new Bar();
bar1.setId(new Long(11));
barColl.add(bar1);
Bar bar2 = new Bar();
bar2.setId(new Long(22));
barColl.add(bar2);
foo.setAnnotatedBarCollection(barColl);
// try modifying bar1 and bar2
// check the logs here to make sure
// the Map is being created
ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
ReflectionContextState.setReportingConversionErrors(vs.getContext(), true);
vs.push(foo);
String bar1Title = "The Phantom Menace";
String bar2Title = "The Clone Wars";
vs.setValue("barCollection(22).title", bar2Title);
vs.setValue("barCollection(11).title", bar1Title);
for (Object aBarColl : barColl) {
Bar next = (Bar) aBarColl;
if (next.getId().intValue() == 22) {
assertEquals(bar2Title, next.getTitle());
} else {
assertEquals(bar1Title, next.getTitle());
}
}
Bar bar3 = new Bar();
bar3.setId(new Long(33));
barColl.add(bar3);
Bar bar4 = new Bar();
bar4.setId(new Long(44));
barColl.add(bar4);
String bar1TitleByAnnotation = "The Phantom Menace By Annotation";
String bar2TitleByAnnotation = "The Clone Wars By Annotation";
vs.setValue("annotatedBarCollection(44).title", bar2TitleByAnnotation);
vs.setValue("annotatedBarCollection(33).title", bar1TitleByAnnotation);
for (Object aBarColl : barColl) {
Bar next = (Bar) aBarColl;
if (next.getId().intValue() == 44) {
assertEquals(bar2TitleByAnnotation, next.getTitle());
} else if (next.getId().intValue() == 33) {
assertEquals(bar1TitleByAnnotation, next.getTitle());
}
}
// now test adding to a collection
String bar3Title = "Revenge of the Sith";
String bar4Title = "A New Hope";
vs.setValue("barCollection.makeNew[4].title", bar4Title, true);
vs.setValue("barCollection.makeNew[0].title", bar3Title, true);
assertEquals(6, barColl.size());
for (Object aBarColl : barColl) {
Bar next = (Bar) aBarColl;
if (next.getId() == null) {
assertNotNull(next.getTitle());
assertTrue(next.getTitle().equals(bar4Title) || next.getTitle().equals(bar3Title));
}
}
// now test adding to a collection by annotation
String bar3TitleByAnnotation = "Revenge of the Sith By Annotation";
String bar4TitleByAnnotation = "A New Hope By Annotation";
vs.setValue("annotatedBarCollection.makeNew[5].title", bar4TitleByAnnotation, true);
vs.setValue("annotatedBarCollection.makeNew[1].title", bar3TitleByAnnotation, true);
assertEquals(8, barColl.size());
for (Object aBarColl : barColl) {
Bar next = (Bar) aBarColl;
if (next.getId() == null) {
assertNotNull(next.getTitle());
assertTrue(next.getTitle().equals(bar4TitleByAnnotation) || next.getTitle().equals(bar3TitleByAnnotation) || next.getTitle().equals(bar4Title) || next.getTitle().equals(bar3Title));
}
}
}
Aggregations