| Commit in servicemix/base/src on MAIN | |||
| main/java/org/servicemix/components/xslt/XsltComponent.java | +2 | -1 | 1.5 -> 1.6 |
| test/java/org/servicemix/components/xslt/XsltPublisherTest.java | +62 | added 1.1 | |
| test/java/org/servicemix/SpringTestSupport.java | +4 | -2 | 1.2 -> 1.3 |
| /TestSupport.java | +10 | -1 | 1.17 -> 1.18 |
| test/resources/org/servicemix/components/xslt/publish.xml | +32 | added 1.1 | |
| /publish.xsl | +42 | added 1.1 | |
| +152 | -4 | ||
added extra test case for publishing to multiple destinations from the XPath router
servicemix/base/src/main/java/org/servicemix/components/xslt
diff -u -r1.5 -r1.6 --- XsltComponent.java 5 Aug 2005 08:13:32 -0000 1.5 +++ XsltComponent.java 30 Aug 2005 19:13:44 -0000 1.6 @@ -45,7 +45,7 @@
* An <a href="">XSLT</a> based JBI component using * <a href="">JAXP</a> to perform the XSLT transformation. *
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class XsltComponent extends TransformComponentSupport implements MessageExchangeListener {
@@ -118,6 +118,7 @@
return shouldOutputResult(transformer);
}
catch (TransformerException e) {
+ e.printStackTrace();
throw new MessagingException("Failed to transform: " + e, e);
}
catch (IOException e) {
servicemix/base/src/test/java/org/servicemix/components/xslt
XsltPublisherTest.java added at 1.1
diff -N XsltPublisherTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ XsltPublisherTest.java 30 Aug 2005 19:13:45 -0000 1.1 @@ -0,0 +1,62 @@
+/**
+ *
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ *
+ * Licensed 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.servicemix.components.xslt;
+
+import org.servicemix.TestSupport;
+import org.servicemix.examples.MessageList;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class XsltPublisherTest extends TestSupport {
+
+ public void testUseXsltAsRouter() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ sendMessages(service, 20);
+ assertMessagesReceived(20);
+
+ MessageList messageList1 = assertMessagesReceived("service1", 20);
+ MessageList messageList2 = assertMessagesReceived("service2", 20);
+ assertMessagesReceived("service3", 20);
+
+ assertMessageHeader(messageList1, 0, "foo", "hello world!");
+ assertMessageHeader(messageList1, 1, "foo", "hello world!");
+ assertMessageHeader(messageList1, 19, "foo", "hello world!");
+
+ assertMessageHeader(messageList2, 0, "bar", "1");
+ assertMessageHeader(messageList2, 1, "bar", "2");
+ }
+
+ protected void assertMessageHeader(MessageList messageList, int index, String propertyName, Object expectedValue) {
+ NormalizedMessage message = (NormalizedMessage) messageList.getMessages().get(index);
+ assertNotNull("Message: " + index + " is null!", message);
+
+ Object value = message.getProperty(propertyName);
+ assertEquals("property: " + propertyName, expectedValue, value);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/servicemix/components/xslt/publish.xml");
+ }
+}
servicemix/base/src/test/java/org/servicemix
diff -u -r1.2 -r1.3 --- SpringTestSupport.java 27 Jul 2005 09:27:44 -0000 1.2 +++ SpringTestSupport.java 30 Aug 2005 19:13:45 -0000 1.3 @@ -40,17 +40,19 @@
import java.util.List; /**
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public abstract class SpringTestSupport extends TestCase {
protected transient Log log = LogFactory.getLog(getClass());
protected AbstractXmlApplicationContext context;
- protected SourceTransformer transformer = new SourceTransformer();
+ protected SourceTransformer transformer;
protected int messageCount = 20;
protected SpringJBIContainer jbi;
protected void setUp() throws Exception {
+ transformer = new SourceTransformer(); +
context = createBeanFactory();
context.setXmlValidating(false);
servicemix/base/src/test/java/org/servicemix
diff -u -r1.17 -r1.18 --- TestSupport.java 5 Aug 2005 08:13:32 -0000 1.17 +++ TestSupport.java 30 Aug 2005 19:13:45 -0000 1.18 @@ -52,7 +52,7 @@
import java.util.Date; /**
- * @version $Revision: 1.17 $
+ * @version $Revision: 1.18 $
*/
public abstract class TestSupport extends SpringTestSupport {
protected ServiceMixClient client;
@@ -122,6 +122,15 @@
MessageList messageList = receiver.getMessageList();
assertMessagesReceived(messageList, messageCount);
+ }
+
+ protected MessageList assertMessagesReceived(String receiverName, int messageCount) throws Exception {
+ Receiver receiver = (Receiver) getBean(receiverName);
+ assertNotNull("receiver: " + receiverName + " not found in JBI container", receiver);
+
+ MessageList messageList = receiver.getMessageList();
+ assertMessagesReceived(messageList, messageCount);
+ return messageList;
}
/**
servicemix/base/src/test/resources/org/servicemix/components/xslt
publish.xml added at 1.1
diff -N publish.xml --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ publish.xml 30 Aug 2005 19:13:45 -0000 1.1 @@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns:foo="http://servicemix.org/cheese/"> + + <!-- the JBI container --> + <container id="jbi"> + <components> + + <!-- START SNIPPET: xslt --> + <component id="transformer" service="foo:transformer" class="org.servicemix.components.xslt.XsltComponent"> + <property name="xsltResource" value="classpath:org/servicemix/components/xslt/publish.xsl"/> + + <!-- lets disable automatic output of the result of the transform; only if we perform + an invoke in the XSLT will we invoke another endpoint --> + <property name="disableOutput" value="true"/> + </component> + <!-- END SNIPPET: xslt --> + + + <component id="service1" service="foo:service1" class="org.servicemix.examples.ReceiverComponent"/> + <component id="service2" service="foo:service2" class="org.servicemix.examples.ReceiverComponent"/> + <component id="service3" service="foo:service3" class="org.servicemix.examples.ReceiverComponent"/> + + <component id="receiver" service="foo:receiver" class="org.servicemix.examples.ReceiverComponent"/> + + <component id="trace" service="foo:trace" class="org.servicemix.components.util.TraceComponent"/> + </components> + </container> + + <bean id="client" class="org.servicemix.client.DefaultServiceMixClient"> + <constructor-arg ref="jbi"/> + </bean> +</beans>
servicemix/base/src/test/resources/org/servicemix/components/xslt
publish.xsl added at 1.1
diff -N publish.xsl --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ publish.xsl 30 Aug 2005 19:13:45 -0000 1.1 @@ -0,0 +1,42 @@
+<?xml version="1.0"?> +<!-- START SNIPPET: route --> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:jbi="xalan://org.servicemix.components.xslt.XalanExtension" + extension-element-prefixes="jbi" + + xmlns:foo="http://servicemix.org/cheese/" + version="1.0"> + + <xsl:strip-space elements="*"/> + + <xsl:template match="/*"> + + <!-- lets invoke a number of services one after the other --> + <jbi:invoke service="foo:service1"> + <jbi:copyProperties/> + <jbi:setOutProperty name="foo" select="/sample"/> + <xsl:copy-of select="/"/> + </jbi:invoke> + + <jbi:invoke service="foo:service2"> + <jbi:copyProperties/> + <jbi:setOutProperty name="bar" select="/sample/@id"/> + <xsl:copy-of select="/"/> + </jbi:invoke> + + <jbi:invoke service="foo:service3"> + <jbi:copyProperties/> + <jbi:setOutProperty name="bar" select="/sample/@id"/> + <xsl:copy-of select="/"/> + </jbi:invoke> + + <jbi:invoke service="foo:receiver"> + <jbi:copyProperties/> + <jbi:setOutProperty name="bar" select="/sample/@id"/> + <xsl:copy-of select="/"/> + </jbi:invoke> + + </xsl:template> + +</xsl:stylesheet> +<!-- END SNIPPET: route -->
