View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.transaction;
8   
9   import org.mule.module.client.MuleClient;
10  
11  import java.util.List;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  
17  public class XAJdbcMule1479TestCase extends AbstractDerbyTestCase
18  {
19      
20      @Override
21      protected String getConfigResources()
22      {
23          return "org/mule/test/integration/transaction/jdbc-xatransaction-1479.xml";
24      }
25  
26      @Override
27      protected void emptyTable() throws Exception
28      {
29          try
30          {
31              execSqlUpdate("DELETE FROM TEST");
32          }
33          catch (Exception e)
34          {
35              execSqlUpdate("CREATE TABLE TEST(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,DATA VARCHAR(255))");
36          }
37      }
38  
39      @Test
40      public void testJdbcXa() throws Exception
41      {
42          MuleClient client = new MuleClient(muleContext);
43          client.dispatch("vm://in","test",null);
44          
45          for (int i = 0; i < 10; i++)
46          {
47              List results = execSqlQuery("SELECT * FROM TEST");
48              assertEquals(0, results.size());
49              
50              Thread.sleep(1000);
51          }
52      }    
53  
54      @Test
55      public void testJmsXa() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58          client.dispatch("vm://in1", "test", null);
59          
60          List results = null;
61          for (int i = 0; i < 10; i++)
62          {
63              results = execSqlQuery("SELECT * FROM TEST");
64              if (results.size() > 0)
65              {
66                  break;
67              }
68              
69              Thread.sleep(1000);
70          }
71  
72          assertEquals(1, results.size());
73      }
74  
75  }