Title: [693] trunk/components/base/src/test/java/org/servicemix/components/groovy: Groovy routing test
- Revision
- 693
- Author
- gnt
- Date
- 2005-10-28 04:45:22 -0400 (Fri, 28 Oct 2005)
Log Message
Groovy routing test
Added Paths
Diff
Added: trunk/components/base/src/test/java/org/servicemix/components/groovy/GroovyChainTest.java (692 => 693)
--- trunk/components/base/src/test/java/org/servicemix/components/groovy/GroovyChainTest.java 2005-10-27 23:02:18 UTC (rev 692)
+++ trunk/components/base/src/test/java/org/servicemix/components/groovy/GroovyChainTest.java 2005-10-28 08:45:22 UTC (rev 693)
@@ -0,0 +1,99 @@
+/**
+ *
+ * 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.groovy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.client.ServiceMixClient;
+import org.servicemix.examples.Receiver;
+import org.servicemix.jbi.container.SpringJBIContainer;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision: 603 $
+ */
+public class GroovyChainTest extends TestCase {
+ private static final transient Log log = LogFactory.getLog(GroovyChainTest.class);
+
+ protected AbstractXmlApplicationContext context;
+ protected ServiceMixClient client;
+ protected Receiver receiver;
+
+ protected SourceTransformer transformer = new SourceTransformer();
+
+
+ // Send methods
+ //-------------------------------------------------------------------------
+ public void testChain() throws Exception {
+
+ InOut exchange = client.createInOutExchange();
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ exchange.setService(service);
+ client.sendSync(exchange);
+
+ System.out.println(transformer.toString(exchange.getMessage("out").getContent()));
+ }
+
+
+ protected void setUp() throws Exception {
+ context = createBeanFactory();
+ //context.setXmlValidating(false);
+
+ client = (ServiceMixClient) getBean("client");
+
+ // TODO
+ //receiver = (Receiver) getBean("receiver");
+
+ SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ protected Object getBean(String name) {
+ Object answer = context.getBean(name);
+ assertNotNull("Could not find object in Spring for key: " + name, answer);
+ return answer;
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/servicemix/components/groovy/groovy-chain.xml");
+
+ }
+}
Added: trunk/components/base/src/test/resources/org/servicemix/components/groovy/groovy-chain.xml (692 => 693)
--- trunk/components/base/src/test/resources/org/servicemix/components/groovy/groovy-chain.xml 2005-10-27 23:02:18 UTC (rev 692)
+++ trunk/components/base/src/test/resources/org/servicemix/components/groovy/groovy-chain.xml 2005-10-28 08:45:22 UTC (rev 693)
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://xbean.org/schemas/spring/1.0"
+ xmlns:spring="http://xbean.org/schemas/spring/1.0"
+ xmlns:sm="http://servicemix.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container spring:id="jbi" flowName="st">
+ <sm:activationSpecs>
+
+ <!-- chaining router -->
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component>
+ <bean class="org.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value><![CDATA[
+
+println "Called with inbound message $inMessage"
+
+// lets output some message properties
+def me1 = deliveryChannel.createExchangeFactoryForService(new javax.xml.namespace.QName("http://servicemix.org/cheese/", "service1")).createInOutExchange()
+def in1 = me1.createMessage()
+in1.bodyText = inMessage.bodyText
+me1.setMessage(in1, "in")
+deliveryChannel.sendSync(me1)
+println "Received: " + me1.getMessage("out").bodyText
+
+// lets output some message properties
+def me2 = deliveryChannel.createExchangeFactoryForService(new javax.xml.namespace.QName("http://servicemix.org/cheese/", "service2")).createInOutExchange()
+def in2 = me2.createMessage()
+in2.bodyText = me1.getMessage("out").bodyText
+me2.setMessage(in2, "in")
+deliveryChannel.sendSync(me2)
+println "Received: " + me2.getMessage("out").bodyText
+
+// lets output some non-xml body
+outMessage.bodyText = me2.getMessage("out").bodyText
+
+ ]]></value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service1"
+ service="foo:service1">
+ <sm:component>
+ <bean class="org.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+println "In Service1"
+def txt = inMessage.bodyText
+println "Content: " + txt
+
+// lets output some non-xml body
+outMessage.bodyText = txt.replace("world", "<service1>world</service1>")
+ ]]>
+ </value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service2"
+ service="foo:service2">
+ <sm:component>
+ <bean class="org.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+println "In Service2"
+def txt = inMessage.bodyText
+println "Content: " + txt
+
+// lets output some non-xml body
+outMessage.bodyText = """
+<service2>
+ <![CDATA[
+ $txt
+ ]""" + """]>
+</service2>
+"""
+ ]]>
+ </value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <!-- START SNIPPET: client -->
+ <bean id="client" class="org.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ </bean>
+ <!-- END SNIPPET: client -->
+
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <!-- START SNIPPET: clientroute -->
+ <bean id="clientWithRouting" class="org.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ <constructor-arg>
+ <sm:activationSpec destinationService="foo:receiver"/>
+ </constructor-arg>
+ </bean>
+ <!-- END SNIPPET: clientroute -->
+
+
+</beans>