KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jbi.messaging.ExchangeStatus;
20 import javax.jbi.messaging.InOut;
21 import javax.xml.namespace.QName JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.servicemix.components.util.EchoComponent;
26 import org.apache.servicemix.jbi.container.ActivationSpec;
27 import org.apache.servicemix.jbi.container.JBIContainer;
28 import org.apache.servicemix.jbi.jaxp.StringSource;
29 import org.springframework.jndi.JndiObjectFactoryBean;
30
31 /**
32  * @author <a HREF="mailto:gnodet [at] apache.org">Guillaume Nodet</a>
33  */

34 public class ClientFactoryTest extends TestCase {
35
36     private JBIContainer jbi;
37     
38     protected void setUp() throws Exception JavaDoc {
39         jbi = new JBIContainer();
40         jbi.setEmbedded(true);
41         jbi.init();
42         jbi.start();
43     }
44     
45     protected void shutDown() throws Exception JavaDoc {
46         jbi.shutDown();
47     }
48     
49     public void testClientFactory() throws Exception JavaDoc {
50         ActivationSpec as = new ActivationSpec();
51         as.setId("echo");
52         as.setComponent(new EchoComponent());
53         as.setService(new QName JavaDoc("echo"));
54         jbi.activateComponent(as);
55         
56         JndiObjectFactoryBean fb = new JndiObjectFactoryBean();
57         fb.setJndiName(ClientFactory.DEFAULT_JNDI_NAME);
58         fb.afterPropertiesSet();
59         ClientFactory cf = (ClientFactory) fb.getObject();
60         ServiceMixClient client = cf.createClient();
61         
62         Destination dest = client.createDestination("service::echo");
63         InOut me = dest.createInOutExchange();
64         me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
65         client.sendSync(me);
66         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
67         client.done(me);
68         client.close();
69     }
70 }
71
Popular Tags