Package org.milyn

Examples of org.milyn.Smooks.filterSource()


        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-01.xml"));
        ExecutionContext execContext = smooks.createExecutionContext();
        String input = new String(StreamUtils.readStream(getClass().getResourceAsStream("test-01.xml")));
        StringWriter writer = new StringWriter();

        smooks.filterSource(execContext, new StreamSource(new ByteArrayInputStream(input.getBytes())), new StreamResult(writer));
        assertEquals(StreamUtils.trimLines(new StringReader(input)).toString(), StreamUtils.trimLines(new StringReader(writer.toString())).toString());
    }

    protected void setUp() throws Exception {
        SAXVisitor01.element = null;
View Full Code Here


    public void test_selection() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-02.xml"));
        ExecutionContext execContext = smooks.createExecutionContext();
        String input = new String(StreamUtils.readStream(getClass().getResourceAsStream("test-01.xml")));

        smooks.filterSource(execContext, new StreamSource(new ByteArrayInputStream(input.getBytes())), null);
        assertEquals("h", SAXVisitor01.element.getName().getLocalPart());
        assertEquals("y", SAXVisitor01.element.getName().getPrefix());
        assertEquals("http://y", SAXVisitor01.element.getName().getNamespaceURI());
        assertEquals(0, SAXVisitor01.children.size());
        assertEquals(0, SAXVisitor01.childText.size());
View Full Code Here

    public void test_contextual(String config) throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream(config));
        ExecutionContext execContext = smooks.createExecutionContext();
        String input = new String(StreamUtils.readStream(getClass().getResourceAsStream("test-01.xml")));

        smooks.filterSource(execContext, new StreamSource(new ByteArrayInputStream(input.getBytes())), null);
        assertEquals("h", SAXVisitor01.element.getName().getLocalPart());
        assertEquals("y", SAXVisitor01.element.getName().getPrefix());
        assertEquals("http://y", SAXVisitor01.element.getName().getNamespaceURI());
        assertEquals(0, SAXVisitor01.children.size());
        assertEquals(0, SAXVisitor01.childText.size());
View Full Code Here

    public void test_$document() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-04.xml"));
        ExecutionContext execContext = smooks.createExecutionContext();
        String input = new String(StreamUtils.readStream(getClass().getResourceAsStream("test-01.xml")));

        smooks.filterSource(execContext, new StreamSource(new ByteArrayInputStream(input.getBytes())), null);
        assertEquals("xx", SAXVisitor01.element.getName().getLocalPart());
        assertEquals("xx", SAXVisitor02.element.getName().getLocalPart());
        assertNull(SAXVisitor03.element);
    }
View Full Code Here

    }

    public void test_visitBeforeOnly() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-05.xml"));

        smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<a/>")), null);
        assertTrue(SAXVisitBeforeVisitor.visited);
        assertEquals("Hi There!", SAXVisitBeforeVisitor.staticInjectedParam);
    }

    public void test_visitBeforeAndChildren() throws IOException, SAXException {
View Full Code Here

    public void test_01() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("config-01.xml"));

        smooks.setFilterSettings(FilterSettings.DEFAULT_SAX);
        smooks.filterSource(new StreamSource(getClass().getResourceAsStream("order.xml")));
        assertEquals("8655", XPathVisitor.saxVisitedBeforeElementStatic.getAttribute("code"));
        assertEquals("8655", XPathVisitor.saxVisitedAfterElementStatic.getAttribute("code"));
    }

    public void test_02() throws IOException, SAXException {
View Full Code Here

    }

    public void test_visitBeforeAndChildren() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-05.xml"));

        smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<b/>")), null);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.visited);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildText);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildElement);
        SAXVisitBeforeAndChildrenVisitor.reset();
View Full Code Here

        assertTrue(SAXVisitBeforeAndChildrenVisitor.visited);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildText);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildElement);
        SAXVisitBeforeAndChildrenVisitor.reset();

        smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<b>text</b>")), null);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.visited);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.onChildText);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildElement);
        SAXVisitBeforeAndChildrenVisitor.reset();
View Full Code Here

    public void test_02() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("config-02.xml"));

        try {
            smooks.setFilterSettings(FilterSettings.DEFAULT_SAX);
            smooks.filterSource(new StreamSource(getClass().getResourceAsStream("order.xml")));
            fail("Expected SmooksConfigurationException");
        } catch(SmooksConfigurationException e) {

            assertEquals("Unsupported selector 'item[@code = '8655']/units[text() = 1]' on resource 'Target Profile: [[org.milyn.profile.Profile#default_profile]], Selector: [item[@code = '8655']/units[text() = 1]], Selector Namespace URI: [null], Resource: [org.milyn.cdr.xpath.XPathVisitor], Num Params: [0]'.  The 'text()' XPath token is only supported on SAX Visitor implementations that implement the org.milyn.delivery.sax.SAXVisitAfter interface only.  Class 'org.milyn.cdr.xpath.XPathVisitor' implements other SAX Visitor interfaces.", e.getMessage());
        }
View Full Code Here

        assertTrue(SAXVisitBeforeAndChildrenVisitor.visited);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.onChildText);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildElement);
        SAXVisitBeforeAndChildrenVisitor.reset();

        smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<b><x/></b>")), null);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.visited);
        assertFalse(SAXVisitBeforeAndChildrenVisitor.onChildText);
        assertTrue(SAXVisitBeforeAndChildrenVisitor.onChildElement);
        SAXVisitBeforeAndChildrenVisitor.reset();
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.