Author: ningjiang Date: Thu Dec 1 06:27:37 2011 New Revision: 1208964 URL: http://svn.apache.org/viewvc?rev=1208964&view=rev Log: Added SaxonXsltTest to the camel-saxon
Added: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java (with props) camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl (with props) Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltFromFileExceptionTest.java camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/camelXsltContext.xml Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltFromFileExceptionTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltFromFileExceptionTest.java?rev=1208964&r1=1208963&r2=1208964&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltFromFileExceptionTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/xslt/XsltFromFileExceptionTest.java Thu Dec 1 06:27:37 2011 @@ -77,6 +77,7 @@ public class XsltFromFileExceptionTest e .onException(Exception.class) .to("mock:error") .end() + .convertBodyTo(String.class) .to("xslt:org/apache/camel/component/xslt/example.xsl") .to("mock:result"); } Added: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java?rev=1208964&view=auto ============================================================================== --- camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java (added) +++ camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java Thu Dec 1 06:27:37 2011 @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.xslt; + +import java.util.List; + +import org.apache.camel.Exchange; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SaxonXsltTest extends CamelSpringTestSupport { + + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/xslt/camelXsltContext.xml"); + } + + @Test + public void testSendMessageAndHaveItTransformed() throws Exception { + MockEndpoint endpoint = getMockEndpoint("mock:result"); + endpoint.expectedMessageCount(1); + + template.sendBody("direct:start", + "<mail><subject>Hey</subject><body>Hello world!</body></mail>"); + + assertMockEndpointsSatisfied(); + + List<Exchange> list = endpoint.getReceivedExchanges(); + Exchange exchange = list.get(0); + String xml = exchange.getIn().getBody(String.class); + + assertNotNull("The transformed XML should not be null", xml); + assertTrue(xml.indexOf("transformed") > -1); + // the cheese tag is in the transform.xsl + assertTrue(xml.indexOf("cheese") > -1); + assertTrue(xml.indexOf("<subject>Hey</subject>") > -1); + assertTrue(xml.indexOf("<body>Hello world!</body>") > -1); + + } + +} Propchange: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/camelXsltContext.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/camelXsltContext.xml?rev=1208964&r1=1208963&r2=1208964&view=diff ============================================================================== --- camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/camelXsltContext.xml (original) +++ camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/camelXsltContext.xml Thu Dec 1 06:27:37 2011 @@ -28,13 +28,11 @@ <from uri="direct:start"/> <to uri="xslt:org/apache/camel/component/xslt/transform.xsl?transformerFactory=factory"/> <multicast> - <bean ref="testBean"/> <to uri="mock:result"/> </multicast> </route> </camelContext> <!-- END SNIPPET: example --> - <bean id="testBean" class="org.apache.camel.component.xslt.TestBean" scope="singleton"/> <bean id="factory" class="net.sf.saxon.TransformerFactoryImpl"/> </beans> Added: camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl?rev=1208964&view=auto ============================================================================== --- camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl (added) +++ camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl Thu Dec 1 06:27:37 2011 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<xsl:stylesheet + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + version='1.0'> + + <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/> + + <xsl:template match="/"> + <transformed subject="{/mail/subject}"> + <cheese> + <xsl:apply-templates select="*|@*"/> + </cheese> + </transformed> + </xsl:template> + + <xsl:template match="*"> + <xsl:copy> + <xsl:copy-of select="attribute::*"/> + <xsl:apply-templates/> + </xsl:copy> + </xsl:template> + +</xsl:stylesheet> Propchange: camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform.xsl ------------------------------------------------------------------------------ svn:mime-type = text/xml