Search in sources :

Example 1 with IdXmlLoader

use of io.servicecomb.foundation.common.config.impl.IdXmlLoader in project java-chassis by ServiceComb.

the class TestConfig method testIdXml.

@Test
public void testIdXml() throws Exception {
    List<String> locationPatternList = new ArrayList<>();
    locationPatternList.add("classpath*:config/config.test.inc.xml");
    ConfigLoader loader = new IdXmlLoader(locationPatternList, ".inc.xml");
    Document doc = loader.load();
    Element root = doc.getDocumentElement();
    Assert.assertEquals("configs", root.getNodeName());
    NodeList propList = root.getElementsByTagName("properties");
    Assert.assertEquals(1, propList.getLength());
    Element prop = (Element) propList.item(0);
    Assert.assertEquals("pTest", prop.getAttributes().getNamedItem("id").getNodeValue());
    NodeList pathListProp = prop.getElementsByTagName("path");
    Assert.assertEquals(TEST_PROP_LIST_SIZE, pathListProp.getLength());
    Assert.assertEquals("classpath*:config/test.properties", pathListProp.item(0).getTextContent());
    Assert.assertEquals("classpath*:config/test.ext.properties", pathListProp.item(1).getTextContent());
    NodeList xmlList = root.getElementsByTagName("xml");
    Assert.assertEquals(1, xmlList.getLength());
    Element xml = (Element) xmlList.item(0);
    Assert.assertEquals("xTest", xml.getAttributes().getNamedItem("id").getNodeValue());
    NodeList pathListXml = xml.getElementsByTagName("path");
    Assert.assertEquals(TEST_PROP_LIST_SIZE, pathListXml.getLength());
    Assert.assertEquals("classpath*:config/test.xml", pathListXml.item(0).getTextContent());
    Assert.assertEquals("classpath*:config/test.ext.xml", pathListXml.item(1).getTextContent());
}
Also used : IdXmlLoader(io.servicecomb.foundation.common.config.impl.IdXmlLoader) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

IdXmlLoader (io.servicecomb.foundation.common.config.impl.IdXmlLoader)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1