KickJava   Java API By Example, From Geeks To Geeks.

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


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: MessageExchangeFactoryImplTest.java 11:21:38 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.messaging;
23
24 import java.net.URI JavaDoc;
25
26 import javax.jbi.messaging.MessageExchange;
27 import javax.jbi.messaging.MessagingException;
28 import javax.jbi.messaging.MessageExchange.Role;
29 import javax.jbi.servicedesc.ServiceEndpoint;
30 import javax.xml.namespace.QName JavaDoc;
31
32 import junit.framework.TestCase;
33
34 import org.easymock.classextension.EasyMock;
35 import org.objectweb.petals.jbi.component.context.ComponentContextImpl;
36 import org.objectweb.petals.jbi.messaging.mock.MockLogger;
37 import org.objectweb.petals.jbi.registry.InternalEndpoint;
38 import org.objectweb.petals.jbi.routing.RouterImpl;
39 import org.objectweb.util.monolog.api.Logger;
40
41 /**
42  * Test of the MessageExchangeFactoryImpl
43  *
44  * @author ddesjardins - eBMWebsourcing
45  */

46 public class MessageExchangeFactoryImplTest extends TestCase {
47
48     private MessageExchangeFactoryImpl factoryImpl;
49
50     public void setUp() {
51         ComponentContextImpl componentContextImpl = new ComponentContextImpl();
52         RouterImpl routerImpl = new RouterImpl();
53         Logger logger = new MockLogger();
54         DeliveryChannelImpl deliveryChannelImpl = new DeliveryChannelImpl(
55             componentContextImpl, routerImpl, logger);
56         factoryImpl = new MessageExchangeFactoryImpl(deliveryChannelImpl, null,
57             logger);
58     }
59
60     public void testSetDefaultInterfaceName() {
61         factoryImpl.setDefaultInterfaceName(new QName JavaDoc("defaultinterfacename"));
62         assertEquals(factoryImpl.defaultInterfaceName, new QName JavaDoc(
63             "defaultinterfacename"));
64     }
65
66     public void testSetDefaultServiceEndpoint() {
67         InternalEndpoint internalEndpoint = new InternalEndpoint(new QName JavaDoc(
68             "servicename"), "endpoint", "compo", null, null);
69         factoryImpl.setDefaultServiceEndpoint(internalEndpoint);
70         assertEquals(factoryImpl.defaultServiceEndpoint, internalEndpoint);
71     }
72
73     public void testSetDefaultServiceName() {
74         factoryImpl.setDefaultServiceName(new QName JavaDoc("servicename"));
75         assertEquals(factoryImpl.defaultServiceName, new QName JavaDoc("servicename"));
76     }
77
78     public void testCreateExchange() throws MessagingException {
79         factoryImpl.setDefaultServiceName(new QName JavaDoc("servicename"));
80         MessageExchangeImpl messageExchangeImpl = factoryImpl.createExchange();
81         assertEquals(messageExchangeImpl.getService(), new QName JavaDoc("servicename"));
82     }
83
84     public void testCreateExchange1() throws MessagingException {
85         MessageExchange messageExchange = factoryImpl.createExchange(new QName JavaDoc(
86             "servicename1"), new QName JavaDoc("operation1"));
87         assertEquals(messageExchange.getService(), new QName JavaDoc("servicename1"));
88         assertEquals(messageExchange.getOperation(), new QName JavaDoc("operation1"));
89     }
90
91     public void testCreateExchange2() throws MessagingException {
92         MessageExchange messageExchange = factoryImpl
93             .createExchange(MessageExchangeImpl.IN_ONLY_PATTERN);
94         assertEquals(messageExchange.getPattern(),
95             MessageExchangeImpl.IN_ONLY_PATTERN);
96     }
97
98     public void testCreateInOnlyExchange() throws MessagingException {
99         MessageExchange messageExchange = factoryImpl.createInOnlyExchange();
100         assertEquals(messageExchange.getPattern(),
101             MessageExchangeImpl.IN_ONLY_PATTERN);
102     }
103
104     public void testCreateInOptionalOutExchange() throws MessagingException {
105         MessageExchange messageExchange = factoryImpl
106             .createInOptionalOutExchange();
107         assertEquals(messageExchange.getPattern(),
108             MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN);
109     }
110
111     public void testCreateInOutExchange() throws MessagingException {
112         MessageExchange messageExchange = factoryImpl.createInOutExchange();
113         assertEquals(messageExchange.getPattern(),
114             MessageExchangeImpl.IN_OUT_PATTERN);
115     }
116
117     public void testCreateRobustInOnlyExchange() throws MessagingException {
118         MessageExchange messageExchange = factoryImpl
119             .createRobustInOnlyExchange();
120         assertEquals(messageExchange.getPattern(),
121             MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN);
122     }
123
124     public void testCreateExchangeException() {
125         try {
126             factoryImpl.createExchange(URI
127                 .create("http://www.ebmwebsourcing.org/"));
128             fail();
129         } catch (MessagingException e) {
130             // do nothing
131
}
132     }
133
134     public void testCreateExchangeDecoratorROBUST_IN_ONLY_PATTERN()
135         throws MessagingException {
136         MessageExchangeImpl messageExchangeImpl = EasyMock
137             .createMock(MessageExchangeImpl.class);
138
139         EasyMock.expect(messageExchangeImpl.getRole()).andReturn(Role.CONSUMER)
140             .anyTimes();
141         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_ONLY_PATTERN);
142         messageExchangeImpl
143             .setPattern(MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN);
144         EasyMock.expect(messageExchangeImpl.getPattern()).andReturn(
145             MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN);
146
147         EasyMock.replay(messageExchangeImpl);
148
149         MessageExchange messageExchange = factoryImpl.createExchangeDecorator(
150             messageExchangeImpl, MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN);
151         assertEquals(messageExchange.getPattern(),
152             MessageExchangeImpl.ROBUST_IN_ONLY_PATTERN);
153     }
154
155     public void testCreateExchangeDecoratorIN_OUT_PATTERN()
156         throws MessagingException {
157         MessageExchangeImpl messageExchangeImpl = EasyMock
158             .createMock(MessageExchangeImpl.class);
159
160         EasyMock.expect(messageExchangeImpl.getRole()).andReturn(Role.CONSUMER)
161             .anyTimes();
162         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_OUT_PATTERN);
163         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_OUT_PATTERN);
164         EasyMock.expect(messageExchangeImpl.getPattern()).andReturn(
165             MessageExchangeImpl.IN_OUT_PATTERN);
166
167         EasyMock.replay(messageExchangeImpl);
168
169         MessageExchange messageExchange = factoryImpl.createExchangeDecorator(
170             messageExchangeImpl, MessageExchangeImpl.IN_OUT_PATTERN);
171         assertEquals(messageExchange.getPattern(),
172             MessageExchangeImpl.IN_OUT_PATTERN);
173     }
174
175     public void testCreateExchangeDecoratorIN_OPTIONAL_OUT_PATTERN()
176         throws MessagingException {
177         MessageExchangeImpl messageExchangeImpl = EasyMock
178             .createMock(MessageExchangeImpl.class);
179
180         EasyMock.expect(messageExchangeImpl.getRole()).andReturn(Role.CONSUMER)
181             .anyTimes();
182         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_OUT_PATTERN);
183         messageExchangeImpl
184             .setPattern(MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN);
185         EasyMock.expect(messageExchangeImpl.getPattern()).andReturn(
186             MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN);
187
188         EasyMock.replay(messageExchangeImpl);
189
190         MessageExchange messageExchange = factoryImpl.createExchangeDecorator(
191             messageExchangeImpl, MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN);
192         assertEquals(messageExchange.getPattern(),
193             MessageExchangeImpl.IN_OPTIONAL_OUT_PATTERN);
194     }
195
196     public void testCreateExchangeDecoratorBadPattern()
197         throws MessagingException {
198         MessageExchangeImpl messageExchangeImpl = EasyMock
199             .createMock(MessageExchangeImpl.class);
200
201         EasyMock.expect(messageExchangeImpl.getRole()).andReturn(Role.CONSUMER);
202
203         EasyMock.replay(messageExchangeImpl);
204
205         assertNotNull(factoryImpl.createExchangeDecorator(messageExchangeImpl,
206             URI.create("http://www.ebmwebsourcing.org/")));
207     }
208
209     public void testSetDefaultMessageExchangeProperties() {
210         ServiceEndpoint serviceEndpoint = EasyMock
211             .createMock(ServiceEndpoint.class);
212         factoryImpl.defaultInterfaceName = new QName JavaDoc("inter");
213         factoryImpl.defaultServiceEndpoint = serviceEndpoint;
214         factoryImpl.defaultServiceName = new QName JavaDoc("serv");
215         MessageExchangeImpl messageExchangeImpl = EasyMock
216             .createMock(MessageExchangeImpl.class);
217
218         messageExchangeImpl.setInterfaceName(new QName JavaDoc("inter"));
219         messageExchangeImpl.setService(new QName JavaDoc("serv"));
220         messageExchangeImpl.setEndpoint(serviceEndpoint);
221         
222         EasyMock.replay(messageExchangeImpl);
223
224         factoryImpl.setDefaultMessageExchangeProperties(messageExchangeImpl);
225     }
226 }
227
Popular Tags