Package org.mule.module.xml.transformer

Examples of org.mule.module.xml.transformer.XPathExtractor


    @Test(expected=TransformerException.class)
    public void badExpression() throws Exception
    {
        final String badExpression = "/$@�%$�&�$$�%";
        final XPathExtractor extractor = initialiseExtractor(badExpression, XPathReturnType.STRING);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);
        extractor.transform(doc);
    }
View Full Code Here


    @Test
    public void nodeToStringResult() throws Exception
    {
        final String expression = "/root/node";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.STRING);

        // just make code coverage tools happy
        assertEquals("Wrong expression returned.", expression, extractor.getExpression());

        Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);

        final Object objResult = extractor.transform(doc);
        assertNotNull(objResult);

        final String result = (String)objResult;
        assertEquals("Wrong value extracted.", "value1", result);
    }
View Full Code Here

    @Test
    public void inputSourceToStringResult() throws Exception
    {
        final String expression = "/root/node";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.STRING);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);
        final InputSource source = getInputSourceForDocument(doc);

        final Object objResult = extractor.transform(source);
        assertNotNull(objResult);

        final String result = (String)objResult;
        assertEquals("Wrong value extracted.", "value1", result);
    }
View Full Code Here

    @Test
    public void nodeToNumberResult() throws Exception
    {
        final String expression = "/root/node2";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.NUMBER);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);

        final Object objResult = extractor.transform(doc);
        assertNotNull(objResult);

        final double result = ((Double) objResult).doubleValue();
        assertEquals("Wrong value extracted.", 2.0, result, 0.0);
    }
View Full Code Here

    @Test
    public void nodeToBooleanResult() throws Exception
    {
        final String expression = "/root/node2";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.BOOLEAN);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);

        final Object objResult = extractor.transform(doc);
        assertNotNull(objResult);

        final Boolean result = (Boolean)objResult;
        assertEquals("Wrong value extracted.", Boolean.TRUE, result);
    }
View Full Code Here

    @Test
    public void nodeToNodeResult() throws Exception
    {
        final String expression = "/root/node2";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.NODE);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);

        final Object objResult = extractor.transform(doc);
        assertNotNull(objResult);

        final Node result = (Node)objResult;
        assertEquals("Wrong value extracted.", "node2", result.getNodeName());
    }
View Full Code Here

    @Test
    public void nodeToNodeSetResult() throws Exception
    {
        final String expression = "/root/node2";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.NODESET);

        final Document doc = getDocumentForString(TEST_XML_SINGLE_RESULT);

        final Object objResult = extractor.transform(doc);
        assertThat(objResult, instanceOf(NodeList.class));

        NodeList result = (NodeList) objResult;
        assertEquals("Wrong value extracted.", "node2", result.item(0).getNodeName());
    }
View Full Code Here

    public void nodeToStringResultWithNameSpaces() throws Exception
    {
        registerNamespaces();

        final String expression = "//f:width";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.STRING);

        // just make code coverage tools happy
        assertEquals("Wrong expression returned.", expression, extractor.getExpression());

        final Document doc = getDocumentForString(TEST_XML_WITH_NAMESPACES);
        final Object objResult = extractor.transform(doc);
        assertNotNull(objResult);

        final String result = (String)objResult;
        assertEquals("Wrong value extracted.", "80", result);
    }
View Full Code Here

    public void xpathNamespacesInitialization() throws Exception
    {
        registerNamespaces();

        final String expression = "//f:width";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.STRING);

        final Map<String, String> namespaces = extractor.getXpathEvaluator().getRegisteredNamespaces();
        assertEquals("http://www.w3schools.com/furniture", namespaces.get("f"));
    }
View Full Code Here

        final Map<String, String> namespaces = new HashMap<String, String>();
        namespaces.put("g", "http://www.test.com/g");

        final String expression = "//f:width";
        final XPathExtractor extractor = initialiseExtractor(expression, XPathReturnType.STRING);
        extractor.setNamespaces(namespaces);

        assertEquals("http://www.test.com/g", extractor.getNamespaces().get("g"));
    }
View Full Code Here

TOP

Related Classes of org.mule.module.xml.transformer.XPathExtractor

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.