Search in sources :

Example 61 with Foo

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

the class SetPropertiesTest method doTestAddingToMapsWithObjects.

public void doTestAddingToMapsWithObjects(boolean allowAdditions) throws Exception {
    loadButAdd(ObjectTypeDeterminer.class, new MockObjectTypeDeterminer(Long.class, Cat.class, null, allowAdditions));
    Foo foo = new Foo();
    foo.setAnotherCatMap(new HashMap());
    String spielname = "Spielen";
    ValueStack vs = ActionContext.getContext().getValueStack();
    vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    vs.getContext().put(ReflectionContextState.CREATE_NULL_OBJECTS, Boolean.TRUE);
    vs.push(foo);
    vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    vs.setValue("anotherCatMap[\"3\"].name", spielname);
    Object setCat = foo.getAnotherCatMap().get(new Long(3));
    if (allowAdditions) {
        assertNotNull(setCat);
        assertTrue(setCat instanceof Cat);
        assertTrue(((Cat) setCat).getName().equals(spielname));
    } else {
        assertNull(setCat);
    }
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) Cat(com.opensymphony.xwork2.util.Cat) Foo(com.opensymphony.xwork2.util.Foo) MockObjectTypeDeterminer(com.opensymphony.xwork2.mock.MockObjectTypeDeterminer)

Example 62 with Foo

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

the class SetPropertiesTest method testSetCollectionByConverterFromArray.

public void testSetCollectionByConverterFromArray() {
    Foo foo = new Foo();
    ValueStack vs = ActionContext.getContext().getValueStack();
    vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    XWorkConverter c = (XWorkConverter) ((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget();
    c.registerConverter(Cat.class.getName(), new FooBarConverter());
    vs.push(foo);
    vs.setValue("cats", new String[] { "1", "2" });
    assertNotNull(foo.getCats());
    assertEquals(2, foo.getCats().size());
    assertEquals(Cat.class, foo.getCats().get(0).getClass());
    assertEquals(Cat.class, foo.getCats().get(1).getClass());
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) Foo(com.opensymphony.xwork2.util.Foo) Cat(com.opensymphony.xwork2.util.Cat) FooBarConverter(com.opensymphony.xwork2.conversion.impl.FooBarConverter) XWorkConverter(com.opensymphony.xwork2.conversion.impl.XWorkConverter)

Example 63 with Foo

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

the class SetPropertiesTest method testSetCollectionByConverterFromCollection.

public void testSetCollectionByConverterFromCollection() {
    Foo foo = new Foo();
    ValueStack vs = ActionContext.getContext().getValueStack();
    vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    XWorkConverter c = (XWorkConverter) ((OgnlTypeConverterWrapper) Ognl.getTypeConverter(vs.getContext())).getTarget();
    c.registerConverter(Cat.class.getName(), new FooBarConverter());
    vs.push(foo);
    HashSet s = new HashSet();
    s.add("1");
    s.add("2");
    vs.setValue("cats", s);
    assertNotNull(foo.getCats());
    assertEquals(2, foo.getCats().size());
    assertEquals(Cat.class, foo.getCats().get(0).getClass());
    assertEquals(Cat.class, foo.getCats().get(1).getClass());
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) Foo(com.opensymphony.xwork2.util.Foo) Cat(com.opensymphony.xwork2.util.Cat) FooBarConverter(com.opensymphony.xwork2.conversion.impl.FooBarConverter) XWorkConverter(com.opensymphony.xwork2.conversion.impl.XWorkConverter)

Example 64 with Foo

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

the class PropertyTest method testTopValueShouldReturnTopOfValueStack.

public void testTopValueShouldReturnTopOfValueStack() {
    final ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(new FooBar("foo-value", "bar-value"));
    final Property property = new Property(stack);
    property.setDefault("default");
    property.setValue("top");
    assertPropertyOutput("foo-value/bar-value", property);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 65 with Foo

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

the class PropertyTest method testTypeConverterShouldBeUsed.

public void testTypeConverterShouldBeUsed() {
    final ValueStack stack = ActionContext.getContext().getValueStack();
    converter.registerConverter("org.apache.struts2.components.PropertyTest$FooBar", new FooBarConverter());
    stack.push(new FooBar("foo-value", "bar-value"));
    final Property property = new Property(stack);
    property.setDefault("default");
    property.setValue("top");
    assertPropertyOutput("*foo-value + bar-value*", property);
}
Also used : 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