001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.jbi.nmr;
018:
019: import javax.jbi.messaging.MessageExchange;
020: import javax.jbi.messaging.MessagingException;
021: import javax.jbi.messaging.NormalizedMessage;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.servicemix.jbi.container.ActivationSpec;
026: import org.apache.servicemix.jbi.container.JBIContainer;
027: import org.apache.servicemix.jbi.container.SubscriptionSpec;
028: import org.apache.servicemix.jbi.nmr.flow.Flow;
029: import org.apache.servicemix.jbi.nmr.flow.FlowProvider;
030: import org.apache.servicemix.tck.ReceiverComponent;
031: import org.apache.servicemix.tck.Sender;
032: import org.apache.servicemix.tck.SenderComponent;
033:
034: public class SubscriptionPropertyCopyTest extends TestCase {
035:
036: public void testStNull() throws Exception {
037: runTest("st", null);
038: }
039:
040: public void testStSt() throws Exception {
041: runTest("st", "st");
042: }
043:
044: public void testStSeda() throws Exception {
045: runTest("st", "seda");
046: }
047:
048: public void testSedaNull() throws Exception {
049: runTest("seda", null);
050: }
051:
052: public void testSedaSt() throws Exception {
053: runTest("seda", "st");
054: }
055:
056: public void testSedaSeda() throws Exception {
057: runTest("seda", "seda");
058: }
059:
060: private void runTest(String flowName, String subscriptionFlowName)
061: throws Exception {
062: JBIContainer container = new JBIContainer();
063: try {
064: if (subscriptionFlowName != null
065: && !subscriptionFlowName.equals(flowName)) {
066: container
067: .getDefaultBroker()
068: .setFlows(
069: new Flow[] {
070: FlowProvider.getFlow(flowName),
071: FlowProvider
072: .getFlow(subscriptionFlowName) });
073: } else {
074: container.getDefaultBroker().setFlows(
075: new Flow[] { FlowProvider.getFlow(flowName) });
076: }
077: if (subscriptionFlowName != null) {
078: container.getDefaultBroker().getSubscriptionManager()
079: .setFlowName(subscriptionFlowName);
080: }
081: container.setEmbedded(true);
082: container.init();
083: container.start();
084:
085: Sender sender = new SenderComponent();
086: ActivationSpec senderActivationSpec = new ActivationSpec(
087: "sender", sender);
088: senderActivationSpec.setFailIfNoDestinationEndpoint(false);
089: container.activateComponent(senderActivationSpec);
090:
091: ReceiverListener receiver1 = new ReceiverListener();
092: container.activateComponent(createReceiverAS("receiver1",
093: receiver1));
094:
095: ReceiverListener receiver2 = new ReceiverListener();
096: container.activateComponent(createReceiverAS("receiver2",
097: receiver2));
098:
099: sender.sendMessages(1);
100:
101: Thread.sleep(100);
102:
103: assertFalse(receiver1.isPropertySetOnExchange());
104: assertFalse(receiver2.isPropertySetOnExchange());
105: assertFalse(receiver1.isPropertySetOnMessage());
106: assertFalse(receiver2.isPropertySetOnMessage());
107: } finally {
108: container.shutDown();
109: }
110: }
111:
112: private ActivationSpec createReceiverAS(String id, Object component) {
113: ActivationSpec as = new ActivationSpec(id, component);
114: SubscriptionSpec ss = new SubscriptionSpec();
115: ss.setService(SenderComponent.SERVICE);
116: as.setEndpoint(id);
117: as.setSubscriptions(new SubscriptionSpec[] { ss });
118: return as;
119: }
120:
121: public static class ReceiverListener extends ReceiverComponent {
122: private boolean propertySetOnExchange;
123:
124: private boolean propertySetOnMessage;
125:
126: public void onMessageExchange(MessageExchange exchange)
127: throws MessagingException {
128: propertySetOnExchange = exchange
129: .getProperty("testProperty") != null;
130: exchange.setProperty("testProperty", "foo");
131: NormalizedMessage in = exchange.getMessage("in");
132: propertySetOnMessage = in.getProperty("testProperty") != null;
133: in.setProperty("testProperty", "foo");
134: }
135:
136: public boolean isPropertySetOnExchange() {
137: return propertySetOnExchange;
138: }
139:
140: public boolean isPropertySetOnMessage() {
141: return propertySetOnMessage;
142: }
143: }
144: }
|