Examples of BeanReader


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

                    + "</strings></SimpleStringCollective>";
               
        //SimpleLog log = new SimpleLog("[test]");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       // BeanRuleSet.setLog(log);
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(SimpleStringCollective.class);
        SimpleStringCollective collective = (SimpleStringCollective) reader.parse(new StringReader(xml));
       
        assertFalse("SimpleStringCollective mapped", collective == null);
        List strings = collective.getStrings();
        assertEquals("String count", 3, strings.size());
        assertEquals("First string", "one", strings.get(0));
View Full Code Here

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

   
    public void testCollection() throws Exception {
        String xml = "<?xml version='1.0'?>"
                + "<elements><element><value>alpha</value></element></elements>";
        StringReader in = new StringReader(xml);
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(Elements.class);
        Elements result = (Elements) reader.parse(in);
        assertNotNull("Element alpha exists", result.getElement("alpha"));
    }
View Full Code Here

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

        container = (Container)beanReader.parse(xmlReader);

        Iterator it = container.getElements();

        assertTrue(it.next() instanceof ElementB);
        assertTrue(it.next() instanceof ElementA);
View Full Code Here

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

        assertFalse(it.hasNext());
    }

    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    container = (Container)beanReader.parse(xmlReader);

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

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

        StringWriter buffer = new StringWriter();
        write( bean, buffer );
       

        // create a BeanReader
        BeanReader reader = new BeanReader();
        reader.registerBeanClass( Channel.class );

        // Register local copies of the DTDs we understand
        for (int i = 0; i < registrations.length; i += 2) {
            URL url = RSSDigester.class.getResource(registrations[i + 1]);
            if (url != null) {
                reader.register(registrations[i], url.toString());
            }
        }
       
        // now lets try parse the output sing the BeanReader
        String text = buffer.toString();       
        bean = reader.parse( new StringReader( text ) );
       
        // managed to parse it again!
       
        // now lets write it to another buffer
        buffer = new StringWriter();
View Full Code Here

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

            "   <timestamp>1999-12-31 00:00:00.0</timestamp>" +
            "</AlertBean>";
        StringReader validIn = new StringReader(xmlWithValidDate);
     
       
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(AlertBean.class);
        try
        {
            AlertBean alterBean = (AlertBean) reader.parse(invalidIn);
            fail("Invalid date so expected exception");
        }
        catch (Exception e)
        {
            // expected
        }
       
        AlertBean alterBean = (AlertBean) reader.parse(validIn);
    }
View Full Code Here

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

    // This test runs in Eclipse but not in maven :/
    public void _testReadPrivateStaticClasses() throws Exception {
       
        StringReader in= new StringReader("<?xml version='1.0'?>" +
                "<ale><name>Timothy Taylor</name></ale>");
        BeanReader reader = new BeanReader();
        reader.registerBeanClass("ale", Nested.class);
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        Object out = reader.parse(in);
        assertNotNull("Expected bean to be output", out);
        assertEquals("Expected bean to be of type Nested", "org.apache.commons.betwixt.io.read.TestReadData$Nested", out.getClass().getName());
        Nested bean = (Nested) out;
        assertEquals("Expected name to be set", "Timothy Taylor", bean.getName());
    }
View Full Code Here

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

            "<key>Aethelred</key>" +
            "<value>The Unready</value>" +
            "</entry>" +
            "</BeanWithConcreteMap>");

        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass(BeanWithConcreteMap.class);
       
       
        BeanWithConcreteMap bean = (BeanWithConcreteMap) reader.parse(in);
        assertNotNull("Parse failed", bean);
       
        Map map = bean.getSomeThingies();
       
        Set keyset = map.keySet();
View Full Code Here

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

                + "      </entry>\n"
                + "    </addressBookItems>\n"
                + "  </AddressBook>\n";
   
        xmlAssertIsomorphicContent(parseString(xml), parseString(outputWriter.toString()), true);
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(AddressBook.class);
        StringReader xmlReader = new StringReader(outputWriter.toString());
        AddressBook result = (AddressBook) reader.parse(xmlReader);
        assertNotNull("Expected to get an AddressBook!", result);
        assertNotNull(
            "Expected AddressBook to have some address entryitems!",
            result.getAddressBookItems());
        AddressBean[] resultAddresses =
View Full Code Here

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

        "          </entry>" +
        "        </mapped>" +
        "        </alpha>";
       
        StringReader in = new StringReader(xml);
        BeanReader reader = new BeanReader();
        reader.getBindingConfiguration().setMapIDs(false);
        reader.getBindingConfiguration().setObjectStringConverter(new PrependingConverter());
        reader.registerBeanClass(AlphaBean.class);
        AlphaBean bean = (AlphaBean) reader.parse(in);
        assertNotNull(bean);
        assertEquals("SIX", bean.getName());
        BetaBean betaBean = bean.getBetaBean();
        assertNotNull(betaBean);
        assertEquals("ONE", betaBean.getName());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.