KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > messaging > MessageExchangeDecoratorTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: MessageExchangeDecoratorTest.java 11:40:23 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.messaging;
23
24 import java.lang.reflect.Method JavaDoc;
25
26 import javax.jbi.messaging.ExchangeStatus;
27 import javax.jbi.messaging.MessageExchange;
28 import javax.jbi.messaging.MessagingException;
29 import javax.jbi.messaging.MessageExchange.Role;
30 import javax.jbi.servicedesc.ServiceEndpoint;
31 import javax.xml.namespace.QName JavaDoc;
32
33 import junit.framework.TestCase;
34
35 import org.easymock.classextension.EasyMock;
36 import org.objectweb.petals.jbi.registry.InternalEndpoint;
37
38 /**
39  * Test of the MessageExchangeDecorator
40  *
41  * @author ddesjardins - eBMWebsourcing
42  */

43 public class MessageExchangeDecoratorTest extends TestCase {
44
45     private MessageExchangeDecorator messageExchangeDecorator;
46
47     public void setUp() throws MessagingException {
48         MessageExchangeImpl me = new MessageExchangeImpl(null);
49         me.setExchangeId("test01");
50         me.setOperation(new QName JavaDoc("operationname"));
51         me.setService(new QName JavaDoc("servicename"));
52         me.setInterfaceName(new QName JavaDoc("interfacename"));
53         me.setStatus(ExchangeStatus.ERROR);
54         me.setEndpoint(new InternalEndpoint(new QName JavaDoc("servicename"),
55             "endpoint", "compo", null, null));
56         me.setError(new RuntimeException JavaDoc("test"));
57         me.setProperty("test", "value");
58         messageExchangeDecorator = new MessageExchangeDecorator(me,
59             Role.CONSUMER);
60     }
61
62     public void testCreateFault() throws MessagingException {
63         assertNotNull(messageExchangeDecorator.createFault());
64     }
65
66     public void testCreateMessage() throws MessagingException {
67         assertNotNull(messageExchangeDecorator.createMessage());
68     }
69
70     public void testGetEndpoint() {
71         ServiceEndpoint endpoint = messageExchangeDecorator.getEndpoint();
72         assertEquals(endpoint.getServiceName(), new QName JavaDoc("servicename"));
73     }
74
75     public void testGetError() {
76         Exception JavaDoc exception = messageExchangeDecorator.getError();
77         assertEquals(exception.getMessage(), "test");
78     }
79
80     public void testGetError1() {
81         messageExchangeDecorator.setError(new RuntimeException JavaDoc("test1"));
82         Exception JavaDoc exception = messageExchangeDecorator.getError();
83         assertEquals(exception.getMessage(), "test1");
84     }
85
86     public void testGetExchangeId() {
87         assertEquals(messageExchangeDecorator.getExchangeId(), "test01");
88     }
89
90     public void testGetProperty() {
91         assertEquals(messageExchangeDecorator.getProperty("test"), "value");
92     }
93
94     public void testGetProperty1() {
95         messageExchangeDecorator.setProperty("test1", "value");
96         assertEquals(messageExchangeDecorator.getProperty("test1"), "value");
97     }
98
99     public void testGetPropertyNames() {
100         assertEquals(messageExchangeDecorator.getPropertyNames().iterator()
101             .next(), "test");
102     }
103
104     public void testGetInterfaceName1() {
105         messageExchangeDecorator.setInterfaceName(new QName JavaDoc("interfacename1"));
106         assertEquals(messageExchangeDecorator.getInterfaceName(), new QName JavaDoc(
107             "interfacename1"));
108     }
109
110     public void testGetInterfaceName() {
111         assertEquals(messageExchangeDecorator.getInterfaceName(), new QName JavaDoc(
112             "interfacename"));
113     }
114
115     public void testGetOperation() {
116         assertEquals(messageExchangeDecorator.getOperation(), new QName JavaDoc(
117             "operationname"));
118     }
119
120     public void testGetOperation1() {
121         messageExchangeDecorator.setOperation(new QName JavaDoc("operationname1"));
122         assertEquals(messageExchangeDecorator.getOperation(), new QName JavaDoc(
123             "operationname1"));
124     }
125
126     public void testGetService() {
127         assertEquals(messageExchangeDecorator.getService(), new QName JavaDoc(
128             "servicename"));
129     }
130
131     public void testGetService1() {
132         messageExchangeDecorator.setService(new QName JavaDoc("servicename1"));
133         assertEquals(messageExchangeDecorator.getService(), new QName JavaDoc(
134             "servicename1"));
135     }
136
137     public void testGetStatus() {
138         assertEquals(messageExchangeDecorator.getStatus(), ExchangeStatus.ERROR);
139     }
140
141     public void testGetStatus1() throws MessagingException {
142         messageExchangeDecorator.setStatus(ExchangeStatus.DONE);
143         assertEquals(messageExchangeDecorator.getStatus(), ExchangeStatus.DONE);
144     }
145
146     public void testGetFault() throws SecurityException JavaDoc, NoSuchMethodException JavaDoc {
147         MessageExchangeDecorator messageExchangeDecorator = EasyMock
148             .createMock(MessageExchangeDecorator.class,
149                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
150                     "checkComponentOwnsExchange", new Class JavaDoc[0])});
151         MessageExchangeImpl messageExchangeImpl = EasyMock
152             .createMock(MessageExchangeImpl.class);
153         FaultImpl faultImpl = EasyMock.createMock(FaultImpl.class);
154
155         messageExchangeDecorator.checkComponentOwnsExchange();
156         EasyMock.expect(messageExchangeImpl.getFault()).andReturn(faultImpl);
157
158         EasyMock.replay(messageExchangeDecorator);
159         EasyMock.replay(faultImpl);
160         EasyMock.replay(messageExchangeImpl);
161
162         messageExchangeDecorator.messageExchange = messageExchangeImpl;
163
164         assertEquals(messageExchangeDecorator.getFault(), faultImpl);
165     }
166
167     public void testGetMessageExchange() {
168         MessageExchangeImpl messageExchangeImpl = EasyMock
169             .createMock(MessageExchangeImpl.class);
170
171         EasyMock.replay(messageExchangeImpl);
172         messageExchangeDecorator.messageExchange = messageExchangeImpl;
173
174         assertEquals(messageExchangeDecorator.getMessageExchange(),
175             messageExchangeImpl);
176     }
177
178     public void testGetObserverRole() {
179         messageExchangeDecorator.observerRole = MessageExchange.Role.CONSUMER;
180         assertEquals(messageExchangeDecorator.getObserverRole(),
181             MessageExchange.Role.CONSUMER);
182     }
183
184     public void testGetRole() throws SecurityException JavaDoc, NoSuchMethodException JavaDoc {
185         MessageExchangeDecorator messageExchangeDecorator = EasyMock
186             .createMock(MessageExchangeDecorator.class,
187                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
188                     "checkComponentOwnsExchange", new Class JavaDoc[0])});
189         MessageExchangeImpl messageExchangeImpl = EasyMock
190             .createMock(MessageExchangeImpl.class);
191
192         EasyMock.expect(messageExchangeImpl.getRole()).andReturn(
193             MessageExchange.Role.PROVIDER);
194         messageExchangeDecorator.checkComponentOwnsExchange();
195
196         EasyMock.replay(messageExchangeDecorator);
197         EasyMock.replay(messageExchangeImpl);
198
199         messageExchangeDecorator.messageExchange = messageExchangeImpl;
200
201         assertEquals(messageExchangeDecorator.getRole(),
202             MessageExchange.Role.PROVIDER);
203     }
204
205     public void testIsTransacted() throws SecurityException JavaDoc,
206         NoSuchMethodException JavaDoc {
207         MessageExchangeDecorator messageExchangeDecorator = EasyMock
208             .createMock(MessageExchangeDecorator.class,
209                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
210                     "checkComponentOwnsExchange", new Class JavaDoc[0])});
211         MessageExchangeImpl messageExchangeImpl = EasyMock
212             .createMock(MessageExchangeImpl.class);
213
214         EasyMock.expect(messageExchangeImpl.isTransacted()).andReturn(true);
215         messageExchangeDecorator.checkComponentOwnsExchange();
216
217         EasyMock.replay(messageExchangeDecorator);
218         EasyMock.replay(messageExchangeImpl);
219
220         messageExchangeDecorator.messageExchange = messageExchangeImpl;
221
222         assertEquals(messageExchangeDecorator.isTransacted(), true);
223     }
224
225     public void testSetEndpoint() throws SecurityException JavaDoc,
226         NoSuchMethodException JavaDoc {
227         MessageExchangeDecorator messageExchangeDecorator = EasyMock
228             .createMock(MessageExchangeDecorator.class,
229                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
230                     "checkComponentOwnsExchange", new Class JavaDoc[0])});
231         MessageExchangeImpl messageExchangeImpl = EasyMock
232             .createMock(MessageExchangeImpl.class);
233         ServiceEndpoint serviceEndpoint = EasyMock
234             .createMock(ServiceEndpoint.class);
235
236         messageExchangeDecorator.checkComponentOwnsExchange();
237         messageExchangeImpl.setEndpoint(serviceEndpoint);
238
239         EasyMock.replay(messageExchangeDecorator);
240         EasyMock.replay(messageExchangeImpl);
241
242         messageExchangeDecorator.messageExchange = messageExchangeImpl;
243
244         messageExchangeDecorator.setEndpoint(serviceEndpoint);
245     }
246
247     public void testSetFault() throws SecurityException JavaDoc, NoSuchMethodException JavaDoc,
248         MessagingException {
249         MessageExchangeDecorator messageExchangeDecorator = EasyMock
250             .createMock(MessageExchangeDecorator.class,
251                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
252                     "checkComponentOwnsExchange", new Class JavaDoc[0])});
253         MessageExchangeImpl messageExchangeImpl = EasyMock
254             .createMock(MessageExchangeImpl.class);
255         FaultImpl faultImpl = EasyMock.createMock(FaultImpl.class);
256
257         messageExchangeDecorator.checkComponentOwnsExchange();
258         messageExchangeImpl.setFault(faultImpl);
259
260         EasyMock.replay(messageExchangeDecorator);
261         EasyMock.replay(messageExchangeImpl);
262
263         messageExchangeDecorator.messageExchange = messageExchangeImpl;
264
265         messageExchangeDecorator.setFault(faultImpl);
266     }
267
268     public void testSetWaitingOnSynchronousSend() {
269         messageExchangeDecorator.setWaitingOnSynchronousSend(true);
270         assertTrue(messageExchangeDecorator.waitingOnSynchronousSend);
271     }
272
273     public void testSetMessageExchange() {
274         MessageExchangeImpl messageExchangeImpl = EasyMock
275             .createMock(MessageExchangeImpl.class);
276
277         messageExchangeDecorator.setMessageExchange(messageExchangeImpl);
278
279         assertEquals(messageExchangeImpl,
280             messageExchangeDecorator.messageExchange);
281     }
282
283     public void testCheckComponentOwnsExchangeException() throws SecurityException JavaDoc,
284         NoSuchMethodException JavaDoc {
285         MessageExchangeDecorator messageExchangeDecorator = EasyMock
286             .createMock(MessageExchangeDecorator.class,
287                 new Method JavaDoc[] {MessageExchangeDecorator.class.getDeclaredMethod(
288                     "hasOwnership", new Class JavaDoc[0])});
289
290         EasyMock.expect(messageExchangeDecorator.hasOwnership()).andReturn(
291             false);
292
293         EasyMock.replay(messageExchangeDecorator);
294
295         try {
296             messageExchangeDecorator.checkComponentOwnsExchange();
297             fail();
298         } catch (Exception JavaDoc e) {
299             // do nothing
300
}
301     }
302 }
303
Popular Tags