KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > transport > ObjectSerializerTest


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: ObjectSerializerTest.java 9:41:31 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.transport;
23
24 import javax.jbi.JBIException;
25 import javax.jms.JMSException JavaDoc;
26 import javax.jms.ObjectMessage JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.easymock.classextension.EasyMock;
31 import org.objectweb.joram.client.jms.QueueSession;
32 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl;
33 import org.objectweb.petals.jbi.registry.ConsumerEndpoint;
34
35 /**
36  * Tests of the ObjectSerializer
37  *
38  * @author ddesjardins - eBMWebsourcing
39  */

40 public class ObjectSerializerTest extends TestCase {
41
42     public void testJbi2jms() throws JBIException, JMSException JavaDoc {
43         ObjectSerializer objectSerializer = new ObjectSerializer();
44         MessageExchangeImpl messageExchangeImpl = new MessageExchangeImpl(
45             new ConsumerEndpoint("compo", "0"));
46
47         QueueSession queueSession = EasyMock.createMock(QueueSession.class);
48         ObjectMessage JavaDoc objectMessage = EasyMock.createMock(ObjectMessage JavaDoc.class);
49
50         EasyMock.expect(queueSession.createObjectMessage(messageExchangeImpl))
51             .andReturn(objectMessage).anyTimes();
52
53         EasyMock.replay(queueSession);
54         EasyMock.replay(objectMessage);
55
56         assertEquals(objectMessage, objectSerializer.jbi2jms(
57             messageExchangeImpl, queueSession));
58     }
59
60     public void testJbi2jmsException() throws JBIException, JMSException JavaDoc {
61         ObjectSerializer objectSerializer = new ObjectSerializer();
62         MessageExchangeImpl messageExchangeImpl = new MessageExchangeImpl(
63             new ConsumerEndpoint("compo", "0"));
64
65         QueueSession queueSession = EasyMock.createMock(QueueSession.class);
66         ObjectMessage JavaDoc objectMessage = EasyMock.createMock(ObjectMessage JavaDoc.class);
67
68         EasyMock.expect(queueSession.createObjectMessage(messageExchangeImpl))
69             .andThrow(new JMSException JavaDoc("error")).anyTimes();
70
71         EasyMock.replay(queueSession);
72         EasyMock.replay(objectMessage);
73
74         try {
75             objectSerializer.jbi2jms(messageExchangeImpl, queueSession);
76             fail();
77         } catch (JBIException e) {
78             // do nothing
79
}
80     }
81
82     public void testJms2jbi() throws JBIException, JMSException JavaDoc {
83         ObjectSerializer objectSerializer = new ObjectSerializer();
84
85         ObjectMessage JavaDoc objectMessage = EasyMock.createMock(ObjectMessage JavaDoc.class);
86         MessageExchangeImpl messageExchangeImpl = new MessageExchangeImpl(
87             new ConsumerEndpoint("compo", "0"));
88
89         EasyMock.expect(objectMessage.getObject()).andReturn(
90             messageExchangeImpl).anyTimes();
91
92         EasyMock.replay(objectMessage);
93
94         assertEquals(messageExchangeImpl, objectSerializer
95             .jms2jbi(objectMessage));
96     }
97
98     public void testJms2jbiException() throws JBIException, JMSException JavaDoc {
99         ObjectSerializer objectSerializer = new ObjectSerializer();
100
101         ObjectMessage JavaDoc objectMessage = EasyMock.createMock(ObjectMessage JavaDoc.class);
102
103         EasyMock.expect(objectMessage.getObject()).andThrow(
104             new JMSException JavaDoc("error")).anyTimes();
105
106         EasyMock.replay(objectMessage);
107
108         try {
109             objectSerializer.jms2jbi(objectMessage);
110             fail();
111         } catch (JBIException e) {
112             // do nothing
113
}
114     }
115 }
116
Popular Tags