001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestExchangeFactory.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import java.net.URI;
032:
033: import javax.jbi.component.Component;
034: import javax.jbi.component.ComponentContext;
035:
036: import javax.jbi.messaging.MessageExchange;
037: import javax.jbi.messaging.InOnly;
038: import javax.jbi.messaging.InOptionalOut;
039: import javax.jbi.messaging.InOut;
040: import javax.jbi.messaging.RobustInOnly;
041:
042: import javax.jbi.servicedesc.ServiceEndpoint;
043:
044: import javax.xml.namespace.QName;
045:
046: import org.w3c.dom.Document;
047:
048: /**
049: * Tests for the TestExchangeFactory class
050: *
051: * @author Sun Microsystems, Inc.
052: */
053: public class TestExchangeFactory extends junit.framework.TestCase {
054: /** NMS impl */
055: private MessageService mMsgSvc;
056:
057: /** NMR Environment Context */
058: private NMRContext mContext;
059:
060: /** Exchange Factory */
061: private ExchangeFactory mFactory;
062:
063: /**
064: * The constructor for this testcase, forwards the test name to
065: * the jUnit TestCase base class.
066: * @param aTestName String with the name of this test.
067: */
068: public TestExchangeFactory(String aTestName) {
069: super (aTestName);
070:
071: mMsgSvc = new MessageService();
072: mFactory = new ExchangeFactory(mMsgSvc);
073: mContext = new NMRContext(mMsgSvc);
074: }
075:
076: /**
077: * Setup for the test. This creates the ComponentRegistry instance
078: * and other objects needed for the tests.
079: * @throws Exception when set up fails for any reason.
080: */
081: public void setUp() throws Exception {
082: super .setUp();
083:
084: mMsgSvc.initService(mContext);
085: mMsgSvc.startService();
086: }
087:
088: /**
089: * Cleanup for the test.
090: * @throws Exception when tearDown fails for any reason.
091: */
092: public void tearDown() throws Exception {
093: super .tearDown();
094:
095: mMsgSvc.stopService();
096: mContext.reset();
097:
098: }
099:
100: // ============================= test methods ================================
101:
102: /**
103: * Test to make sure the 4 standard URIs are good.
104: */
105: public void testCreateExchangeUriGood() throws Exception {
106: assertTrue(mFactory.createExchange(ExchangePattern.IN_ONLY
107: .getURI()) instanceof InOnly);
108:
109: assertTrue(mFactory.createExchange(ExchangePattern.IN_OUT
110: .getURI()) instanceof InOut);
111:
112: assertTrue(mFactory
113: .createExchange(ExchangePattern.ROBUST_IN_ONLY.getURI()) instanceof RobustInOnly);
114:
115: assertTrue(mFactory
116: .createExchange(ExchangePattern.IN_OPTIONAL_OUT
117: .getURI()) instanceof InOptionalOut);
118: }
119:
120: /**
121: * Factory which has been initialized with an interface should always
122: * set that value on created exchanges.
123: */
124: public void testCreateExchangeWithInterface() throws Exception {
125: QName interfaceName = new QName("boo");
126: ExchangeFactory iFactory;
127:
128: iFactory = ExchangeFactory.newInterfaceFactory(mMsgSvc,
129: interfaceName);
130:
131: assertEquals(iFactory.createExchange(
132: ExchangePattern.IN_ONLY.getURI()).getInterfaceName(),
133: interfaceName);
134: }
135:
136: /**
137: * Test WSDL 2.0 parsing.
138: */
139: public void testCreateExchangeFromWsdl20() throws Exception {
140: String id = "testcomp";
141: Component com;
142: ComponentContext ctx;
143: MessageExchange me;
144:
145: // create a component, add it to env, and get it's context object
146: com = new NMRComponent();
147: mContext.addComponentInstance(id, com);
148: ctx = mContext.getComponentContext(id);
149:
150: // activate an endpoint and create an exchange for one of its operations
151: ctx.activateEndpoint(WsdlDocument.STOCK_SERVICE_Q,
152: WsdlDocument.STOCK_ENDPOINT);
153: me = mFactory.createExchange(WsdlDocument.STOCK_SERVICE_Q,
154: WsdlDocument.STOCK_OPERATION_Q);
155:
156: assertTrue(me instanceof InOut);
157: }
158:
159: /**
160: * Test WSDL 1.1 parsing.
161: */
162: public void testCreateExchangeFromWsdl11() throws Exception {
163: String id = "testcomp";
164: Component com;
165: ComponentContext ctx;
166: MessageExchange me;
167:
168: // create a component, add it to env, and get it's context object
169: com = new NMRComponent(NMRComponent.WSDL_11);
170: mContext.addComponentInstance(id, com);
171: ctx = mContext.getComponentContext(id);
172:
173: // activate an endpoint and create an exchange for one of its operations
174: ctx.activateEndpoint(WsdlDocument.STOCK_SERVICE_Q,
175: WsdlDocument.STOCK_ENDPOINT);
176: me = mFactory.createExchange(WsdlDocument.STOCK_SERVICE_Q,
177: WsdlDocument.STOCK_OPERATION_Q);
178:
179: assertTrue(me instanceof InOut);
180: }
181:
182: /**
183: * Factory which has been initialized with an endpoint should always
184: * set that value on created exchanges.
185: */
186: public void testCreateExchangeWithEndpoint() throws Exception {
187: RegisteredEndpoint endpoint;
188: ExchangeFactory eFactory;
189:
190: endpoint = new InternalEndpoint(new QName("foo"), "bar", "la");
191: eFactory = ExchangeFactory
192: .newEndpointFactory(mMsgSvc, endpoint);
193:
194: assertEquals(eFactory.createExchange(
195: ExchangePattern.IN_OUT.getURI()).getEndpoint(),
196: endpoint);
197: }
198:
199: /**
200: * Test to make sure bogus URIs throw an exception
201: */
202: public void testCreateExchangeUriBad() throws Exception {
203: try {
204: // this line should throw an exception
205: mFactory.createExchange(new URI("inside-out-mep"));
206: // shouldn't get here
207: fail("able to create exchange with bogus uri");
208: } catch (Exception ex) {
209: // expected
210: }
211: }
212:
213: /**
214: * Test MEP factory method.
215: * @throws Exception if an unexpected error occurs
216: */
217: public void testCreateInOnlyExchange() throws Exception {
218: InOnly inOnly = mFactory.createInOnlyExchange();
219: }
220:
221: /**
222: * Test MEP factory method.
223: * @throws Exception if an unexpected error occurs
224: */
225: public void testCreateInOptionalOutExchange() throws Exception {
226: InOptionalOut inOptionalOut = mFactory
227: .createInOptionalOutExchange();
228: }
229:
230: /**
231: * Test MEP factory method.
232: * @throws Exception if an unexpected error occurs
233: */
234: public void testCreateInOutExchange() throws Exception {
235: InOut inOut = mFactory.createInOutExchange();
236: }
237:
238: /**
239: * Test MEP factory method.
240: * @throws Exception if an unexpected error occurs
241: */
242: public void testCreateRobustInOnlyExchange() throws Exception {
243: RobustInOnly robInOnly = mFactory.createRobustInOnlyExchange();
244: }
245:
246: }
|