01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
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 {
35: container = new JBIContainer();
36: container.setEmbedded(true);
37: container.init();
38: container.start();
39: }
40:
41: protected void tearDown() throws Exception {
42: container.shutDown();
43: }
44:
45: public void testEndpointConnection() throws Exception {
46: Receiver receiver = new ReceiverComponent();
47: ActivationSpec asReceiver = new ActivationSpec();
48: asReceiver.setComponent(receiver);
49: asReceiver.setService(new QName("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("service"));
56: asSender.setDestinationEndpoint("linkedEndpoint");
57:
58: container.activateComponent(asReceiver);
59: container.activateComponent(asSender);
60: container.getRegistry().registerEndpointConnection(
61: new QName("service"), "linkedEndpoint",
62: new QName("service"), "endpoint", null);
63:
64: sender.sendMessages(1);
65: receiver.getMessageList().assertMessagesReceived(1);
66: }
67:
68: public void testInterfaceConnection() throws Exception {
69: Receiver receiver = new ReceiverComponent();
70: ActivationSpec asReceiver = new ActivationSpec();
71: asReceiver.setComponent(receiver);
72: asReceiver.setService(new QName("service"));
73: asReceiver.setEndpoint("endpoint");
74:
75: Sender sender = new SenderComponent();
76: ActivationSpec asSender = new ActivationSpec();
77: asSender.setComponent(sender);
78: asSender.setDestinationInterface(new QName("interface"));
79:
80: container.activateComponent(asReceiver);
81: container.activateComponent(asSender);
82: container.getRegistry().registerInterfaceConnection(
83: new QName("interface"), new QName("service"),
84: "endpoint");
85:
86: sender.sendMessages(1);
87: receiver.getMessageList().assertMessagesReceived(1);
88: }
89:
90: }
|