Package org.apache.commons.betwixt.io

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


        String output = outputWriter.toString();

        assertEquals(EXPECTED, output);
           
        BeanReader beanReader = new BeanReader();

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

        StringReader xmlReader = new StringReader(output);

        element = (Element)beanReader.parse(xmlReader);

        assertEquals("Some text",
                     element.getValue());
    }
View Full Code Here


        String xmlLocation = getTestFile("src/test/org/apache/commons/betwixt/nowrap/po_add_test.xml");

        FileInputStream in = new FileInputStream(new File(xmlLocation));

        // create a new BeanReader
        BeanReader reader = createBeanReader(POTest.class);
        po = (POTest) reader.parse(in);
        assertEquals("PO Printing No", "555008805581", po.getPrintingNumber());
        List componentTests = po.getComponenttests();
       
        assertEquals("#Component tests", 3, componentTests.size());
        Componenttest testOne = (Componenttest) componentTests.get(0);
View Full Code Here

     * Description of the Method
     */
    protected BeanReader createBeanReader(Class beanClass)
        throws Exception
    {
        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(createXMLIntrospector());
        reader.registerBeanClass(beanClass);
        return reader;
    }
View Full Code Here

     * method should test both Project objects are identical
     */
    public void testRoundTrip()
        throws Exception
    {
        BeanReader reader = createBeanReader();

        ScarabSettings ss = (ScarabSettings) reader.parse(
            new FileInputStream(getTestFile("src/test/org/apache/commons/betwixt/scarab/scarab-settings.xml")));

        // now lets output it to a buffer
        StringWriter buffer = new StringWriter();
        write(ss, buffer);
View Full Code Here

     * Description of the Method
     */
    protected BeanReader createBeanReader()
        throws Exception
    {
        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(createXMLIntrospector());
        reader.registerBeanClass(ScarabSettings.class);
        return reader;
    }
View Full Code Here

    public TestBeanReader(String testName) {
        super(testName);
    }
   
    public void testBeanWriter() throws Exception {
        BeanReader reader = new BeanReader();
        reader.registerBeanClass( getBeanClass() );

        InputStream in = getXMLInput();
        try {
            Object bean = reader.parse( in );

            testCustomer(bean);
           
            String out = writeBean( bean );
            String xml = "<?xml version='1.0'?><CustomerBean><name>James</name><time>20:30:40</time>"
View Full Code Here

        BeanWriter beanWriter = new BeanWriter(stringWriter);
        beanWriter.write(bean);
        stringWriter.flush();
        String xml = "<?xml version='1.0'?>" + stringWriter.toString();
       
        BeanReader reader = new BeanReader();
        reader.registerBeanClass( PersonBean.class );
        bean = (PersonBean) reader.parse(new StringReader(xml));
       
        assertEquals("Person age wrong", 21 , bean.getAge());
        assertEquals("Person name wrong", "Samual Smith" , bean.getName());
       
        // test now with attributes for primitives
        bean = new PersonBean(19, "John Smith");
        stringWriter = new StringWriter();
        beanWriter = new BeanWriter(stringWriter);
        beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        beanWriter.write(bean);
        stringWriter.flush();
        xml = "<?xml version='1.0'?>" + stringWriter.toString();
       
        reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.registerBeanClass( PersonBean.class );
        bean = (PersonBean) reader.parse(new StringReader(xml));
       
        assertEquals("[Attribute] Person age wrong", 19 , bean.getAge());
        assertEquals("[Attribute] Person name wrong", "John Smith" , bean.getName());
    }
View Full Code Here

//        BeanCreateRule.setLog(log);
       
//        log = new SimpleLog("[TestPersonList:XMLIntrospector]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanReader reader = new BeanReader();
//        reader.getXMLIntrospector().setLog(log);
             
//        log = new SimpleLog("[TestPersonList:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
//        reader.setLog(log);
        reader.registerBeanClass( PersonListBean.class );
       
        InputStream in = 
            new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/person-list.xml") );
        try {
       
            checkBean((PersonListBean) reader.parse( in ));
           
        }
        finally {
            in.close();
        }  
View Full Code Here

        ListOfNames listOfNames = new ListOfNames();
        listOfNames.addName( new NameBean("Martin") );
       
        String xml = "<ListOfNames><names><name name='Martin'/></names></ListOfNames>";
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(true);
       
        reader.registerBeanClass(ListOfNames.class);
        ListOfNames newListOfNames = (ListOfNames) reader.parse(new StringReader(xml));
       
        assertEquals("Wrapped collection read fails", listOfNames, newListOfNames);
    }
View Full Code Here

        ListOfNames listOfNames = new ListOfNames();
        listOfNames.addName( martinBean );
       
        String xml = "<ListOfNames><names><name name='Martin'/></names></ListOfNames>";
       
        BeanReader reader = new BeanReader();
        reader.setRules( new ExtendedBaseRules() );
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(true);
       
        TestRule ruleOne = new TestRule();
        TestRule ruleTwo = new TestRule();
       
        // add a test rule before the bean rules
        reader.addRule("!*/ListOfNames/names/name", ruleOne);
        reader.registerBeanClass(ListOfNames.class);
        // add a test rule after the bean rules
        reader.addRule("!*/ListOfNames/names/name", ruleTwo);
       
        ListOfNames newListOfNames = (ListOfNames) reader.parse(new StringReader(xml));
       
        reader.parse(new StringReader(xml));
       
        // test that the rules were called
        assertEquals("Rule one called", true , ruleOne.isCalled());
        assertEquals("Rule two called", true , ruleTwo.isCalled());
       
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.