public void parseConfiguration(final InputStream input) throws Exception { Reader reader = new InputStreamReader(input); String xml = XMLUtil.readerToString(reader); xml = XMLUtil.replaceSystemProps(xml); Element e = XMLUtil.stringToElement(xml); // only parse elements from <jms> NodeList children = e.getElementsByTagName(CONFIGURATION_SCHEMA_ROOT_ELEMENT); if (children.getLength() > 0) { parseConfiguration(children.item(0)); } }
public Configuration parseMainConfig(final InputStream input) throws Exception { Reader reader = new InputStreamReader(input); String xml = XMLUtil.readerToString(reader); xml = XMLUtil.replaceSystemProps(xml); Element e = XMLUtil.stringToElement(xml); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(XMLUtil.findResource("schema/artemis-server.xsd")); Validator validator = schema.newValidator(); try { validator.validate(new DOMSource(e)); } catch (Exception ex) { ActiveMQServerLogger.LOGGER.error(ex.getMessage()); } Configuration config = new ConfigurationImpl(); parseMainConfig(e, config); return config; }
@Test public void testEquivalent_4() throws Exception { String s = "<a attr1=\"val1\" attr2=\"val2\"/>"; String s2 = "<a attr2=\"val2\" attr1=\"val1\"/>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testEquivalent_2() throws Exception { String s = "<a></a>"; String s2 = "<a/>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testEquivalent_1() throws Exception { String s = "<a/>"; String s2 = "<a/>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testEquivalent_5() throws Exception { String s = "<a><b/></a>"; String s2 = "<a><b/></a>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testEquivalent_6() throws Exception { String s = "<enclosing><a attr1=\"val1\" attr2=\"val2\"/></enclosing>"; String s2 = "<enclosing><a attr2=\"val2\" attr1=\"val1\"/></enclosing>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testEquivalent_8() throws Exception { String s = "<a><!-- some comment --><b/><!--some other comment --><c/><!-- blah --></a>"; String s2 = "<a><b/><!--blah blah--><c/></a>"; XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); }
@Test public void testElementToString_4() throws Exception { String s = "<a><![CDATA[somedata]]></a>"; Element e = XMLUtil.stringToElement(s); String tostring = XMLUtil.elementToString(e); Element convertedAgain = XMLUtil.stringToElement(tostring); XMLUtil.assertEquivalent(e, convertedAgain); }
@Test public void testGetTextContext_3() throws Exception { String document = "<blah someattribute=\"somevalue\"><a/></blah>"; Element e = XMLUtil.stringToElement(document); String s = XMLUtil.getTextContent(e); Element subelement = XMLUtil.stringToElement(s); Assert.assertEquals("a", subelement.getNodeName()); }
@Test public void testGetTextContext_4() throws Exception { String document = "<blah someattribute=\"somevalue\"><a></a></blah>"; Element e = XMLUtil.stringToElement(document); String s = XMLUtil.getTextContent(e); Element subelement = XMLUtil.stringToElement(s); Assert.assertEquals("a", subelement.getNodeName()); }
@Test public void testElementToString_2() throws Exception { String s = "<a b=\"something\"></a>"; Element e = XMLUtil.stringToElement(s); String tostring = XMLUtil.elementToString(e); Element convertedAgain = XMLUtil.stringToElement(tostring); XMLUtil.assertEquivalent(e, convertedAgain); }
@Test public void testElementToString_1() throws Exception { String s = "<a b=\"something\">somethingelse</a>"; Element e = XMLUtil.stringToElement(s); String tostring = XMLUtil.elementToString(e); Element convertedAgain = XMLUtil.stringToElement(tostring); XMLUtil.assertEquivalent(e, convertedAgain); }
@Test public void testEquivalent_7() throws Exception { String s = "<a><b/><c/></a>"; String s2 = "<a><c/><b/></a>"; try { XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); Assert.fail("this should throw exception"); } catch (IllegalArgumentException e) { // OK e.printStackTrace(); } }
@Test public void testEquivalent_3() throws Exception { String s = "<a attr1=\"val1\" attr2=\"val2\"/>"; String s2 = "<a attr2=\"val2\"/>"; try { XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2)); Assert.fail("this should throw exception"); } catch (IllegalArgumentException e) { // expected } }
@Test public void testElementToString_3() throws Exception { String s = "<a b=\"something\"/>"; Element e = XMLUtil.stringToElement(s); String tostring = XMLUtil.elementToString(e); Element convertedAgain = XMLUtil.stringToElement(tostring); XMLUtil.assertEquivalent(e, convertedAgain); }
@Test public void testGetTextContext_5() throws Exception { String document = "<blah someattribute=\"somevalue\"><a><b/></a></blah>"; Element e = XMLUtil.stringToElement(document); String s = XMLUtil.getTextContent(e); Element subelement = XMLUtil.stringToElement(s); Assert.assertEquals("a", subelement.getNodeName()); NodeList nl = subelement.getChildNodes(); // try to find <b> boolean found = false; for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if ("b".equals(n.getNodeName())) { found = true; } } Assert.assertTrue(found); }
/** * test does not pass in eclipse (because it can not find artemis-configuration.xsd). * It runs fine on the CLI with the proper env setting. */ @Test public void testMinimalConfiguration() throws Exception { String xml = "<core xmlns='urn:activemq:core'>" + "</core>"; Element element = XMLUtil.stringToElement(xml); Assert.assertNotNull(element); XMLUtil.validate(element, "schema/artemis-configuration.xsd"); }
@Test public void testGetTextContext_2() throws Exception { String document = "<blah someattribute=\"somevalue\">foo</blah>"; Element e = XMLUtil.stringToElement(document); Assert.assertEquals("foo", XMLUtil.getTextContent(e)); }
@Test public void testGetTextContext_1() throws Exception { String document = "<blah>foo</blah>"; Element e = XMLUtil.stringToElement(document); Assert.assertEquals("foo", XMLUtil.getTextContent(e)); }