KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > groovy > GroovyChainTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.groovy;
18
19 import java.io.StringReader JavaDoc;
20
21 import javax.jbi.messaging.InOut;
22 import javax.jbi.messaging.NormalizedMessage;
23 import javax.xml.namespace.QName JavaDoc;
24 import javax.xml.transform.stream.StreamSource JavaDoc;
25
26 import junit.framework.TestCase;
27
28 import org.apache.servicemix.client.ServiceMixClient;
29 import org.apache.servicemix.jbi.container.SpringJBIContainer;
30 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
31 import org.apache.servicemix.tck.Receiver;
32 import org.springframework.context.support.AbstractXmlApplicationContext;
33 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
34
35 /**
36  * @version $Revision: 426415 $
37  */

38 public class GroovyChainTest extends TestCase {
39     protected AbstractXmlApplicationContext context;
40     protected ServiceMixClient client;
41     protected Receiver receiver;
42
43     protected SourceTransformer transformer = new SourceTransformer();
44
45
46     // Send methods
47
//-------------------------------------------------------------------------
48
public void testChain() throws Exception JavaDoc {
49
50         InOut exchange = client.createInOutExchange();
51
52         NormalizedMessage message = exchange.getInMessage();
53         message.setContent(new StreamSource JavaDoc(new StringReader JavaDoc("<hello>world</hello>")));
54
55         QName JavaDoc service = new QName JavaDoc("http://servicemix.org/cheese/", "receiver");
56         exchange.setService(service);
57         client.sendSync(exchange);
58         
59         System.out.println(transformer.toString(exchange.getMessage("out").getContent()));
60     }
61
62
63     protected void setUp() throws Exception JavaDoc {
64         context = createBeanFactory();
65         //context.setXmlValidating(false);
66

67         client = (ServiceMixClient) getBean("client");
68
69         // TODO
70
//receiver = (Receiver) getBean("receiver");
71

72         SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
73         assertNotNull(jbi);
74     }
75
76     protected void tearDown() throws Exception JavaDoc {
77         super.tearDown();
78
79         if (context != null) {
80             context.close();
81         }
82     }
83
84     protected Object JavaDoc getBean(String JavaDoc name) {
85         Object JavaDoc answer = context.getBean(name);
86         assertNotNull("Could not find object in Spring for key: " + name, answer);
87         return answer;
88     }
89
90     protected AbstractXmlApplicationContext createBeanFactory() {
91         return new ClassPathXmlApplicationContext("org/apache/servicemix/components/groovy/groovy-chain.xml");
92
93     }
94 }
95
Popular Tags