Search in sources :

Example 21 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class OgnlUtilTest method testSetPropertiesLongArray.

public void testSetPropertiesLongArray() {
    Foo foo = new Foo();
    Map<String, Object> context = ognlUtil.createDefaultContext(foo);
    Map<String, Object> props = new HashMap<>();
    props.put("points", new String[] { "1", "2" });
    ognlUtil.setProperties(props, foo, context);
    assertNotNull(foo.getPoints());
    assertEquals(2, foo.getPoints().length);
    assertEquals(1, foo.getPoints()[0]);
    assertEquals(2, foo.getPoints()[1]);
}
Also used : HashMap(java.util.HashMap) Foo(com.opensymphony.xwork2.util.Foo)

Example 22 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class OgnlUtilTest method testAccessContext.

public void testAccessContext() throws Exception {
    Map<String, Object> context = ognlUtil.createDefaultContext(null);
    Foo foo = new Foo();
    Object result = ognlUtil.getValue("#context", context, null);
    Object root = ognlUtil.getValue("#root", context, foo);
    Object that = ognlUtil.getValue("#this", context, foo);
    assertNotSame(context, result);
    assertNull(result);
    assertNotNull(root);
    assertSame(root.getClass(), Foo.class);
    assertNotNull(that);
    assertSame(that.getClass(), Foo.class);
    assertSame(that, root);
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 23 with Foo

use of com.opensymphony.xwork2.util.Foo 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));
}
Also used : Bar(com.opensymphony.xwork2.util.Bar) Foo(com.opensymphony.xwork2.util.Foo) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList)

Example 24 with Foo

use of com.opensymphony.xwork2.util.Foo 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());
}
Also used : InputSource(org.xml.sax.InputSource) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Location(com.opensymphony.xwork2.util.location.Location)

Example 25 with Foo

use of com.opensymphony.xwork2.util.Foo in project struts by apache.

the class AnnotationXWorkConverterTest method testFindConversionErrorMessage.

public void testFindConversionErrorMessage() {
    ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction();
    container.inject(action);
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(action);
    stack.push(action.getModel());
    String message = XWorkConverter.getConversionErrorMessage("birth", Integer.class, stack);
    assertNotNull(message);
    assertEquals("Invalid date for birth.", message);
    message = XWorkConverter.getConversionErrorMessage("foo", Integer.class, stack);
    assertNotNull(message);
    assertEquals("Invalid field value for field \"foo\".", message);
}
Also used : BigInteger(java.math.BigInteger) ValueStack(com.opensymphony.xwork2.util.ValueStack)

Aggregations

Foo (com.opensymphony.xwork2.util.Foo)53 HashMap (java.util.HashMap)32 ValueStack (com.opensymphony.xwork2.util.ValueStack)23 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)20 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)19 StrutsException (org.apache.struts2.StrutsException)19 OgnlException (ognl.OgnlException)18 IntrospectionException (java.beans.IntrospectionException)17 InappropriateExpressionException (ognl.InappropriateExpressionException)17 MethodFailedException (ognl.MethodFailedException)17 NoSuchPropertyException (ognl.NoSuchPropertyException)17 ActionProxy (com.opensymphony.xwork2.ActionProxy)16 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)8 Bar (com.opensymphony.xwork2.util.Bar)8 Map (java.util.Map)8 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)7 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)7 StubValueStack (com.opensymphony.xwork2.StubValueStack)6