XmlBean { public void configure(String xml, Object obj) throws XmlBeanException, IOException, SAXException { configure(xml, obj, null); } XmlBean(); void setRootTag(String value); void setAccessPrivateProperties(boolean value); void configure(String xml, Object obj); void configure(String xml, Object obj, String xpath); void configure(InputStream in, Object obj); void configure(InputStream in, Object obj, String xpath); void configure(File file, Object obj); void configure(File file, Object obj, String xpath); void configure(XmlParser.Node rootNode, Object obj, String xpath); void configure(XmlParser.Node rootNode, Object obj); CollectionHelper createCollectionHelper(XmlParser.Node node, Object obj, Object value, String propertyName, BeanProperty property, String valueAttrString, String keyAttrString);  }
@Test public void configureSimpleProperties() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<configuration>\n") .append(" <port>80</port>\n") .append(" <host>www.google.com</host>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); Assert.assertNull(config.size); Assert.assertEquals(80, config.port); Assert.assertEquals("www.google.com", config.host); Assert.assertEquals("http: }
@Test(expected=PropertyNotFoundException.class) public void configureThrowPropertyNotFoundException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <port2>80</port2>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test(expected=PropertyPermissionException.class) public void configureThrowPropertyPermissionException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <size>80</size>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test(expected=PropertyIsEmptyException.class) public void configureThrowPropertyIsEmptyException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <port></port>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test(expected=PropertyConversionException.class) public void configureThrowPropertyConversionException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <port>joe</port>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test(expected=PropertyInvocationException.class) public void configureThrowPropertyInvocationException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <port>-1</port>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test public void configureComplex() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <port>80</port>\n") .append(" <host>www.google.com</host>\n") .append(" </server>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); Assert.assertNull(config.getServer()); Assert.assertNull(config.url); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); Assert.assertNotNull(config.getServer()); Assert.assertEquals("http: Assert.assertEquals(80, config.getServer().port); Assert.assertEquals("www.google.com", config.getServer().host); }
@Test public void configureComplexWithProvidedInstance() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <host>www.google.com</host>\n") .append(" </server>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); Server server = new Server(); server.setPort(80); config.setServer(server); config.setUrl("http: XmlBean bean = new XmlBean(); bean.configure(rootNode, config); Assert.assertSame(server, config.getServer()); Assert.assertEquals("http: Assert.assertEquals(80, config.getServer().port); Assert.assertEquals("www.google.com", config.getServer().host); }
@Test public void configureComplexNoChildProperties() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server />\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); Assert.assertNull(config.getServer()); Assert.assertNull(config.url); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); Assert.assertNotNull(config.getServer()); Assert.assertEquals("http: Assert.assertEquals(0, config.getServer().port); Assert.assertEquals(null, config.getServer().host); }
@Test(expected=PropertyNotFoundException.class) public void configureComplexWithPropertyNotFoundException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <port2>80</port2>\n") .append(" </server>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test public void configureComplexWithPropertyNotFoundExceptionEnsureOnlyOnePropertyChanged() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <url>http: .append(" <server>\n") .append(" <host>www2.google.com</host>\n") .append(" <port2>80</port2>\n") .append(" </server>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); Server server = new Server(); config.setServer(server); server.setHost("www.google.com"); server.setPort(443); XmlBean bean = new XmlBean(); try { bean.configure(rootNode, config); Assert.fail("Configure should have failed"); } catch (XmlBeanException e) { } Assert.assertSame(server, config.getServer()); Assert.assertEquals("http: Assert.assertEquals(443, config.getServer().port); Assert.assertEquals("www2.google.com", config.getServer().host); }
@Test public void configureComplexWithPropertyNotFoundExceptionEnsureNoPropertiesChanged() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <url>http: .append(" <server>\n") .append(" <host>www2.google.com</host>\n") .append(" <port2>80</port2>\n") .append(" </server>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); XmlBean bean = new XmlBean(); try { bean.configure(rootNode, config); Assert.fail("Configure should have failed"); } catch (XmlBeanException e) { } Assert.assertNull(config.getServer()); Assert.assertEquals("http: }
@Test(expected=PropertyNoAttributesExpectedException.class) public void configureNoAttributesExpectedInRootNode() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration id=\"stratus\">\n") .append(" <port>80</port>\n") .append(" <host>www.google.com</host>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test(expected=PropertyNoAttributesExpectedException.class) public void configureNoAttributesExpectedInProperty() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <port>80</port>\n") .append(" <host id=\"1\">www.google.com</host>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); SimpleConfiguration config = new SimpleConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }
@Test public void configureComplexTwice() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <port>80</port>\n") .append(" <host>www.google.com</host>\n") .append(" </server>\n") .append(" <url>http: .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); Assert.assertNotNull(config.getServer()); Assert.assertEquals("http: Assert.assertEquals(80, config.getServer().port); Assert.assertEquals("www.google.com", config.getServer().host); StringBuilder string1 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <port>8080</port>\n") .append(" </server>\n") .append(" <url>http: .append("</configuration>"); is = new ByteArrayInputStream(string1.toString().getBytes()); rootNode = parser.parse(is); bean.configure(rootNode, config); Assert.assertNotNull(config.getServer()); Assert.assertEquals("http: Assert.assertEquals(8080, config.getServer().port); Assert.assertEquals("www.google.com", config.getServer().host); }
@Test(expected=PropertyAlreadySetException.class) public void configureSamePropertyTwiceCausesException() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<configuration>\n") .append(" <server>\n") .append(" <port>80</port>\n") .append(" <port>8080</port>\n") .append(" </server>\n") .append("</configuration>") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); XmlParser parser = new XmlParser(); XmlParser.Node rootNode = parser.parse(is); ComplexConfiguration config = new ComplexConfiguration(); XmlBean bean = new XmlBean(); bean.configure(rootNode, config); }