1 17 package org.apache.servicemix.jbi.audit.jdbc; 18 19 import org.apache.servicemix.jbi.audit.jdbc.JdbcAuditor; 20 import org.apache.servicemix.jbi.container.JBIContainer; 21 import org.apache.servicemix.jbi.jaxp.StringSource; 22 import org.apache.servicemix.tck.ReceiverComponent; 23 import org.apache.servicemix.tck.SenderComponent; 24 import org.hsqldb.jdbc.jdbcDataSource; 25 26 import javax.jbi.messaging.ExchangeStatus; 27 import javax.jbi.messaging.InOnly; 28 import javax.jbi.messaging.MessageExchange; 29 import javax.sql.DataSource ; 30 31 import java.sql.Connection ; 32 33 import junit.framework.TestCase; 34 35 36 public class JdbcAuditorTest extends TestCase { 37 38 private DataSource dataSource; 39 private Connection connection; 40 private JBIContainer jbi; 41 42 43 protected void setUp() throws Exception { 44 jdbcDataSource ds = new jdbcDataSource(); 45 ds.setDatabase("jdbc:hsqldb:mem:aname"); 46 ds.setUser("sa"); 47 dataSource = ds; 48 connection = dataSource.getConnection(); 49 jbi = new JBIContainer(); 50 } 51 52 protected void tearDown() throws Exception { 53 if (jbi != null) { 54 jbi.shutDown(); 55 } 56 if (connection != null) { 57 connection.close(); 58 } 59 } 60 61 62 public void testInsertUpdate() throws Exception { 63 jbi.setFlowName("st"); 64 jbi.setEmbedded(true); 65 jbi.init(); 66 jbi.start(); 67 SenderComponent sender = new SenderComponent(); 68 ReceiverComponent receiver = new ReceiverComponent(); 69 jbi.activateComponent(sender, "sender"); 70 jbi.activateComponent(receiver, "receiver"); 71 72 JdbcAuditor auditor = new JdbcAuditor(); 73 auditor.setContainer(jbi); 74 auditor.setDataSource(dataSource); 75 auditor.afterPropertiesSet(); 76 77 InOnly inonly = sender.createInOnlyExchange(ReceiverComponent.SERVICE, null, null); 78 inonly.setInMessage(inonly.createMessage()); 79 inonly.getInMessage().setContent(new StringSource("<hello>world</hello>")); 80 sender.send(inonly); 81 82 int nbMessages = auditor.getExchangeCount(); 83 assertEquals(1, nbMessages); 84 MessageExchange[] exchanges = auditor.getExchanges(0, 1); 85 assertNotNull(exchanges); 86 assertEquals(1, exchanges.length); 87 assertEquals(ExchangeStatus.DONE, exchanges[0].getStatus()); 88 89 auditor.resendExchange(exchanges[0]); 90 91 nbMessages = auditor.getExchangeCount(); 92 assertEquals(2, nbMessages); 93 MessageExchange exchange = auditor.getExchange(1); 94 assertNotNull(exchange); 95 assertEquals(ExchangeStatus.DONE, exchange.getStatus()); 96 97 113 114 } 115 116 } 117 | Popular Tags |