1 22 package org.objectweb.petals.jbi.transport; 23 24 import javax.jbi.JBIException; 25 import javax.jms.JMSException ; 26 import javax.jms.ObjectMessage ; 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 40 public class ObjectSerializerTest extends TestCase { 41 42 public void testJbi2jms() throws JBIException, JMSException { 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 objectMessage = EasyMock.createMock(ObjectMessage .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 { 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 objectMessage = EasyMock.createMock(ObjectMessage .class); 67 68 EasyMock.expect(queueSession.createObjectMessage(messageExchangeImpl)) 69 .andThrow(new JMSException ("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 } 80 } 81 82 public void testJms2jbi() throws JBIException, JMSException { 83 ObjectSerializer objectSerializer = new ObjectSerializer(); 84 85 ObjectMessage objectMessage = EasyMock.createMock(ObjectMessage .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 { 99 ObjectSerializer objectSerializer = new ObjectSerializer(); 100 101 ObjectMessage objectMessage = EasyMock.createMock(ObjectMessage .class); 102 103 EasyMock.expect(objectMessage.getObject()).andThrow( 104 new JMSException ("error")).anyTimes(); 105 106 EasyMock.replay(objectMessage); 107 108 try { 109 objectSerializer.jms2jbi(objectMessage); 110 fail(); 111 } catch (JBIException e) { 112 } 114 } 115 } 116 | Popular Tags |