Package org.milyn

Examples of org.milyn.Smooks


* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class AbstractParserTest extends TestCase {

    public void test() throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream("smooks-config-AbstractParserTest.xml"));
        ExecutionContext execContext = smooks.createExecutionContext();

        TestParser parser = new TestParser(execContext);
        TestXMLReader reader = (TestXMLReader) parser.createXMLReader();

        parser.configureReader(reader, new DefaultHandler2(), execContext, null);
View Full Code Here


        assertNotNull(reader.entityResolver);
        assertNotNull(reader.errorHandler);
    }
   
    public void test_readerPool_Pooled() {
      Smooks smooks = new Smooks();
     
      smooks.setReaderConfig(new GenericReaderConfigurator(PooledSAXParser.class));
      smooks.setFilterSettings(FilterSettings.newSAXSettings().setReaderPoolSize(1));
     
      PooledSAXParser.numSetHandlerCalls = 0;
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));     
      assertEquals(3, PooledSAXParser.numSetHandlerCalls);
    }
View Full Code Here

      smooks.filterSource(new StringSource("<x/>"));     
      assertEquals(3, PooledSAXParser.numSetHandlerCalls);
    }
   
    public void test_readerPool_Unpooled() {
      Smooks smooks = new Smooks();
     
      smooks.setReaderConfig(new GenericReaderConfigurator(UnpooledSAXParser.class));
      smooks.setFilterSettings(FilterSettings.newSAXSettings().setReaderPoolSize(0));
     
      UnpooledSAXParser.numSetHandlerCalls = 0;
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));     
      assertEquals(3, UnpooledSAXParser.numSetHandlerCalls);
    }
View Full Code Here

    protected void tearDown() throws Exception {
        System.getProperties().remove("test.parameter");
    }

    public void test_system_property() {
        Smooks smooks = new Smooks();
        ContentDeliveryConfig deliveryConfig = smooks.createExecutionContext().getDeliveryConfig();

        assertEquals(null, ParameterAccessor.getStringParameter("test.parameter", deliveryConfig));

        System.setProperty("test.parameter", "xxxxxxx");
        assertEquals("xxxxxxx", ParameterAccessor.getStringParameter("test.parameter", deliveryConfig));
View Full Code Here

        test_exception("no-exception-config.xml", false);
        test_exception("no-exception-config-sax.xml", false);
    }

    private void test_exception(String config, boolean expectException) throws IOException, SAXException {
        Smooks smooks = new Smooks("/org/milyn/delivery/" + config);

        if(expectException) {
            try {
                smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<doc/>")), null);
                fail("Expected SmooksException");
            } catch(SmooksException e) {
                assertEquals("Terminate Exception", e.getCause().getMessage());
            }
        } else {
            smooks.filterSource(smooks.createExecutionContext(), new StreamSource(new StringReader("<doc/>")), null);
        }
    }
View Full Code Here

* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class MILYN_560_Test extends TestCase {

    public void test_DOM() {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new DOMVisitAfter() {
            public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException {
                assertEquals("&tomfennelly", element.getAttribute("attrib"));
                assertEquals("&tomfennelly", element.getTextContent());
            }
        }, "element");

        StringResult serializedRes = new StringResult();
        smooks.filterSource(new StringSource("<element attrib=\"&amp;tomfennelly\">&amp;tomfennelly</element>"), serializedRes);

        assertEquals("<element attrib=\"&amp;tomfennelly\">&amp;tomfennelly</element>", serializedRes.getResult());
    }
View Full Code Here

        assertEquals("<element attrib=\"&amp;tomfennelly\">&amp;tomfennelly</element>", serializedRes.getResult());
    }

    public void test_SAX() {
        Smooks smooks = new Smooks();

        smooks.addVisitor(new MockSAX(), "element");

        StringResult serializedRes = new StringResult();
        smooks.filterSource(new StringSource("<element attrib=\"&amp;tomfennelly\">&amp;tomfennelly</element>"), serializedRes);

        assertEquals("<element attrib=\"&amp;tomfennelly\">&amp;tomfennelly</element>", serializedRes.getResult());
    }
View Full Code Here

        testListener(eventListener, "smooks-config-dom.xml", "test-data-01.xml");
        assertEquals(30, eventListener.getEvents().size());
    }

    private void testListener(BasicExecutionEventListener eventListener, String config, String sourceFile) throws IOException, SAXException {
        Smooks smooks = new Smooks(getClass().getResourceAsStream(config));
        ExecutionContext execContext = smooks.createExecutionContext();
        StreamSource source = new StreamSource(getClass().getResourceAsStream(sourceFile));

        execContext.setEventListener(eventListener);
        smooks.filterSource(execContext, source, new StreamResult(new NullWriter()));
    }
View Full Code Here

public class SmooksVisitorPhaseTest extends TestCase {
 
  Log log = LogFactory.getLog( SmooksVisitorPhaseTest.class );

    public void test_phase_selection() throws IOException, SAXException {
        Smooks smooks = new Smooks();
        ExecutionContext execContext;
        DOMContentDeliveryConfig config;

        smooks.addConfigurations("config1.xml", getClass().getResourceAsStream("config1.xml"));
        execContext = smooks.createExecutionContext();
        config = (DOMContentDeliveryConfig) execContext.getDeliveryConfig();

        // Check the assembly units...
        List<ContentHandlerConfigMap<DOMVisitBefore>> assemblyVBs = config.getAssemblyVisitBefores().getMappings("a");
        List<ContentHandlerConfigMap<DOMVisitAfter>> assemblyVAs = config.getAssemblyVisitAfters().getMappings("a");
View Full Code Here

        assertTrue(processingVAs.get(0).getContentHandler() instanceof ConfigurableVisitor);
        assertTrue(processingVAs.get(1).getContentHandler() instanceof ProcessorVisitor1);
    }

    public void test_filtering() throws IOException, SAXException {
        Smooks smooks = new Smooks();
        BasicExecutionEventListener eventListener = new BasicExecutionEventListener();

        smooks.addConfigurations("config2.xml", getClass().getResourceAsStream("config2.xml"));
        // Create an exec context - no profiles....
        ExecutionContext executionContext = smooks.createExecutionContext();
        CharArrayWriter outputWriter = new CharArrayWriter();

        // Filter the input message to the outputWriter, using the execution context...
        executionContext.setEventListener(eventListener);
        smooks.filterSource(executionContext, new StreamSource(getClass().getResourceAsStream("testxml1.xml")), new StreamResult(outputWriter));

        log.debug(outputWriter.toString());
        byte[] expected = StreamUtils.readStream(getClass().getResourceAsStream("testxml1-expected.xml"));
        assertTrue(StreamUtils.compareCharStreams(new ByteArrayInputStream(expected), new ByteArrayInputStream(outputWriter.toString().getBytes())));
        assertEquals(32, eventListener.getEvents().size());
View Full Code Here

TOP

Related Classes of org.milyn.Smooks

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.