use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class OgnlUtilTest method testIncudeExcludes.
public void testIncudeExcludes() {
Foo foo1 = new Foo();
Foo foo2 = new 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);
foo1.setPoints(new long[] { 1, 2, 3 });
foo1.setBirthday(cal.getTime());
foo1.setUseful(false);
foo1.setTitle("foo1 title");
foo1.setNumber(1);
foo2.setTitle("foo2 title");
foo2.setNumber(2);
Map<String, Object> context = ognlUtil.createDefaultContext(foo1);
List<String> excludes = new ArrayList<>();
excludes.add("title");
excludes.add("number");
ognlUtil.copy(foo1, foo2, context, excludes, null);
// these values should remain unchanged in foo2
assertEquals(foo2.getTitle(), "foo2 title");
assertEquals(foo2.getNumber(), 2);
// these values should be changed/copied
assertEquals(foo1.getPoints(), foo2.getPoints());
assertEquals(foo1.getBirthday(), foo2.getBirthday());
assertEquals(foo1.isUseful(), foo2.isUseful());
Bar b1 = new Bar();
Bar b2 = new Bar();
b1.setTitle("bar1 title");
b1.setSomethingElse(10);
b1.setId(1L);
b2.setTitle("");
b2.setId(2L);
context = ognlUtil.createDefaultContext(b1);
List<String> includes = new ArrayList<>();
includes.add("title");
includes.add("somethingElse");
ognlUtil.copy(b1, b2, context, null, includes);
// includes properties got copied
assertEquals(b1.getTitle(), b2.getTitle());
assertEquals(b1.getSomethingElse(), b2.getSomethingElse());
// id properties did not
assertEquals(b2.getId(), new Long(2));
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class DomHelperTest method testGetLocationObject.
public void testGetLocationObject() throws Exception {
InputSource in = new InputSource(new StringReader(xml));
in.setSystemId("foo://bar");
Document doc = DomHelper.parse(in);
NodeList nl = doc.getElementsByTagName("bar");
Location loc = DomHelper.getLocationObject((Element) nl.item(0));
assertNotNull(loc);
assertTrue("Should be line 6, was " + loc.getLineNumber(), 6 == loc.getLineNumber());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class AnnotationXWorkConverterTest method testStringToCustomTypeUsingCustomConverter.
public void testStringToCustomTypeUsingCustomConverter() {
// the converter needs to be registered as the Bar.class converter
// it won't be detected from the Foo-conversion.properties
// because the Foo-conversion.properties file is only used when converting a property of Foo
converter.registerConverter(Bar.class.getName(), new FooBarConverter());
Bar bar = (Bar) converter.convertValue(null, null, null, null, "blah:123", Bar.class);
assertNotNull("conversion failed", bar);
assertEquals(123, bar.getSomethingElse());
assertEquals("blah", bar.getTitle());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class AnnotationXWorkConverterTest method testFindConversionMappingForInterfaceAndSuperclass.
public void testFindConversionMappingForInterfaceAndSuperclass() {
ModelDrivenAnnotationAction2 action = new ModelDrivenAnnotationAction2();
ValueStack stack = ActionContext.getContext().getValueStack();
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("class is: " + o.getClass(), o instanceof Bar);
Bar b = (Bar) o;
assertEquals(value, b.getTitle() + ":" + b.getSomethingElse());
String value2 = "qwer:456";
Object o2 = converter.convertValue(ognlStackContext, action.getModel(), null, "supperBarObj", value2, Bar.class);
assertNotNull(o2);
assertTrue("class is: " + o.getClass(), o2 instanceof Bar);
Bar b2 = (Bar) o2;
assertEquals(value2, b2.getTitle() + ":" + b2.getSomethingElse());
}
use of com.opensymphony.xwork2.util.Bar in project struts by apache.
the class SimpleActionValidationTest method testParamterizedMessage.
public void testParamterizedMessage() {
HashMap<String, Object> params = new HashMap<>();
params.put("bar", "42");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> barErrors = errors.get("bar");
assertEquals(1, barErrors.size());
String errorMessage = barErrors.get(0);
assertNotNull(errorMessage);
assertEquals("bar must be between 6 and 10, current value is 42.", errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations