KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > csv > 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 1216 2006-11-14 18:27:09Z dutoo $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.engine.csv.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  * @version $Rev: 1069 $Date: ${date}
41  * @since Petals 1.0
42  * @author Marc Dutoo - Open Wide
43  *
44  */

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