KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jsr181 > Jsr181ProxySUTest


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.jsr181;
18
19 import java.io.File JavaDoc;
20 import java.net.URL JavaDoc;
21
22 import javax.jbi.messaging.ExchangeStatus;
23 import javax.jbi.messaging.InOut;
24 import javax.naming.InitialContext JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.apache.servicemix.client.DefaultServiceMixClient;
30 import org.apache.servicemix.jbi.container.JBIContainer;
31 import org.apache.servicemix.jbi.jaxp.StringSource;
32
33 public class Jsr181ProxySUTest extends TestCase {
34
35     protected JBIContainer container;
36     
37     protected void setUp() throws Exception JavaDoc {
38         container = new JBIContainer();
39         container.setUseMBeanServer(false);
40         container.setCreateMBeanServer(false);
41         container.setMonitorInstallationDirectory(false);
42         container.setNamingContext(new InitialContext JavaDoc());
43         container.setEmbedded(true);
44         container.init();
45     }
46     
47     protected void tearDown() throws Exception JavaDoc {
48         if (container != null) {
49             container.shutDown();
50         }
51     }
52     
53     public void test() throws Exception JavaDoc {
54         Jsr181Component component = new Jsr181Component();
55         container.activateComponent(component, "JSR181Component");
56
57         // Start container
58
container.start();
59         
60         // Deploy SU
61
component.getServiceUnitManager().deploy("target", getServiceUnitPath("target"));
62         component.getServiceUnitManager().init("target", getServiceUnitPath("target"));
63         component.getServiceUnitManager().start("target");
64         
65         component.getServiceUnitManager().deploy("proxy", getServiceUnitPath("proxy"));
66         component.getServiceUnitManager().init("proxy", getServiceUnitPath("proxy"));
67         component.getServiceUnitManager().start("proxy");
68         
69         DefaultServiceMixClient client = new DefaultServiceMixClient(container);
70         InOut me = client.createInOutExchange(new QName JavaDoc("http://test", "Echo"), null, null);
71         me.setInMessage(me.createMessage());
72         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><msg>world</msg></echo>"));
73         client.sendSync(me);
74         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
75         assertNotNull(me.getOutMessage());
76         client.done(me);
77     }
78     
79     protected String JavaDoc getServiceUnitPath(String JavaDoc name) {
80         URL JavaDoc url = getClass().getClassLoader().getResource(name + "/xbean.xml");
81         File JavaDoc path = new File JavaDoc(url.getFile());
82         path = path.getParentFile();
83         return path.getAbsolutePath();
84     }
85     
86 }
87
Popular Tags