KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > nmr > ConnectionsTest


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.jbi.nmr;
18
19 import javax.xml.namespace.QName JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.servicemix.jbi.container.ActivationSpec;
24 import org.apache.servicemix.jbi.container.JBIContainer;
25 import org.apache.servicemix.tck.Receiver;
26 import org.apache.servicemix.tck.ReceiverComponent;
27 import org.apache.servicemix.tck.Sender;
28 import org.apache.servicemix.tck.SenderComponent;
29
30 public class ConnectionsTest extends TestCase {
31
32     private JBIContainer container;
33     
34     protected void setUp() throws Exception JavaDoc {
35         container = new JBIContainer();
36         container.setEmbedded(true);
37         container.init();
38         container.start();
39     }
40     
41     protected void tearDown() throws Exception JavaDoc {
42         container.shutDown();
43     }
44     
45     public void testEndpointConnection() throws Exception JavaDoc {
46         Receiver receiver = new ReceiverComponent();
47         ActivationSpec asReceiver = new ActivationSpec();
48         asReceiver.setComponent(receiver);
49         asReceiver.setService(new QName JavaDoc("service"));
50         asReceiver.setEndpoint("endpoint");
51         
52         Sender sender = new SenderComponent();
53         ActivationSpec asSender = new ActivationSpec();
54         asSender.setComponent(sender);
55         asSender.setDestinationService(new QName JavaDoc("service"));
56         asSender.setDestinationEndpoint("linkedEndpoint");
57         
58         container.activateComponent(asReceiver);
59         container.activateComponent(asSender);
60         container.getRegistry().registerEndpointConnection(new QName JavaDoc("service"), "linkedEndpoint", new QName JavaDoc("service"), "endpoint", null);
61         
62         sender.sendMessages(1);
63         receiver.getMessageList().assertMessagesReceived(1);
64     }
65     
66     public void testInterfaceConnection() throws Exception JavaDoc {
67         Receiver receiver = new ReceiverComponent();
68         ActivationSpec asReceiver = new ActivationSpec();
69         asReceiver.setComponent(receiver);
70         asReceiver.setService(new QName JavaDoc("service"));
71         asReceiver.setEndpoint("endpoint");
72         
73         Sender sender = new SenderComponent();
74         ActivationSpec asSender = new ActivationSpec();
75         asSender.setComponent(sender);
76         asSender.setDestinationInterface(new QName JavaDoc("interface"));
77         
78         container.activateComponent(asReceiver);
79         container.activateComponent(asSender);
80         container.getRegistry().registerInterfaceConnection(new QName JavaDoc("interface"), new QName JavaDoc("service"), "endpoint");
81         
82         sender.sendMessages(1);
83         receiver.getMessageList().assertMessagesReceived(1);
84     }
85     
86 }
87
Popular Tags