KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > client > SimpleClientTest


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.client;
18
19 import org.apache.servicemix.client.DefaultServiceMixClient;
20 import org.apache.servicemix.client.ServiceMixClient;
21 import org.apache.servicemix.components.util.OutBinding;
22 import org.apache.servicemix.jbi.container.ActivationSpec;
23 import org.apache.servicemix.jbi.container.JBIContainer;
24
25 import javax.jbi.messaging.InOnly;
26 import javax.jbi.messaging.MessageExchange;
27 import javax.jbi.messaging.MessagingException;
28 import javax.jbi.messaging.NormalizedMessage;
29 import javax.xml.namespace.QName JavaDoc;
30 import javax.xml.transform.stream.StreamSource JavaDoc;
31
32 import java.io.StringReader JavaDoc;
33
34 import junit.framework.TestCase;
35
36 /**
37  * @version $Revision: 426415 $
38  */

39 public class SimpleClientTest extends TestCase {
40     protected JBIContainer container;
41     protected OutBinding out;
42     protected ServiceMixClient client;
43
44     protected void setUp() throws Exception JavaDoc {
45         container = new JBIContainer();
46         container.setEmbedded(true);
47         container.init();
48         container.start();
49         out = new OutBinding() {
50             protected void process(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
51                 System.out.println("Received: " + message);
52                 done(exchange);
53             }
54         };
55         ActivationSpec as = new ActivationSpec("out",out);
56         as.setService(new QName JavaDoc("out"));
57         container.activateComponent(as);
58         client = new DefaultServiceMixClient(container);
59     }
60
61     protected void tearDown() throws Exception JavaDoc {
62         container.shutDown();
63     }
64
65     /**
66      * Simple test
67      *
68      * @throws Exception
69      */

70     public void testSimple() throws Exception JavaDoc {
71         InOnly exchange = client.createInOnlyExchange();
72         NormalizedMessage message = exchange.getInMessage();
73         message.setProperty("name", "john");
74         message.setContent(new StreamSource JavaDoc(new StringReader JavaDoc("<hello>world</hello>")));
75         QName JavaDoc service = new QName JavaDoc("out");
76         exchange.setService(service);
77         client.sendSync(exchange);
78     }
79 }
80
Popular Tags