KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > xquarebc > mock > MockDeliveryChannel


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: MockDeliveryChannel.java,v 1.1 2006/10/23 18:22:41 mdutoo Exp $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.binding.xquarebc.mock;
23
24 import javax.jbi.messaging.DeliveryChannel;
25 import javax.jbi.messaging.MessageExchange;
26 import javax.jbi.messaging.MessageExchangeFactory;
27 import javax.jbi.messaging.MessagingException;
28 import javax.jbi.servicedesc.ServiceEndpoint;
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.objectweb.petals.component.common.util.SourceHelper;
32
33 import static org.easymock.EasyMock.expect;
34 import static org.easymock.classextension.EasyMock.createMock;
35 import static org.easymock.classextension.EasyMock.replay;
36
37 /**
38  * Mock of DeliveryChannel
39  *
40  * @author Marc Dutoo - Open Wide
41  */

42 public class MockDeliveryChannel implements DeliveryChannel {
43
44     public MessageExchange accept() throws MessagingException {
45         return null;
46     }
47
48     public MessageExchange accept(long timeoutMS) throws MessagingException,
49         IllegalArgumentException JavaDoc {
50         return null;
51     }
52
53     public void close() throws MessagingException {
54     }
55
56     public MessageExchangeFactory createExchangeFactory() {
57         MessageExchangeFactory messageExchangeFactory = createMock(MessageExchangeFactory.class);
58         try {
59             expect(messageExchangeFactory.createInOnlyExchange()).andReturn(
60                 new MockInOnly()).anyTimes();
61             expect(messageExchangeFactory.createRobustInOnlyExchange())
62                 .andReturn(new MockRobustInOnly()).anyTimes();
63             expect(messageExchangeFactory.createInOutExchange()).andReturn(
64                 new MockInOut()).anyTimes();
65         } catch (MessagingException e) {
66         }
67         replay(messageExchangeFactory);
68         return messageExchangeFactory;
69     }
70
71     public MessageExchangeFactory createExchangeFactory(QName JavaDoc interfaceName) {
72         return null;
73     }
74
75     public MessageExchangeFactory createExchangeFactory(ServiceEndpoint endpoint) {
76         return null;
77     }
78
79     public MessageExchangeFactory createExchangeFactoryForService(
80         QName JavaDoc serviceName) {
81         return null;
82     }
83
84     private boolean send;
85
86     public boolean isSend() {
87         return send;
88     }
89
90     public void setSend(boolean send) {
91         this.send = send;
92     }
93
94     public void send(MessageExchange exchange) throws MessagingException {
95         send = true;
96     }
97
98     private boolean sendSync;
99
100     public boolean sendSync(MessageExchange exchange) throws MessagingException {
101         if (exchange instanceof MockInOut) {
102             MockNormalizedMessage mockNormalizedMessage = new MockNormalizedMessage();
103             mockNormalizedMessage.setContent(SourceHelper
104                 .createContentSource("test"));
105             ((MockInOut) exchange).setOutMessage(mockNormalizedMessage);
106         }
107         sendSync = true;
108         return false;
109     }
110
111     private boolean sendSyncLong;
112
113     public boolean sendSync(MessageExchange exchange, long timeoutMS)
114         throws MessagingException {
115         sendSyncLong = true;
116         return false;
117     }
118
119     public boolean isSendSync() {
120         return sendSync;
121     }
122
123     public void setSendSync(boolean sendSync) {
124         this.sendSync = sendSync;
125     }
126
127     public boolean isSendSyncLong() {
128         return sendSyncLong;
129     }
130
131     public void setSendSyncLong(boolean sendSyncLong) {
132         this.sendSyncLong = sendSyncLong;
133     }
134
135 }
136
Popular Tags