View Javadoc

1   /*
2    * $Id: XAJdbcMule1479TestCase.java 22551 2011-07-25 06:32:00Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.integration.transaction;
12  
13  import org.junit.runners.Parameterized;
14  import org.mule.module.client.MuleClient;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  import java.util.List;
19  
20  import org.junit.Test;
21  import org.mule.tck.AbstractServiceAndFlowTestCase;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  public class XAJdbcMule1479TestCase extends AbstractDerbyTestCase
26  {
27      
28      public XAJdbcMule1479TestCase(AbstractServiceAndFlowTestCase.ConfigVariant variant, String configResources)
29      {
30          super(variant, configResources);
31      }
32  
33      @Parameterized.Parameters
34      public static Collection<Object[]> parameters()
35      {
36          return Arrays.asList(new Object[][]{
37              {AbstractServiceAndFlowTestCase.ConfigVariant.SERVICE, "org/mule/test/integration/transaction/jdbc-xatransaction-1479.xml"},
38              // The flow version does not work because flow doesn't support outgoing transaction configuration
39              //{AbstractServiceAndFlowTestCase.ConfigVariant.FLOW, "org/mule/test/integration/transaction/jdbc-xatransaction-1479-flow.xml"}
40          });
41      }
42  
43      @Override
44      protected void emptyTable() throws Exception
45      {
46          try
47          {
48              execSqlUpdate("DELETE FROM TEST");
49          }
50          catch (Exception e)
51          {
52              execSqlUpdate("CREATE TABLE TEST(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,DATA VARCHAR(255))");
53          }
54      }
55  
56      @Test
57      public void testJdbcXa() throws Exception
58      {
59          MuleClient client = new MuleClient(muleContext);
60          client.dispatch("vm://in","test",null);
61          
62          for (int i = 0; i < 10; i++)
63          {
64              List results = execSqlQuery("SELECT * FROM TEST");
65              assertEquals(0, results.size());
66              
67              Thread.sleep(1000);
68          }
69      }    
70  
71      @Test
72      public void testJmsXa() throws Exception
73      {
74          MuleClient client = new MuleClient(muleContext);
75          client.dispatch("vm://in1", "test", null);
76          
77          List results = null;
78          for (int i = 0; i < 10; i++)
79          {
80              results = execSqlQuery("SELECT * FROM TEST");
81              if (results.size() > 0)
82              {
83                  break;
84              }
85              
86              Thread.sleep(1000);
87          }
88  
89          assertEquals(1, results.size());
90      }
91  
92  }