FileDocCategorySizeDatePackage
PropertyTest.javaAPI DocExample5397Mon Jul 23 13:26:10 BST 2007org.apache.struts2.components

PropertyTest

public class PropertyTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
private static voidassertPropertyOutput(java.lang.String expectedOutput, Property property)

        final StringWriter out = new StringWriter();
        assertTrue(property.start(out));
        assertEquals(expectedOutput, out.getBuffer().toString());
    
public voidtestDefaultShouldBeOutputIfBeanNotAvailable()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        final Property property = new Property(stack);
        property.setDefault("default");
        property.setValue("foo");
        assertPropertyOutput("default", property);
    
public voidtestDefaultShouldBeOutputIfPropertyIsNull()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        stack.push(new FooBar(null, "bar-value"));
        final Property property = new Property(stack);
        property.setDefault("default");
        property.setValue("foo");
        assertPropertyOutput("default", property);
    
public voidtestNormalBehaviour()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        stack.push(new FooBar("foo-value", "bar-value"));
        final Property property = new Property(stack);
        property.setDefault("default");
        property.setValue("foo");
        assertPropertyOutput("foo-value", property);
    
public voidtestTopValueShouldReturnTopOfValueStack()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        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);
    
public voidtestTypeConverterReturningNullShouldLeadToDisplayOfDefaultValue()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        Ognl.setTypeConverter(stack.getContext(), new TestDefaultConverter());

        stack.push(new FooBar("foo-value", null));
        final Property property = new Property(stack);
        property.setDefault("default");
        property.setValue("top");
        assertPropertyOutput("default", property);
    
public voidtestTypeConverterShouldBeUsed()

        final ValueStack stack = ValueStackFactory.getFactory().createValueStack();
        Ognl.setTypeConverter(stack.getContext(), new TestDefaultConverter());

        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);