Package org.apache.commons.betwixt.io

Examples of org.apache.commons.betwixt.io.BeanReader


            + "<excuse>Wedding</excuse>"
            + "</party>";
       
        xmlAssertIsomorphic(parseString(xml), parseString(out) , true);
       
        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(introspector);
        reader.registerBeanClass("party", PartyBean.class);
        PartyBean readBean = (PartyBean) reader.parse(new StringReader(xml));
       
        assertEquals("FromHours incorrect property value", readBean.getFromHour(), bean.getFromHour());
        assertEquals("Excuse incorrect property value", readBean.getExcuse(), bean.getExcuse());
       
        // check address
View Full Code Here


            + "<excuse>Wedding</excuse>"
            + "</party-bean>";
       
        xmlAssertIsomorphic(parseString(xml), parseString(out) , true);
       
        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(introspector);
        reader.registerBeanClass(PartyBean.class);
        PartyBean readBean = (PartyBean) reader.parse(new StringReader(xml));
       
        assertEquals("FromHours incorrect property value", readBean.getFromHour(), bean.getFromHour());
        assertEquals("Excuse incorrect property value", readBean.getExcuse(), bean.getExcuse());
       
        // check address
View Full Code Here

            + "<excuse>Wedding</excuse>"
            + "</party>";
       
        xmlAssertIsomorphic(parseString(xml), parseString(out) , true);
       
        BeanReader reader = new BeanReader();
        reader.setBindingConfiguration(configuration);
        reader.setXMLIntrospector(introspector);
        reader.registerBeanClass("party", PartyBean.class);
        PartyBean readBean = (PartyBean) reader.parse(new StringReader(xml));
       
        assertEquals("FromHours incorrect property value", readBean.getFromHour(), bean.getFromHour());
        assertEquals("Excuse incorrect property value", readBean.getExcuse(), bean.getExcuse());
       
        // check address
View Full Code Here

//        XMLIntrospectorHelper.setLog(log);
//        log = new SimpleLog("[testReadMap:MapEntryAdder]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        MapEntryAdder.setLog(log);

        BeanReader reader = new BeanReader();

//        log = new SimpleLog("[testReadMap:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        reader.setLog(log);
//        log = new SimpleLog("[testReadMap:XMLIntrospector]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        reader.getXMLIntrospector().setLog(log);

        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass("address-book", MapBean.class);
        bean = (MapBean) reader.parse(new StringReader(xml));
       
        assertEquals("Title property is incorrect", "drinkers", bean.getTitle());
        assertEquals("Map entries", 3, bean.getAddresses().size());
       
        AddressBean address = (AddressBean) bean.getAddresses().get("Russell McManus");
View Full Code Here

    BeanWriter beanWriter = new BeanWriter(outputWriter);
    beanWriter.write(idMap);
    String xml = outputWriter.toString();
    System.out.println("Map test: " + xml);

    BeanReader beanReader = new BeanReader();
    beanReader.registerBeanClass(IdMap.class);
    IdMap result = (IdMap)beanReader.parse(new StringReader(xml));
    assertNotNull("didn't get an object back!", result);
    assertNotNull("didn't get a Map out of the IdMap!", result.getIds());
    assertEquals("Got the Map, but doesn't have an entry!", 1, result.getIds().size());
    assertNotNull("Got the Map, but doesn't have correct values!", result.getIds().get(id));
  }
View Full Code Here

        writer.write(dee);
        String xml =  "<?xml version='1.0'?><Tweedledee><name>Tweedledee</name>"
                    + "<brother><name>Tweedledum</name></brother></Tweedledee>";
        xmlAssertIsomorphic(parseString(xml), parseString(out) , true);

        BeanReader reader = new BeanReader();
       
        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass(Tweedledee.class);
        Tweedledee bean = (Tweedledee) reader.parse(new StringReader(xml));
        assertNotNull(bean.getBrother());
    }
View Full Code Here

                    + "<CHILD><NAME>Demeter</NAME></CHILD>"
                    + "<CHILD><NAME>Poseidon</NAME></CHILD>"
                    + "<CHILD><NAME>Zeus</NAME></CHILD>"
                    + "</CHILDREN></DOUBLE_LINKED_PARENT_BEAN>";
                   
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setElementNameMapper(new HyphenatedNameMapper(true, "_"));
        reader.registerBeanClass(DoubleLinkedParentBean.class);
        DoubleLinkedParentBean bean = (DoubleLinkedParentBean) reader.parse(new StringReader(xml));
       
        assertNotNull("Bean read", bean);
        assertEquals("Cronus", "Parent name", bean.getName());
        assertEquals("Number of children", 6, bean.getSize());
       
View Full Code Here

        super(testName);
    }

    public void testInvalidXML() throws IOException, IntrospectionException, SAXException
    {
        BeanReader beanReader = new BeanReader();

        beanReader.registerMultiMapping(new InputSource(new StringReader(MAPPING)));

        StringReader xmlReader = new StringReader(INVALID_XML);
        Container     database  = (Container) beanReader.parse(xmlReader);

        // either we get an exception in the parse method (would perhaps be better)
        // or the collection is empty (SubElementB cannot be added to Container)
        assertFalse(database.getElements().hasNext());
    }
View Full Code Here

        StringReader in = new StringReader(xmlOut);
       
//        SimpleLog log = new SimpleLog("[TestElementsAlt:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanReader reader = new BeanReader();
//        reader.setLog(log);

//        log = new SimpleLog("[TestElementsAlt:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        BeanCreateRule.setLog(log);
       
        reader.setXMLIntrospector(newXMLIntrospector(mapper));
        reader.registerBeanClass(Elements.class);
        Elements result = (Elements) reader.parse(in);

        assertNotNull("Element 'a' is null (" + testName + ")", result.getElement("a"));
        assertNotNull("Element 'b' is null (" + testName + ")", result.getElement("b"));
        assertNotNull("Element 'c' is null (" + testName + ")", result.getElement("c"));
    }
View Full Code Here

            "<start>2004-02-10 00:00:00.0</start>" +
            "<end/>" +
            "</EventBean>";
           
       StringReader in = new StringReader(xml);
       BeanReader reader = new BeanReader();
       reader.registerBeanClass(EventBean.class);
       EventBean bean = (EventBean) reader.parse(in);
      
       assertNotNull("Parsing should work", bean);
       assertEquals("Type property", "WARNING", bean.getType());
       assertEquals("Start property", "2004-02-10 00:00:00.0", bean.getStart().toString());
       assertNull("End property", bean.getEnd());
View Full Code Here

TOP

Related Classes of org.apache.commons.betwixt.io.BeanReader

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.