1 17 package org.apache.servicemix.jms; 18 19 import javax.jbi.messaging.ExchangeStatus; 20 import javax.jbi.messaging.InOnly; 21 import javax.jbi.messaging.InOut; 22 import javax.naming.Context ; 23 import javax.transaction.TransactionManager ; 24 import javax.xml.namespace.QName ; 25 26 import org.apache.servicemix.client.DefaultServiceMixClient; 27 import org.apache.servicemix.client.Destination; 28 import org.apache.servicemix.jbi.jaxp.StringSource; 29 import org.apache.servicemix.tck.ExchangeCompletedListener; 30 import org.apache.servicemix.tck.Receiver; 31 import org.apache.servicemix.tck.SpringTestSupport; 32 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 33 import org.apache.xbean.spring.jndi.SpringInitialContextFactory; 34 import org.springframework.context.support.AbstractXmlApplicationContext; 35 36 public class JmsSpringJcaTest extends SpringTestSupport { 37 38 protected ExchangeCompletedListener listener; 39 protected DefaultServiceMixClient client; 40 protected Receiver receiver; 41 42 protected void setUp() throws Exception { 43 super.setUp(); 44 listener = new ExchangeCompletedListener(5000); 45 jbi.addListener(listener); 46 client = new DefaultServiceMixClient(jbi); 47 receiver = (Receiver) getBean("receiver"); 48 } 49 50 protected void tearDown() throws Exception { 51 listener.assertExchangeCompleted(); 52 super.tearDown(); 53 } 54 55 public void testInOut() throws Exception { 56 TransactionManager tm = (TransactionManager ) getBean("transactionManager"); 57 tm.begin(); 58 InOut me = client.createInOutExchange(); 59 me.setService(new QName ("http://test", "MyProviderService")); 60 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 61 client.send(me); 62 tm.commit(); 63 me = (InOut) client.receive(); 64 assertEquals(ExchangeStatus.ERROR, me.getStatus()); 65 assertNotNull(me.getError()); 66 assertTrue(me.getError() instanceof UnsupportedOperationException ); 67 } 68 69 public void testInOnlyWithAsyncConsumer() throws Exception { 70 TransactionManager tm = (TransactionManager ) getBean("transactionManager"); 71 tm.begin(); 72 Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async"); 73 InOnly me = dest.createInOnlyExchange(); 74 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 75 client.send(me); 76 tm.commit(); 77 me = (InOnly) client.receive(); 78 assertEquals(ExchangeStatus.DONE, me.getStatus()); 79 receiver.getMessageList().assertMessagesReceived(1); 80 } 81 82 public void testInOnlySyncWithAsyncConsumer() throws Exception { 83 TransactionManager tm = (TransactionManager ) getBean("transactionManager"); 84 tm.begin(); 85 Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async"); 86 InOnly me = dest.createInOnlyExchange(); 87 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 88 client.sendSync(me); 89 assertEquals(ExchangeStatus.DONE, me.getStatus()); 90 tm.commit(); 91 receiver.getMessageList().assertMessagesReceived(1); 92 } 93 94 public void testInOnlyWithSyncConsumer() throws Exception { 95 TransactionManager tm = (TransactionManager ) getBean("transactionManager"); 96 tm.begin(); 97 Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous"); 98 InOnly me = dest.createInOnlyExchange(); 99 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 100 client.send(me); 101 tm.commit(); 102 me = (InOnly) client.receive(); 103 assertEquals(ExchangeStatus.DONE, me.getStatus()); 104 receiver.getMessageList().assertMessagesReceived(1); 105 } 106 107 public void testInOnlySyncWithSyncConsumer() throws Exception { 108 TransactionManager tm = (TransactionManager ) getBean("transactionManager"); 109 tm.begin(); 110 Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous"); 111 InOnly me = dest.createInOnlyExchange(); 112 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>")); 113 client.sendSync(me); 114 assertEquals(ExchangeStatus.DONE, me.getStatus()); 115 tm.commit(); 116 receiver.getMessageList().assertMessagesReceived(1); 117 } 118 119 protected AbstractXmlApplicationContext createBeanFactory() { 120 System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName()); 121 System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml"); 122 return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring-jca.xml"); 123 } 124 125 } 126 | Popular Tags |