0001: /*
0002: * BEGIN_HEADER - DO NOT EDIT
0003: *
0004: * The contents of this file are subject to the terms
0005: * of the Common Development and Distribution License
0006: * (the "License"). You may not use this file except
0007: * in compliance with the License.
0008: *
0009: * You can obtain a copy of the license at
0010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011: * See the License for the specific language governing
0012: * permissions and limitations under the License.
0013: *
0014: * When distributing Covered Code, include this CDDL
0015: * HEADER in each file and include the License file at
0016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017: * If applicable add the following below this CDDL HEADER,
0018: * with the fields enclosed by brackets "[]" replaced with
0019: * your own identifying information: Portions Copyright
0020: * [year] [name of copyright owner]
0021: */
0022:
0023: /*
0024: * @(#)TestInOnly.java
0025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026: *
0027: * END_HEADER - DO NOT EDIT
0028: */
0029: package com.sun.jbi.messaging;
0030:
0031: import com.sun.jbi.ComponentManager;
0032: import com.sun.jbi.ComponentState;
0033: import com.sun.jbi.ComponentType;
0034:
0035: import java.util.HashMap;
0036: import java.util.List;
0037:
0038: import javax.jbi.component.Component;
0039: import javax.jbi.messaging.ExchangeStatus;
0040: import javax.jbi.messaging.Fault;
0041: import javax.jbi.messaging.InOnly;
0042: import javax.jbi.messaging.MessageExchange;
0043: import javax.jbi.messaging.MessageExchangeFactory;
0044: import javax.jbi.messaging.NormalizedMessage;
0045:
0046: import javax.jbi.servicedesc.ServiceEndpoint;
0047:
0048: import javax.transaction.xa.XAResource;
0049: import javax.transaction.Transaction;
0050: import javax.transaction.TransactionManager;
0051:
0052: import javax.xml.namespace.QName;
0053:
0054: /**
0055: * Test InOnly Message Exchange.
0056: * @author Sun Microsystems, Inc.
0057: */
0058: public class TestInOnly extends junit.framework.TestCase {
0059: private static final QName SERVICE = new QName("InOnlyService");
0060: private static final String ENDPOINT = "InOnlyEndpoint";
0061: private static final QName OPERATION = new QName("foobar");
0062: private TransactionManager mTM;
0063: private FakeXAResource mXAR;
0064: private FakeXAResource mXAR2;
0065:
0066: private MessageService mMsgSvc;
0067: /** NMR Environment Context */
0068: private NMRContext mContext;
0069: private MessageExchangeFactory mFactory;
0070: private ComponentManagerImpl mCompMgr;
0071:
0072: /**
0073: * The constructor for this testcase, forwards the test name to
0074: * the jUnit TestCase base class.
0075: * @param aTestName String with the name of this test.
0076: */
0077: public TestInOnly(String aTestName) throws Exception {
0078: super (aTestName);
0079: mMsgSvc = new MessageService();
0080: mContext = new NMRContext(mMsgSvc);
0081: }
0082:
0083: /**
0084: * Setup for the test.
0085: * @throws Exception when set up fails for any reason.
0086: */
0087: public void setUp() throws Exception {
0088: super .setUp();
0089:
0090: mMsgSvc.initService(mContext);
0091: mMsgSvc.startService();
0092:
0093: mFactory = new ExchangeFactory(mMsgSvc);
0094:
0095: //
0096: // When running as a LifeCycleListener, one can use the Context that is
0097: // that is past at startup, cast it to the internal implementation:
0098: // ((com.sun.jbi.framework.EnvironmentContext)ctx).getTransactionManager();
0099: // NOTE: the TransactionManager isn't available at this early time, soyou have
0100: // save the ctx until after processing has started.
0101: //
0102: mTM = FakeTransactionManager.getTM();
0103: mMsgSvc.setTransactionManager(mTM);
0104: mXAR = new FakeXAResource();
0105: mXAR2 = new FakeXAResource();
0106:
0107: mCompMgr = new ComponentManagerImpl();
0108: mMsgSvc.setComponentManager(mCompMgr);
0109: }
0110:
0111: /**
0112: * Cleanup for the test.
0113: * @throws Exception when tearDown fails for any reason.
0114: */
0115: public void tearDown() throws Exception {
0116: super .tearDown();
0117:
0118: mMsgSvc.stopService();
0119: mContext.reset();
0120: }
0121:
0122: // ============================= test methods ================================
0123:
0124: /**
0125: * Happy path test for an InOnly exchange.
0126: * @throws Exception test failed
0127: */
0128: public void testExchangeGood() throws Exception {
0129: Binding binding;
0130: Engine engine;
0131:
0132: // Engine is provider, binding is consumer
0133:
0134: binding = new HappyBinding(mMsgSvc.activateChannel("binding",
0135: null));
0136: engine = new HappyEngine(mMsgSvc
0137: .activateChannel("engine", null));
0138:
0139: mCompMgr.addComponent("engine", engine);
0140:
0141: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0142: .toString());
0143: binding.init(SERVICE);
0144:
0145: Framework.runTest(binding, engine);
0146:
0147: // check for binding or engine failure
0148: binding.checkError();
0149: engine.checkError();
0150:
0151: binding.stop();
0152: engine.stop();
0153: }
0154:
0155: /**
0156: * Happy path test for an InOnly exchange.
0157: * @throws Exception test failed
0158: */
0159: public void testExchangeBindingSynch() throws Exception {
0160: Binding binding;
0161: Engine engine;
0162:
0163: // Engine is provider, binding is consumer
0164:
0165: binding = new HappySynchBinding(mMsgSvc.activateChannel(
0166: "binding", null));
0167: engine = new HappyEngine(mMsgSvc
0168: .activateChannel("engine", null));
0169:
0170: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0171: .toString());
0172: binding.init(SERVICE);
0173:
0174: Framework.runTest(binding, engine);
0175:
0176: // check for binding or engine failure
0177: binding.checkError();
0178: engine.checkError();
0179:
0180: binding.stop();
0181: engine.stop();
0182: }
0183:
0184: /**
0185: * Happy path test for an InOnly exchange.
0186: * @throws Exception test failed
0187: */
0188: public void testExchangeEngineSynch() throws Exception {
0189: Binding binding;
0190: Engine engine;
0191:
0192: // Engine is provider, binding is consumer
0193:
0194: binding = new HappyBinding(mMsgSvc.activateChannel("binding",
0195: null));
0196: engine = new HappySynchEngine(mMsgSvc.activateChannel("engine",
0197: null));
0198:
0199: mCompMgr.addComponent("engine", engine);
0200:
0201: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0202: .toString());
0203: binding.init(SERVICE);
0204:
0205: Framework.runTest(binding, engine);
0206:
0207: // check for binding or engine failure
0208: binding.checkError();
0209: engine.checkError();
0210:
0211: binding.stop();
0212: engine.stop();
0213: }
0214:
0215: /**
0216: * Happy path test for an InOnly exchange.
0217: * @throws Exception test failed
0218: */
0219: public void testExchangeBothSynch() throws Exception {
0220: Binding binding;
0221: Engine engine;
0222:
0223: // Engine is provider, binding is consumer
0224:
0225: binding = new HappySynchBinding(mMsgSvc.activateChannel(
0226: "binding", null));
0227: engine = new HappySynchEngine(mMsgSvc.activateChannel("engine",
0228: null));
0229:
0230: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0231: .toString());
0232: binding.init(SERVICE);
0233:
0234: Framework.runTest(binding, engine);
0235:
0236: // check for binding or engine failure
0237: binding.checkError();
0238: engine.checkError();
0239:
0240: binding.stop();
0241: engine.stop();
0242: }
0243:
0244: /**
0245: * Happy path test for an InOnly exchange.
0246: * @throws Exception test failed
0247: */
0248: public void testExchangeGoodTimeout() throws Exception {
0249: Binding binding;
0250: Engine engine;
0251:
0252: // Engine is provider, binding is consumer
0253:
0254: binding = new HappyTimeoutBinding(mMsgSvc.activateChannel(
0255: "binding", null));
0256: engine = new HappyTimeoutEngine(mMsgSvc.activateChannel(
0257: "engine", null));
0258:
0259: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0260: .toString());
0261: binding.init(SERVICE);
0262:
0263: Framework.runTest(binding, engine);
0264:
0265: // check for binding or engine failure
0266: binding.checkError();
0267: engine.checkError();
0268:
0269: binding.stop();
0270: engine.stop();
0271: }
0272:
0273: /**
0274: * Happy path test for an InOnly exchange.
0275: * @throws Exception test failed
0276: */
0277: public void testExchangeGoodSynchTimeout() throws Exception {
0278: Binding binding;
0279: Engine engine;
0280:
0281: // Engine is provider, binding is consumer
0282:
0283: binding = new HappySynchTimeoutBinding(mMsgSvc.activateChannel(
0284: "binding", null));
0285: engine = new HappyTimeoutEngine(mMsgSvc.activateChannel(
0286: "engine", null));
0287:
0288: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0289: .toString());
0290: binding.init(SERVICE);
0291:
0292: Framework.runTest(binding, engine);
0293:
0294: // check for binding or engine failure
0295: binding.checkError();
0296: engine.checkError();
0297:
0298: binding.stop();
0299: engine.stop();
0300: }
0301:
0302: /**
0303: * Happy path test for an InOnly exchange.
0304: * @throws Exception test failed
0305: */
0306: public void testExchangeBadSynchTimeout() throws Exception {
0307: Binding binding;
0308: Engine engine;
0309:
0310: // Engine is provider, binding is consumer
0311:
0312: binding = new BadSynchTimeoutBinding(mMsgSvc.activateChannel(
0313: "binding", null));
0314: engine = new BadTimeoutEngine(mMsgSvc.activateChannel("engine",
0315: null));
0316:
0317: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0318: .toString());
0319: binding.init(SERVICE);
0320:
0321: Framework.runTest(binding, engine);
0322:
0323: // check for binding or engine failure
0324: binding.checkError();
0325: engine.checkError();
0326:
0327: binding.stop();
0328: engine.stop();
0329: }
0330:
0331: /**
0332: * Attempt to do bad things with an InOnly exchange.
0333: * @throws Exception test failed
0334: */
0335: public void testExchangeFailure() throws Exception {
0336: Binding binding;
0337: Engine engine;
0338:
0339: // Engine is provider, binding is consumer
0340:
0341: binding = new HappyBinding(mMsgSvc.activateChannel("binding",
0342: null));
0343: engine = new BadEngine(mMsgSvc.activateChannel("engine", null));
0344:
0345: mCompMgr.addComponent("engine", engine);
0346:
0347: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0348: .toString());
0349: binding.init(SERVICE);
0350:
0351: Framework.runTest(binding, engine);
0352:
0353: // check for binding or engine failure
0354: binding.checkError();
0355: engine.checkError();
0356:
0357: binding.stop();
0358: engine.stop();
0359: }
0360:
0361: /**
0362: * Attempt to do bad things with an InOnly exchange.
0363: * @throws Exception test failed
0364: */
0365: public void testServiceEndpointFailure() throws Exception {
0366: Binding binding;
0367: Engine engine;
0368:
0369: // Engine is provider, binding is consumer
0370:
0371: binding = new BadServiceEndpointBinding(mMsgSvc
0372: .activateChannel("binding", null));
0373: engine = new HappyEngine(mMsgSvc
0374: .activateChannel("engine", null));
0375:
0376: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0377: .toString());
0378: binding.init(SERVICE);
0379:
0380: Framework.runTest(binding, engine);
0381:
0382: // check for binding or engine failure
0383: binding.checkError();
0384: engine.checkError();
0385:
0386: binding.stop();
0387: engine.stop();
0388: }
0389:
0390: /**
0391: * Attempt to do bad things with an OutOnly exchange.
0392: * @throws Exception test failed
0393: */
0394: public void testXactGood() throws Exception {
0395: Binding binding;
0396: Engine engine;
0397:
0398: binding = new XactBinding(mMsgSvc.activateChannel("binding",
0399: null));
0400: engine = new XactEngine(mMsgSvc.activateChannel("engine", null));
0401:
0402: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0403: .toString());
0404: binding.init(SERVICE);
0405:
0406: Framework.runTest(binding, engine);
0407:
0408: // check for binding or engine failure
0409: binding.checkError();
0410: engine.checkError();
0411:
0412: binding.stop();
0413: engine.stop();
0414: }
0415:
0416: /**
0417: * Attempt to do bad things with an OutOnly exchange.
0418: * @throws Exception test failed
0419: */
0420: public void testXactAbort() throws Exception {
0421: Binding binding;
0422: Engine engine;
0423:
0424: binding = new XactBindingAbort(mMsgSvc.activateChannel(
0425: "binding", null));
0426: engine = new XactEngine(mMsgSvc.activateChannel("engine", null));
0427:
0428: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0429: .toString());
0430: binding.init(SERVICE);
0431:
0432: Framework.runTest(binding, engine);
0433:
0434: // check for binding or engine failure
0435: binding.checkError();
0436: engine.checkError();
0437:
0438: binding.stop();
0439: engine.stop();
0440: }
0441:
0442: /**
0443: * Attempt to do bad things with an OutOnly exchange.
0444: * @throws Exception test failed
0445: */
0446: public void testTransactional() throws Exception {
0447: Binding binding;
0448: Engine engine;
0449:
0450: binding = new XactTransactionalBinding(mMsgSvc.activateChannel(
0451: "binding", null));
0452: engine = new XactTransactionalEngine(mMsgSvc.activateChannel(
0453: "engine", null));
0454:
0455: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0456: .toString());
0457: binding.init(SERVICE);
0458:
0459: Framework.runTest(binding, engine);
0460:
0461: // check for binding or engine failure
0462: binding.checkError();
0463: engine.checkError();
0464:
0465: binding.stop();
0466: engine.stop();
0467: }
0468:
0469: /**
0470: * Attempt to do bad things with an OutOnly exchange.
0471: * @throws Exception test failed
0472: */
0473: public void testAcceptorClose() throws Exception {
0474: Binding binding;
0475: Engine engine;
0476: Sequencer sequencer = new Sequencer();
0477:
0478: binding = new CloseBinding(mMsgSvc.activateChannel("binding",
0479: null));
0480: engine = new CloseEngine(mMsgSvc
0481: .activateChannel("engine", null));
0482:
0483: mCompMgr.addComponent("engine", engine);
0484:
0485: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0486: .toString());
0487: binding.init(SERVICE);
0488: engine.setSequencer(sequencer);
0489: binding.setSequencer(sequencer);
0490:
0491: Framework.runTest(binding, engine);
0492:
0493: // check for binding or engine failure
0494: binding.checkError();
0495: engine.checkError();
0496:
0497: binding.stop();
0498: engine.stop();
0499: }
0500:
0501: /**
0502: * Attempt to do bad things with an OutOnly exchange.
0503: * @throws Exception test failed
0504: */
0505: public void testSenderClose() throws Exception {
0506: Binding binding;
0507: Engine engine;
0508: Sequencer sequencer = new Sequencer();
0509:
0510: binding = new Close2Binding(mMsgSvc.activateChannel("binding",
0511: null));
0512: engine = new Close2Engine(mMsgSvc.activateChannel("engine",
0513: null));
0514:
0515: mCompMgr.addComponent("engine", engine);
0516:
0517: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0518: .toString());
0519: binding.init(SERVICE);
0520: engine.setSequencer(sequencer);
0521: binding.setSequencer(sequencer);
0522:
0523: Framework.runTest(binding, engine);
0524:
0525: // check for binding or engine failure
0526: binding.checkError();
0527: engine.checkError();
0528:
0529: binding.stop();
0530: engine.stop();
0531: }
0532:
0533: /**
0534: * Attempt to do bad things with an OutOnly exchange.
0535: * @throws Exception test failed
0536: */
0537: public void testsendSyncClose() throws Exception {
0538: Binding binding;
0539: Engine engine;
0540: Sequencer sequencer = new Sequencer();
0541:
0542: binding = new Close3Binding(mMsgSvc.activateChannel("binding",
0543: null));
0544: engine = new Close2Engine(mMsgSvc.activateChannel("engine",
0545: null));
0546:
0547: mCompMgr.addComponent("engine", engine);
0548:
0549: engine.init(SERVICE, ENDPOINT, ExchangePattern.IN_ONLY
0550: .toString());
0551: binding.init(SERVICE);
0552: engine.setSequencer(sequencer);
0553: binding.setSequencer(sequencer);
0554:
0555: Framework.runTest(binding, engine);
0556:
0557: // check for binding or engine failure
0558: binding.checkError();
0559: engine.checkError();
0560:
0561: binding.stop();
0562: engine.stop();
0563: }
0564:
0565: // ============================ internal stuff ================================
0566:
0567: class HappyBinding extends Binding {
0568: HappyBinding(DeliveryChannelImpl channel) {
0569: super (channel);
0570: }
0571:
0572: public void start() throws Exception {
0573: NormalizedMessage inMsg;
0574: InOnly inOnly;
0575:
0576: // create the exchange
0577: inOnly = mFactory.createInOnlyExchange();
0578: inMsg = inOnly.createMessage();
0579: assertEquals(inOnly.getPattern().toString(),
0580: ExchangePattern.IN_ONLY.toString());
0581: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0582: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0583: .getRole());
0584: assertEquals(mFactory.createExchange(SERVICE, OPERATION)
0585: .getPattern().toString(), ExchangePattern.IN_ONLY
0586: .toString());
0587:
0588: // set the stuff we know & check that they are set.
0589: inOnly.setEndpoint(mEndpoint);
0590: assertEquals(mEndpoint, inOnly.getEndpoint());
0591:
0592: inOnly.setOperation(OPERATION);
0593: assertEquals(OPERATION, inOnly.getOperation());
0594:
0595: // set the payload
0596: Payload.setPayload(inMsg);
0597:
0598: // set message on exchange
0599: inOnly.setInMessage(inMsg);
0600: assertEquals(inMsg, inOnly.getInMessage());
0601:
0602: // send the exchange
0603: mChannel.send(inOnly);
0604: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0605: .getRole());
0606:
0607: // Check that settings are ignored while ownership is elsewhere.
0608: inOnly.setEndpoint(null);
0609: assertEquals(mEndpoint, inOnly.getEndpoint());
0610:
0611: inOnly.setOperation(null);
0612: assertEquals(OPERATION, inOnly.getOperation());
0613:
0614: // receive the response
0615: inOnly = (InOnly) mChannel.accept();
0616:
0617: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
0618:
0619: // Check that settings are ignored when DONE.
0620:
0621: inOnly.setEndpoint(null);
0622: assertEquals(mEndpoint, inOnly.getEndpoint());
0623:
0624: inOnly.setOperation(null);
0625: assertEquals(OPERATION, inOnly.getOperation());
0626: }
0627: }
0628:
0629: class HappyTimeoutBinding extends Binding {
0630: HappyTimeoutBinding(DeliveryChannelImpl channel) {
0631: super (channel);
0632: }
0633:
0634: public void start() throws Exception {
0635: NormalizedMessage inMsg;
0636: InOnly inOnly;
0637:
0638: // create the exchange
0639: inOnly = mFactory.createInOnlyExchange();
0640: inMsg = inOnly.createMessage();
0641: assertEquals(inOnly.getPattern().toString(),
0642: ExchangePattern.IN_ONLY.toString());
0643: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0644:
0645: // set the stuff we know & check that they are set.
0646: inOnly.setEndpoint(mEndpoint);
0647: assertEquals(mEndpoint, inOnly.getEndpoint());
0648:
0649: inOnly.setOperation(OPERATION);
0650: assertEquals(OPERATION, inOnly.getOperation());
0651:
0652: // set the payload
0653: Payload.setPayload(inMsg);
0654:
0655: // set message on exchange
0656: inOnly.setInMessage(inMsg);
0657: assertEquals(inMsg, inOnly.getInMessage());
0658:
0659: // Delay to check accept timeout.
0660:
0661: synchronized (this ) {
0662: this .wait(1000);
0663: }
0664:
0665: // send the exchange
0666: mChannel.send(inOnly);
0667: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0668: .getRole());
0669:
0670: // Check that settings are ignored while ownership is elsewhere.
0671: inOnly.setEndpoint(null);
0672: assertEquals(mEndpoint, inOnly.getEndpoint());
0673:
0674: inOnly.setOperation(null);
0675: assertEquals(OPERATION, inOnly.getOperation());
0676:
0677: // receive the response
0678: inOnly = (InOnly) mChannel.accept();
0679:
0680: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
0681:
0682: // Check that settings are ignored when DONE.
0683:
0684: inOnly.setEndpoint(null);
0685: assertEquals(mEndpoint, inOnly.getEndpoint());
0686:
0687: inOnly.setOperation(null);
0688: assertEquals(OPERATION, inOnly.getOperation());
0689: }
0690: }
0691:
0692: class HappySynchBinding extends Binding {
0693: HappySynchBinding(DeliveryChannelImpl channel) {
0694: super (channel);
0695: }
0696:
0697: public void start() throws Exception {
0698: NormalizedMessage inMsg;
0699: InOnly inOnly;
0700:
0701: // create the exchange
0702: inOnly = mFactory.createInOnlyExchange();
0703: inMsg = inOnly.createMessage();
0704: assertEquals(inOnly.getPattern().toString(),
0705: ExchangePattern.IN_ONLY.toString());
0706: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0707:
0708: // set the stuff we know & check that they are set.
0709: inOnly.setEndpoint(mEndpoint);
0710: assertEquals(mEndpoint, inOnly.getEndpoint());
0711:
0712: inOnly.setOperation(OPERATION);
0713: assertEquals(OPERATION, inOnly.getOperation());
0714:
0715: // set the payload
0716: Payload.setPayload(inMsg);
0717:
0718: // set message on exchange
0719: inOnly.setInMessage(inMsg);
0720: assertEquals(inMsg, inOnly.getInMessage());
0721:
0722: // send the exchange and wait for response
0723: assertTrue(mChannel.sendSync(inOnly));
0724: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0725: .getRole());
0726:
0727: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
0728:
0729: // Check that settings are ignored when DONE.
0730:
0731: inOnly.setEndpoint(null);
0732: assertEquals(mEndpoint, inOnly.getEndpoint());
0733:
0734: inOnly.setOperation(null);
0735: assertEquals(OPERATION, inOnly.getOperation());
0736: }
0737: }
0738:
0739: class HappySynchTimeoutBinding extends Binding {
0740: HappySynchTimeoutBinding(DeliveryChannelImpl channel) {
0741: super (channel);
0742: }
0743:
0744: public void start() throws Exception {
0745: NormalizedMessage inMsg;
0746: InOnly inOnly;
0747:
0748: // create the exchange
0749: inOnly = mFactory.createInOnlyExchange();
0750: inMsg = inOnly.createMessage();
0751: assertEquals(inOnly.getPattern().toString(),
0752: ExchangePattern.IN_ONLY.toString());
0753: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0754:
0755: // set the stuff we know & check that they are set.
0756: inOnly.setEndpoint(mEndpoint);
0757: assertEquals(mEndpoint, inOnly.getEndpoint());
0758:
0759: inOnly.setOperation(OPERATION);
0760: assertEquals(OPERATION, inOnly.getOperation());
0761:
0762: // set the payload
0763: Payload.setPayload(inMsg);
0764:
0765: // set message on exchange
0766: inOnly.setInMessage(inMsg);
0767: assertEquals(inMsg, inOnly.getInMessage());
0768:
0769: // send the exchange and wait for response
0770: assertTrue(mChannel.sendSync(inOnly, 2000));
0771: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0772: .getRole());
0773: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
0774:
0775: // Check that settings are ignored when DONE.
0776:
0777: inOnly.setEndpoint(null);
0778: assertEquals(mEndpoint, inOnly.getEndpoint());
0779:
0780: inOnly.setOperation(null);
0781: assertEquals(OPERATION, inOnly.getOperation());
0782: }
0783: }
0784:
0785: class BadSynchTimeoutBinding extends Binding {
0786: BadSynchTimeoutBinding(DeliveryChannelImpl channel) {
0787: super (channel);
0788: }
0789:
0790: public void start() throws Exception {
0791: NormalizedMessage inMsg;
0792: InOnly inOnly;
0793:
0794: // create the exchange
0795: inOnly = mFactory.createInOnlyExchange();
0796: inMsg = inOnly.createMessage();
0797: assertEquals(inOnly.getPattern().toString(),
0798: ExchangePattern.IN_ONLY.toString());
0799: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0800:
0801: // set the stuff we know & check that they are set.
0802: inOnly.setEndpoint(mEndpoint);
0803: assertEquals(mEndpoint, inOnly.getEndpoint());
0804:
0805: inOnly.setOperation(OPERATION);
0806: assertEquals(OPERATION, inOnly.getOperation());
0807:
0808: // set the payload
0809: Payload.setPayload(inMsg);
0810:
0811: // set message on exchange
0812: inOnly.setInMessage(inMsg);
0813: assertEquals(inMsg, inOnly.getInMessage());
0814:
0815: // send the exchange and wait for response
0816: assertTrue(!mChannel.sendSync(inOnly, 500));
0817: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0818: .getRole());
0819:
0820: // Check that settings are ignored after ERROR.
0821:
0822: inOnly.setEndpoint(null);
0823: assertEquals(mEndpoint, inOnly.getEndpoint());
0824:
0825: inOnly.setOperation(null);
0826: assertEquals(OPERATION, inOnly.getOperation());
0827: }
0828: }
0829:
0830: class BadTimeoutBinding extends Binding {
0831: BadTimeoutBinding(DeliveryChannelImpl channel) {
0832: super (channel);
0833: }
0834:
0835: public void start() throws Exception {
0836: NormalizedMessage inMsg;
0837: InOnly inOnly;
0838:
0839: // create the exchange
0840: inOnly = mFactory.createInOnlyExchange();
0841: inMsg = inOnly.createMessage();
0842: assertEquals(inOnly.getPattern().toString(),
0843: ExchangePattern.IN_ONLY.toString());
0844: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0845:
0846: // set the stuff we know & check that they are set.
0847: inOnly.setEndpoint(mEndpoint);
0848: assertEquals(mEndpoint, inOnly.getEndpoint());
0849:
0850: inOnly.setOperation(OPERATION);
0851: assertEquals(OPERATION, inOnly.getOperation());
0852:
0853: // set the payload
0854: Payload.setPayload(inMsg);
0855:
0856: // set message on exchange
0857: inOnly.setInMessage(inMsg);
0858: assertEquals(inMsg, inOnly.getInMessage());
0859:
0860: // send the exchange
0861: mChannel.send(inOnly);
0862: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0863: .getRole());
0864:
0865: // Check that settings are ignored while ownership is elsewhere.
0866: inOnly.setEndpoint(null);
0867: assertEquals(mEndpoint, inOnly.getEndpoint());
0868:
0869: inOnly.setOperation(null);
0870: assertEquals(OPERATION, inOnly.getOperation());
0871:
0872: // receive the response
0873: inOnly = (InOnly) mChannel.accept(500);
0874: assertTrue(inOnly == null);
0875: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0876: .getRole());
0877: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0878:
0879: // Check that settings are ignored after ERROR.
0880:
0881: inOnly.setEndpoint(null);
0882: assertEquals(mEndpoint, inOnly.getEndpoint());
0883:
0884: inOnly.setOperation(null);
0885: assertEquals(OPERATION, inOnly.getOperation());
0886: }
0887: }
0888:
0889: class BadServiceEndpointBinding extends Binding {
0890: BadServiceEndpointBinding(DeliveryChannelImpl channel) {
0891: super (channel);
0892: }
0893:
0894: public void start() throws Exception {
0895: NormalizedMessage inMsg;
0896: InOnly inOnly;
0897:
0898: // create the exchange
0899: inOnly = mFactory.createInOnlyExchange();
0900: inMsg = inOnly.createMessage();
0901: assertEquals(inOnly.getPattern().toString(),
0902: ExchangePattern.IN_ONLY.toString());
0903: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0904: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0905: .getRole());
0906:
0907: inOnly.setOperation(OPERATION);
0908: assertEquals(OPERATION, inOnly.getOperation());
0909:
0910: // set the payload
0911: Payload.setPayload(inMsg);
0912:
0913: // set message on exchange
0914: inOnly.setInMessage(inMsg);
0915: assertEquals(inMsg, inOnly.getInMessage());
0916:
0917: // Try missing service/endpoint.
0918: try {
0919: mChannel.send(inOnly);
0920: setFailure("Expected exception for service/endpoint missing");
0921: } catch (javax.jbi.messaging.MessagingException mEx) {
0922:
0923: }
0924:
0925: // send the exchange
0926: inOnly.setEndpoint(mEndpoint);
0927: mChannel.send(inOnly);
0928: assertEquals(MessageExchange.Role.CONSUMER, inOnly
0929: .getRole());
0930:
0931: // Check that settings are ignored while ownership is elsewhere.
0932: inOnly.setEndpoint(null);
0933: assertEquals(mEndpoint, inOnly.getEndpoint());
0934:
0935: inOnly.setOperation(null);
0936: assertEquals(OPERATION, inOnly.getOperation());
0937:
0938: // receive the response
0939: inOnly = (InOnly) mChannel.accept();
0940:
0941: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
0942:
0943: // Check that settings are ignored when DONE.
0944:
0945: inOnly.setEndpoint(null);
0946: assertEquals(mEndpoint, inOnly.getEndpoint());
0947:
0948: inOnly.setOperation(null);
0949: assertEquals(OPERATION, inOnly.getOperation());
0950: }
0951: }
0952:
0953: class XactBinding extends Binding {
0954: XactBinding(DeliveryChannelImpl channel) {
0955: super (channel);
0956: }
0957:
0958: public void start() throws Exception {
0959: NormalizedMessage inMsg;
0960: InOnly inOnly;
0961: Transaction xact;
0962:
0963: // create the exchange
0964: inOnly = mFactory.createInOnlyExchange();
0965: inMsg = inOnly.createMessage();
0966: assertEquals(inOnly.getPattern().toString(),
0967: ExchangePattern.IN_ONLY.toString());
0968: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
0969:
0970: // set the stuff we know
0971: inOnly.setOperation(OPERATION);
0972:
0973: // lookup the endpoint reference and set on exchange
0974: inOnly.setEndpoint(mEndpoint);
0975: assertEquals(mEndpoint, inOnly.getEndpoint());
0976:
0977: // set the payload
0978: Payload.setPayload(inMsg);
0979:
0980: // set the message on the exchange
0981: inOnly.setInMessage(inMsg);
0982:
0983: // send the exchange
0984: mTM.begin();
0985: xact = mTM.getTransaction();
0986: xact.enlistResource(mXAR);
0987: inOnly
0988: .setProperty(
0989: MessageExchange.JTA_TRANSACTION_PROPERTY_NAME,
0990: xact);
0991: inMsg.setProperty("Value", new Integer(1234));
0992: mXAR.setValue(new Integer(1234));
0993: try {
0994: mChannel.send(inOnly);
0995: setFailure("Didn't throw exception for active transaction.");
0996: } catch (javax.jbi.JBIException jEx) {
0997: }
0998: mTM.suspend();
0999: mChannel.send(inOnly);
1000:
1001: // Check that settings are ignored while ownership is elsewhere.
1002:
1003: inOnly.setEndpoint(null);
1004: assertEquals(mEndpoint, inOnly.getEndpoint());
1005:
1006: inOnly.setOperation(null);
1007: assertEquals(OPERATION, inOnly.getOperation());
1008:
1009: // receive the response
1010: inOnly = (InOnly) mChannel.accept();
1011:
1012: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
1013:
1014: // Check that settings are ignored when DONE.
1015:
1016: inOnly.setEndpoint(null);
1017: assertEquals(mEndpoint, inOnly.getEndpoint());
1018:
1019: inOnly.setOperation(null);
1020: assertEquals(OPERATION, inOnly.getOperation());
1021:
1022: xact.delistResource(mXAR, XAResource.TMSUCCESS);
1023: xact.commit();
1024: assertEquals(mXAR.getValue(), mXAR2.getValue());
1025: assertEquals(1234, mXAR.getValue());
1026: }
1027: }
1028:
1029: class XactBindingAbort extends Binding {
1030: XactBindingAbort(DeliveryChannelImpl channel) {
1031: super (channel);
1032: }
1033:
1034: public void start() throws Exception {
1035: NormalizedMessage inMsg;
1036: InOnly inOnly;
1037: Transaction xact;
1038:
1039: // create the exchange
1040: inOnly = mFactory.createInOnlyExchange();
1041: inMsg = inOnly.createMessage();
1042: assertEquals(inOnly.getPattern().toString(),
1043: ExchangePattern.IN_ONLY.toString());
1044: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
1045:
1046: // set the stuff we know
1047: inOnly.setOperation(OPERATION);
1048:
1049: // lookup the endpoint reference and set on exchange
1050: inOnly.setEndpoint(mEndpoint);
1051: assertEquals(mEndpoint, inOnly.getEndpoint());
1052:
1053: // set the payload
1054: Payload.setPayload(inMsg);
1055:
1056: // set the message on the exchange
1057: inOnly.setInMessage(inMsg);
1058:
1059: // send the exchange
1060: mTM.begin();
1061: xact = mTM.getTransaction();
1062: xact.enlistResource(mXAR);
1063: inOnly
1064: .setProperty(
1065: MessageExchange.JTA_TRANSACTION_PROPERTY_NAME,
1066: xact);
1067: inMsg.setProperty("Value", new Integer(1234));
1068: mXAR.setValue(new Integer(1234));
1069: try {
1070: mChannel.send(inOnly);
1071: setFailure("Didn't throw exception for active transaction.");
1072: } catch (javax.jbi.JBIException jEx) {
1073: }
1074: mTM.suspend();
1075: mChannel.send(inOnly);
1076:
1077: // Check that settings are ignored while ownership is elsewhere.
1078:
1079: inOnly.setEndpoint(null);
1080: assertEquals(mEndpoint, inOnly.getEndpoint());
1081:
1082: inOnly.setOperation(null);
1083: assertEquals(OPERATION, inOnly.getOperation());
1084:
1085: // receive the response
1086: inOnly = (InOnly) mChannel.accept();
1087:
1088: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
1089:
1090: // Check that settings are ignored when DONE.
1091:
1092: inOnly.setEndpoint(null);
1093: assertEquals(mEndpoint, inOnly.getEndpoint());
1094:
1095: inOnly.setOperation(null);
1096: assertEquals(OPERATION, inOnly.getOperation());
1097:
1098: xact.delistResource(mXAR, XAResource.TMSUCCESS);
1099: xact.rollback();
1100: assertEquals(mXAR.getValue(), mXAR2.getValue());
1101: assertEquals(0, mXAR.getValue());
1102: }
1103: }
1104:
1105: class XactTransactionalBinding extends Binding {
1106: XactTransactionalBinding(DeliveryChannelImpl channel) {
1107: super (channel);
1108: }
1109:
1110: public void start() throws Exception {
1111: NormalizedMessage inMsg;
1112: InOnly inOnly;
1113: Transaction xact;
1114:
1115: // create the exchange
1116: inOnly = mFactory.createInOnlyExchange();
1117: inMsg = inOnly.createMessage();
1118: assertEquals(inOnly.getPattern().toString(),
1119: ExchangePattern.IN_ONLY.toString());
1120: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
1121:
1122: // set the stuff we know
1123: inOnly.setOperation(OPERATION);
1124:
1125: // lookup the endpoint reference and set on exchange
1126: inOnly.setEndpoint(mEndpoint);
1127: assertEquals(mEndpoint, inOnly.getEndpoint());
1128:
1129: // set the payload
1130: Payload.setPayload(inMsg);
1131:
1132: // set the message on the exchange
1133: inOnly.setInMessage(inMsg);
1134:
1135: // send the exchange
1136: mTM.begin();
1137: xact = mTM.getTransaction();
1138: xact.enlistResource(mXAR);
1139: inOnly
1140: .setProperty(
1141: MessageExchange.JTA_TRANSACTION_PROPERTY_NAME,
1142: xact);
1143: inMsg.setProperty("Value", new Integer(1234));
1144: mXAR.setValue(new Integer(1234));
1145: try {
1146: mChannel.send(inOnly);
1147: setFailure("Didn't throw exception for active transaction.");
1148: } catch (javax.jbi.JBIException jEx) {
1149: }
1150: mTM.suspend();
1151: mChannel.send(inOnly);
1152:
1153: // Check that settings are ignored while ownership is elsewhere.
1154:
1155: inOnly.setEndpoint(null);
1156: assertEquals(mEndpoint, inOnly.getEndpoint());
1157:
1158: inOnly.setOperation(null);
1159: assertEquals(OPERATION, inOnly.getOperation());
1160:
1161: // receive the response
1162: inOnly = (InOnly) mChannel.accept();
1163:
1164: assertEquals(ExchangeStatus.DONE, inOnly.getStatus());
1165:
1166: // Check that settings are ignored when DONE.
1167:
1168: inOnly.setEndpoint(null);
1169: assertEquals(mEndpoint, inOnly.getEndpoint());
1170:
1171: inOnly.setOperation(null);
1172: assertEquals(OPERATION, inOnly.getOperation());
1173: mTM.resume(xact);
1174: xact.delistResource(mXAR, XAResource.TMSUCCESS);
1175: xact.commit();
1176: assertEquals(0, mXAR2.getValue());
1177: assertEquals(1234, mXAR.getValue());
1178: }
1179: }
1180:
1181: class CloseBinding extends Binding {
1182: CloseBinding(DeliveryChannelImpl channel) {
1183: super (channel);
1184: }
1185:
1186: public void start() throws Exception {
1187: NormalizedMessage inMsg;
1188: InOnly inOnly;
1189:
1190: // create the exchange
1191: inOnly = mFactory.createInOnlyExchange();
1192: inMsg = inOnly.createMessage();
1193: assertEquals(inOnly.getPattern().toString(),
1194: ExchangePattern.IN_ONLY.toString());
1195: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
1196: assertEquals(MessageExchange.Role.CONSUMER, inOnly
1197: .getRole());
1198: assertEquals(mFactory.createExchange(SERVICE, OPERATION)
1199: .getPattern().toString(), ExchangePattern.IN_ONLY
1200: .toString());
1201:
1202: // set the stuff we know & check that they are set.
1203: inOnly.setEndpoint(mEndpoint);
1204: assertEquals(mEndpoint, inOnly.getEndpoint());
1205:
1206: inOnly.setOperation(OPERATION);
1207: assertEquals(OPERATION, inOnly.getOperation());
1208:
1209: // set the payload
1210: Payload.setPayload(inMsg);
1211:
1212: // set message on exchange
1213: inOnly.setInMessage(inMsg);
1214: assertEquals(inMsg, inOnly.getInMessage());
1215:
1216: // send the exchange
1217: mChannel.send(inOnly);
1218: assertEquals(MessageExchange.Role.CONSUMER, inOnly
1219: .getRole());
1220:
1221: mChannel.close();
1222:
1223: getSequencer().reached(1);
1224: }
1225: }
1226:
1227: class Close2Binding extends Binding {
1228: Close2Binding(DeliveryChannelImpl channel) {
1229: super (channel);
1230: }
1231:
1232: public void start() throws Exception {
1233: NormalizedMessage inMsg;
1234: InOnly inOnly;
1235:
1236: // create the exchange
1237: inOnly = mFactory.createInOnlyExchange();
1238: inMsg = inOnly.createMessage();
1239: assertEquals(inOnly.getPattern().toString(),
1240: ExchangePattern.IN_ONLY.toString());
1241: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
1242: assertEquals(MessageExchange.Role.CONSUMER, inOnly
1243: .getRole());
1244: assertEquals(mFactory.createExchange(SERVICE, OPERATION)
1245: .getPattern().toString(), ExchangePattern.IN_ONLY
1246: .toString());
1247:
1248: // set the stuff we know & check that they are set.
1249: inOnly.setEndpoint(mEndpoint);
1250: assertEquals(mEndpoint, inOnly.getEndpoint());
1251:
1252: inOnly.setOperation(OPERATION);
1253: assertEquals(OPERATION, inOnly.getOperation());
1254:
1255: // set the payload
1256: Payload.setPayload(inMsg);
1257:
1258: // set message on exchange
1259: inOnly.setInMessage(inMsg);
1260: assertEquals(inMsg, inOnly.getInMessage());
1261:
1262: // send the exchange
1263: mChannel.send(inOnly);
1264: assertEquals(MessageExchange.Role.CONSUMER, inOnly
1265: .getRole());
1266:
1267: getSequencer().stallUntil(1);
1268:
1269: // receive the response
1270: inOnly = (InOnly) mChannel.accept();
1271:
1272: assertEquals(ExchangeStatus.ERROR, inOnly.getStatus());
1273:
1274: // Check that settings are ignored when DONE.
1275:
1276: inOnly.setEndpoint(null);
1277: assertEquals(mEndpoint, inOnly.getEndpoint());
1278:
1279: inOnly.setOperation(null);
1280: assertEquals(OPERATION, inOnly.getOperation());
1281: }
1282: }
1283:
1284: class Close3Binding extends Binding {
1285: Close3Binding(DeliveryChannelImpl channel) {
1286: super (channel);
1287: }
1288:
1289: public void start() throws Exception {
1290: NormalizedMessage inMsg;
1291: InOnly inOnly;
1292:
1293: // create the exchange
1294: inOnly = mFactory.createInOnlyExchange();
1295: inMsg = inOnly.createMessage();
1296: assertEquals(inOnly.getPattern().toString(),
1297: ExchangePattern.IN_ONLY.toString());
1298: assertEquals(ExchangeStatus.ACTIVE, inOnly.getStatus());
1299: assertEquals(MessageExchange.Role.CONSUMER, inOnly
1300: .getRole());
1301: assertEquals(mFactory.createExchange(SERVICE, OPERATION)
1302: .getPattern().toString(), ExchangePattern.IN_ONLY
1303: .toString());
1304:
1305: // set the stuff we know & check that they are set.
1306: inOnly.setEndpoint(mEndpoint);
1307: assertEquals(mEndpoint, inOnly.getEndpoint());
1308:
1309: inOnly.setOperation(OPERATION);
1310: assertEquals(OPERATION, inOnly.getOperation());
1311:
1312: // set the payload
1313: Payload.setPayload(inMsg);
1314:
1315: // set message on exchange
1316: inOnly.setInMessage(inMsg);
1317: assertEquals(inMsg, inOnly.getInMessage());
1318:
1319: // send the exchange
1320: mChannel.sendSync(inOnly);
1321: }
1322: }
1323:
1324: class HappyEngine extends Engine {
1325: HappyEngine(DeliveryChannelImpl channel) {
1326: super (channel);
1327: }
1328:
1329: public void start() throws Exception {
1330: InOnly inOnly;
1331:
1332: inOnly = (InOnly) mChannel.accept();
1333: assertEquals(inOnly.getPattern().toString(),
1334: ExchangePattern.IN_ONLY.toString());
1335: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1336: .getRole());
1337: assertTrue(inOnly.getEndpoint() != null);
1338:
1339: // Check that settings are ignored after message is ACTIVE.
1340:
1341: inOnly.setEndpoint(null);
1342: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1343: inOnly.getEndpoint());
1344:
1345: inOnly.setOperation(null);
1346: assertNotSame("Allowed to set operation after ACTIVE",
1347: null, inOnly.getOperation());
1348:
1349: // verify out message is present
1350: if (inOnly.getInMessage() == null) {
1351: setFailure("In message is null!");
1352: return;
1353: }
1354:
1355: inOnly.setStatus(ExchangeStatus.DONE);
1356: mChannel.send(inOnly);
1357: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1358: .getRole());
1359:
1360: // Check that settings are ignored after message is DONE.
1361:
1362: inOnly.setEndpoint(null);
1363: assertNotSame("Allowed to set endpoint after done", null,
1364: inOnly.getEndpoint());
1365:
1366: inOnly.setOperation(null);
1367: assertNotSame("Allowed to set operation after done", null,
1368: inOnly.getOperation());
1369: }
1370: }
1371:
1372: class HappySynchEngine extends Engine {
1373: HappySynchEngine(DeliveryChannelImpl channel) {
1374: super (channel);
1375: }
1376:
1377: public void start() throws Exception {
1378: InOnly inOnly;
1379:
1380: inOnly = (InOnly) mChannel.accept();
1381: assertEquals(inOnly.getPattern().toString(),
1382: ExchangePattern.IN_ONLY.toString());
1383: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1384: .getRole());
1385: assertTrue(inOnly.getEndpoint() != null);
1386:
1387: // Check that settings are ignored after message is ACTIVE.
1388:
1389: inOnly.setEndpoint(null);
1390: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1391: inOnly.getEndpoint());
1392:
1393: inOnly.setOperation(null);
1394: assertNotSame("Allowed to set operation after ACTIVE",
1395: null, inOnly.getOperation());
1396:
1397: // verify out message is present
1398: if (inOnly.getInMessage() == null) {
1399: setFailure("In message is null!");
1400: return;
1401: }
1402:
1403: inOnly.setStatus(ExchangeStatus.DONE);
1404: try {
1405: mChannel.sendSync(inOnly);
1406: setFailure("Able to sendSync when not legal");
1407: } catch (Exception ex) {
1408: }
1409: ;
1410:
1411: mChannel.send(inOnly);
1412: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1413: .getRole());
1414: // Check that settings are ignored after message is DONE.
1415:
1416: inOnly.setEndpoint(null);
1417: assertNotSame("Allowed to set endpoint after done", null,
1418: inOnly.getEndpoint());
1419:
1420: inOnly.setOperation(null);
1421: assertNotSame("Allowed to set operation after done", null,
1422: inOnly.getOperation());
1423: }
1424: }
1425:
1426: class HappyTimeoutEngine extends Engine {
1427: HappyTimeoutEngine(DeliveryChannelImpl channel) {
1428: super (channel);
1429: }
1430:
1431: public void start() throws Exception {
1432: InOnly inOnly;
1433:
1434: inOnly = (InOnly) mChannel.accept();
1435: assertEquals(inOnly.getPattern().toString(),
1436: ExchangePattern.IN_ONLY.toString());
1437: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1438: .getRole());
1439: assertTrue(inOnly.getEndpoint() != null);
1440:
1441: // Check that settings are ignored after message is ACTIVE.
1442:
1443: inOnly.setEndpoint(null);
1444: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1445: inOnly.getEndpoint());
1446:
1447: inOnly.setOperation(null);
1448: assertNotSame("Allowed to set operation after ACTIVE",
1449: null, inOnly.getOperation());
1450:
1451: // verify out message is present
1452: if (inOnly.getInMessage() == null) {
1453: setFailure("In message is null!");
1454: return;
1455: }
1456:
1457: // Delay to help force timeouts.
1458: synchronized (this ) {
1459: this .wait(1000);
1460: }
1461:
1462: inOnly.setStatus(ExchangeStatus.DONE);
1463: mChannel.send(inOnly);
1464: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1465: .getRole());
1466:
1467: // Check that settings are ignored after message is DONE.
1468:
1469: inOnly.setEndpoint(null);
1470: assertNotSame("Allowed to set endpoint after done", null,
1471: inOnly.getEndpoint());
1472:
1473: inOnly.setOperation(null);
1474: assertNotSame("Allowed to set operation after done", null,
1475: inOnly.getOperation());
1476: }
1477: }
1478:
1479: class XactEngine extends Engine {
1480: XactEngine(DeliveryChannelImpl channel) {
1481: super (channel);
1482: }
1483:
1484: public void start() throws Exception {
1485: InOnly inOnly;
1486: Transaction xact;
1487: NormalizedMessage inMsg;
1488:
1489: inOnly = (InOnly) mChannel.accept();
1490: assertEquals(inOnly.getPattern().toString(),
1491: ExchangePattern.IN_ONLY.toString());
1492: assertTrue(inOnly.getEndpoint() != null);
1493:
1494: // Check that settings are ignored after message is ACTIVE.
1495:
1496: inOnly.setEndpoint(null);
1497: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1498: inOnly.getEndpoint());
1499:
1500: inOnly.setOperation(null);
1501: assertNotSame("Allowed to set operation after ACTIVE",
1502: null, inOnly.getOperation());
1503:
1504: // verify out message is present
1505: if ((inMsg = inOnly.getInMessage()) == null) {
1506: setFailure("In message is null!");
1507: return;
1508: }
1509:
1510: xact = (Transaction) inOnly
1511: .getProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
1512: assertNotSame("XACT shouldn't be null", null, xact);
1513: xact.enlistResource(mXAR2);
1514: mXAR2.setValue((Integer) inMsg.getProperty("Value"));
1515: xact.delistResource(mXAR2, XAResource.TMSUCCESS);
1516: inOnly.setStatus(ExchangeStatus.DONE);
1517: mChannel.send(inOnly);
1518:
1519: // Check that settings are ignored after message is DONE.
1520:
1521: inOnly.setEndpoint(null);
1522: assertNotSame("Allowed to set endpoint after done", null,
1523: inOnly.getEndpoint());
1524:
1525: inOnly.setOperation(null);
1526: assertNotSame("Allowed to set operation after done", null,
1527: inOnly.getOperation());
1528:
1529: }
1530: }
1531:
1532: class XactTransactionalEngine extends Engine {
1533: XactTransactionalEngine(DeliveryChannelImpl channel) {
1534: super (channel);
1535: }
1536:
1537: public void start() throws Exception {
1538: InOnly inOnly;
1539: Transaction xact;
1540: NormalizedMessage inMsg;
1541:
1542: inOnly = (InOnly) mChannel.accept();
1543: assertEquals(inOnly.getPattern().toString(),
1544: ExchangePattern.IN_ONLY.toString());
1545: assertTrue(inOnly.getEndpoint() != null);
1546:
1547: // Check that settings are ignored after message is ACTIVE.
1548:
1549: inOnly.setEndpoint(null);
1550: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1551: inOnly.getEndpoint());
1552:
1553: inOnly.setOperation(null);
1554: assertNotSame("Allowed to set operation after ACTIVE",
1555: null, inOnly.getOperation());
1556:
1557: // verify out message is present
1558: if ((inMsg = inOnly.getInMessage()) == null) {
1559: setFailure("In message is null!");
1560: return;
1561: }
1562:
1563: xact = (Transaction) inOnly
1564: .getProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME);
1565: assertNotSame("XACT should be null", null, xact);
1566: inOnly.setStatus(ExchangeStatus.DONE);
1567: mChannel.send(inOnly);
1568:
1569: // Check that settings are ignored after message is DONE.
1570:
1571: inOnly.setEndpoint(null);
1572: assertNotSame("Allowed to set endpoint after done", null,
1573: inOnly.getEndpoint());
1574:
1575: inOnly.setOperation(null);
1576: assertNotSame("Allowed to set operation after done", null,
1577: inOnly.getOperation());
1578:
1579: }
1580: }
1581:
1582: class BadTimeoutEngine extends Engine {
1583: BadTimeoutEngine(DeliveryChannelImpl channel) {
1584: super (channel);
1585: }
1586:
1587: public void start() throws Exception {
1588: InOnly inOnly;
1589:
1590: inOnly = (InOnly) mChannel.accept();
1591: assertEquals(inOnly.getPattern().toString(),
1592: ExchangePattern.IN_ONLY.toString());
1593: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1594: .getRole());
1595: assertTrue(inOnly.getEndpoint() != null);
1596:
1597: // Check that settings are ignored after message is ACTIVE.
1598:
1599: inOnly.setEndpoint(null);
1600: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1601: inOnly.getEndpoint());
1602:
1603: inOnly.setOperation(null);
1604: assertNotSame("Allowed to set operation after ACTIVE",
1605: null, inOnly.getOperation());
1606:
1607: // verify out message is present
1608: if (inOnly.getInMessage() == null) {
1609: setFailure("In message is null!");
1610: return;
1611: }
1612:
1613: // Delay to help force timeouts.
1614: synchronized (this ) {
1615: this .wait(1000);
1616: }
1617:
1618: try {
1619: inOnly.setStatus(ExchangeStatus.DONE);
1620: setFailure("Can set status after a timeout");
1621: } catch (Exception e) {
1622: }
1623:
1624: try {
1625: mChannel.send(inOnly);
1626: setFailure("Can send after timeout.");
1627: } catch (javax.jbi.messaging.MessagingException e) {
1628: }
1629: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1630: .getRole());
1631:
1632: // Check that settings are ignored after message is DONE.
1633:
1634: inOnly.setEndpoint(null);
1635: assertNotSame("Allowed to set endpoint after done", null,
1636: inOnly.getEndpoint());
1637:
1638: inOnly.setOperation(null);
1639: assertNotSame("Allowed to set operation after done", null,
1640: inOnly.getOperation());
1641: }
1642: }
1643:
1644: class BadEngine extends Engine {
1645: BadEngine(DeliveryChannelImpl channel) {
1646: super (channel);
1647: }
1648:
1649: public void start() throws Exception {
1650: InOnly inOnly;
1651: Fault fault;
1652: NormalizedMessage msg;
1653:
1654: inOnly = (InOnly) mChannel.accept();
1655: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1656: .getRole());
1657: assertTrue(inOnly.getEndpoint() != null);
1658:
1659: // Try to create a fault
1660: try {
1661: fault = inOnly.createFault();
1662: setFailure("Able to create fault on InOnly exchange");
1663: return;
1664: } catch (Exception ex1) {
1665: }
1666: ;
1667:
1668: // Try to set a fault
1669: try {
1670: inOnly.setFault(null);
1671: setFailure("Able to set a fault on InOnly exchange");
1672: return;
1673: } catch (Exception ex1) {
1674: }
1675: ;
1676:
1677: // Try to set in message from engine
1678: try {
1679: msg = inOnly.createMessage();
1680: inOnly.setInMessage(msg);
1681: setFailure("Able to set in message from engine");
1682: return;
1683: } catch (Exception ex1) {
1684: }
1685: ;
1686:
1687: // complete the exchange normally
1688: inOnly.setStatus(ExchangeStatus.DONE);
1689: mChannel.send(inOnly);
1690: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1691: .getRole());
1692:
1693: // Try to set in after DONE.
1694: try {
1695: msg = inOnly.createMessage();
1696: inOnly.setInMessage(msg);
1697: setFailure("Able to set in message from engine");
1698: return;
1699: } catch (Exception ex1) {
1700: }
1701: ;
1702: }
1703: }
1704:
1705: class CloseEngine extends Engine {
1706: CloseEngine(DeliveryChannelImpl channel) {
1707: super (channel);
1708: }
1709:
1710: public void start() throws Exception {
1711: InOnly inOnly;
1712:
1713: inOnly = (InOnly) mChannel.accept();
1714: assertEquals(inOnly.getPattern().toString(),
1715: ExchangePattern.IN_ONLY.toString());
1716: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1717: .getRole());
1718: assertTrue(inOnly.getEndpoint() != null);
1719:
1720: // Check that settings are ignored after message is ACTIVE.
1721:
1722: inOnly.setEndpoint(null);
1723: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1724: inOnly.getEndpoint());
1725:
1726: inOnly.setOperation(null);
1727: assertNotSame("Allowed to set operation after ACTIVE",
1728: null, inOnly.getOperation());
1729:
1730: // verify out message is present
1731: if (inOnly.getInMessage() == null) {
1732: setFailure("In message is null!");
1733: return;
1734: }
1735:
1736: getSequencer().stallUntil(1);
1737:
1738: try {
1739: inOnly.setStatus(ExchangeStatus.DONE);
1740: setFailure("Can set status after a timeout");
1741: } catch (Exception e) {
1742: }
1743:
1744: try {
1745: mChannel.send(inOnly);
1746: setFailure("Send didn't get error for closed channel");
1747: } catch (javax.jbi.messaging.MessagingException mEx) {
1748: }
1749: }
1750: }
1751:
1752: class Close2Engine extends Engine {
1753: Close2Engine(DeliveryChannelImpl channel) {
1754: super (channel);
1755: }
1756:
1757: public void start() throws Exception {
1758: InOnly inOnly;
1759:
1760: inOnly = (InOnly) mChannel.accept();
1761: assertEquals(inOnly.getPattern().toString(),
1762: ExchangePattern.IN_ONLY.toString());
1763: assertEquals(MessageExchange.Role.PROVIDER, inOnly
1764: .getRole());
1765: assertTrue(inOnly.getEndpoint() != null);
1766:
1767: // Check that settings are ignored after message is ACTIVE.
1768:
1769: inOnly.setEndpoint(null);
1770: assertNotSame("Allowed to set endpoint after ACTIVE", null,
1771: inOnly.getEndpoint());
1772:
1773: inOnly.setOperation(null);
1774: assertNotSame("Allowed to set operation after ACTIVE",
1775: null, inOnly.getOperation());
1776:
1777: // verify out message is present
1778: if (inOnly.getInMessage() == null) {
1779: setFailure("In message is null!");
1780: return;
1781: }
1782:
1783: mChannel.close();
1784:
1785: getSequencer().reached(1);
1786: }
1787: }
1788:
1789: class ComponentManagerImpl implements com.sun.jbi.ComponentManager {
1790: private HashMap mComponentMap = new HashMap();
1791:
1792: public void installSharedLibrary(String name,
1793: String description, String componentRoot,
1794: boolean isSelfFirst, List elements)
1795: throws javax.jbi.JBIException {
1796:
1797: }
1798:
1799: public javax.management.ObjectName loadBootstrap(
1800: com.sun.jbi.component.InstallationContext installContext,
1801: String bootClassName, List bootClassPathElements,
1802: List sharedLibraryList) throws javax.jbi.JBIException {
1803: return null;
1804: }
1805:
1806: public void uninstallSharedLibrary(String id)
1807: throws javax.jbi.JBIException {
1808:
1809: }
1810:
1811: public void unloadBootstrap(String componentName)
1812: throws javax.jbi.JBIException {
1813:
1814: }
1815:
1816: public javax.jbi.component.Component getComponentInstance(
1817: String str) {
1818: return (Component) mComponentMap.get(str);
1819: }
1820:
1821: /**
1822: * Get the com.sun.jbi.framework.DeployerMBean instance.
1823: * @param name - the unique name of the component.
1824: * @return The instance for the requested component or null if the
1825: * component is not registered or not active.
1826: */
1827: public com.sun.jbi.framework.DeployerMBean getDeployerInstance(
1828: String name) {
1829: return null;
1830: }
1831:
1832: public java.util.List getDependentComponentIds(String str) {
1833: return null;
1834: }
1835:
1836: public void addComponent(String componentId, Component c) {
1837: mComponentMap.put(componentId, c);
1838: }
1839:
1840: public void cancelComponentUpdate(String componentName)
1841: throws javax.jbi.JBIException {
1842: }
1843:
1844: public void updateComponent(
1845: com.sun.jbi.component.InstallationContext installContext,
1846: List bootClassPathElements)
1847: throws javax.jbi.JBIException {
1848: }
1849:
1850: public void validateComponentForUpdate(
1851: com.sun.jbi.component.InstallationContext installContext,
1852: List bootClassPathElements)
1853: throws javax.jbi.JBIException {
1854: }
1855:
1856: public void cancelComponentUpgrade(String componentName)
1857: throws javax.jbi.JBIException {
1858: }
1859:
1860: public void upgradeComponent(
1861: com.sun.jbi.component.InstallationContext installContext,
1862: String bootClassName, List bootClassPathElements,
1863: List sharedLibraryNames) throws javax.jbi.JBIException {
1864: }
1865:
1866: public boolean validateComponentForUpgrade(
1867: com.sun.jbi.component.InstallationContext installContext,
1868: String bootClassName, List bootClassPathElements,
1869: List sharedLibraryNames) throws javax.jbi.JBIException {
1870: return false;
1871: }
1872: }
1873: }
|