Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.TestBean


            new Integer(3),
            "/map[@name='TestKey4'][1]/int");
    }

    public void testRemovePath() {
        TestBean bean = (TestBean) context.getContextBean();
        bean.getMap().put("TestKey1", "test");

        // Remove dynamic property
        context.removePath("map[@name = 'TestKey1']");
        assertEquals(
            "Remove dynamic property value",
View Full Code Here


            null,
            context.getValue("map[@name = 'TestKey1']"));
    }

    public void testRemovePathArrayElement() {
        TestBean bean = (TestBean) context.getContextBean();

        bean.getMap().put("TestKey2", new String[] { "temp1", "temp2" });
        context.removePath("map[@name = 'TestKey2'][1]");
        assertEquals(
            "Remove dynamic property collection element",
            "temp2",
            context.getValue("map[@name = 'TestKey2'][1]"));
View Full Code Here

            "temp2",
            context.getValue("map[@name = 'TestKey2'][1]"));
    }
   
    public void testCollectionOfMaps() {
        TestBean bean = (TestBean) context.getContextBean();
        List list = new ArrayList();

        bean.getMap().put("stuff", list);       

        Map m = new HashMap();
        m.put("fruit", "apple");
        list.add(m);
View Full Code Here

            "/map/stuff[@name='fruit']",
            list("apple", "banana"));       
    }

    public void testMapOfMaps() {
        TestBean bean = (TestBean) context.getContextBean();

        Map fruit = new HashMap();
        fruit.put("apple", "green");
        fruit.put("orange", "red");
       
        Map meat = new HashMap();
        meat.put("pork", "pig");
        meat.put("beef", "cow");
       
        bean.getMap().put("fruit", fruit);       
        bean.getMap().put("meat", meat);       
               
        assertXPathPointer(
            context,
            "//beef",
            "/map[@name='meat'][@name='beef']");
View Full Code Here

*/

public class DynaBeanModelTest extends BeanModelTestCase {

    protected Object createContextBean() {
        return new WrapDynaBean(new TestBean());
    }
View Full Code Here

            }
            ((Map) parent).put(name, v);
            return true;
        }
        else if (name.equals("TestKey4")) {
            ((Map) parent).put(name, new Object[] { new TestBean()});
            return true;
        }
        return false;
    }
View Full Code Here

        Object parent,
        String name,
        int index)
    {
        if (name.equals("testArray")) {
            ((TestBean[]) parent)[index] = new TestBean();
            return true;
        }
        else if (name.equals("stringArray")) {
            ((String[]) parent)[index] = "";
            return true;
View Full Code Here

    /**
     * Create a new object and set it on the specified variable
     */
    public boolean declareVariable(JXPathContext context, String name) {
        if (name.equals("test")) {
            context.getVariables().declareVariable(name, new TestBean());
            return true;
        }
        else if (name.equals("testArray")) {
            context.getVariables().declareVariable(name, new TestBean[0]);
            return true;
View Full Code Here

    private TestBean testBean;
    private TypeConverter typeConverter;

    public void setUp() {
        if (context == null) {
            testBean = new TestBean();
            context = JXPathContext.newContext(testBean);
            Variables vars = context.getVariables();
            vars.declareVariable("test", new TestFunctions(4, "test"));

            FunctionLibrary lib = new FunctionLibrary();
View Full Code Here

    public void testRootAsCollection() {
        assertXPathValue(context, ".[1]/string", "string");
    }

    public void testCreatePath() {
        context = JXPathContext.newContext(new TestBean());
        context.setFactory(new TestMixedModelFactory());

        TestBean bean = (TestBean) context.getContextBean();
        bean.setMap(null);

        assertXPathCreatePath(
            context,
            "/map[@name='TestKey5']/nestedBean/int",
            new Integer(1),
            "/map[@name='TestKey5']/nestedBean/int");

        bean.setMap(null);
        assertXPathCreatePath(
            context,
            "/map[@name='TestKey5']/beans[2]/int",
            new Integer(1),
            "/map[@name='TestKey5']/beans[2]/int");
View Full Code Here

TOP

Related Classes of org.apache.commons.jxpath.TestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.