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.transport.jdbc.functional;
8   
9   import org.mule.tck.junit4.FunctionalTestCase;
10  
11  import java.sql.Connection;
12  import java.sql.ResultSet;
13  import java.sql.Statement;
14  
15  import javax.sql.DataSource;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  /**
23   * Test for MULE-3625, submitted by community member Guy Veraghtert
24   */
25  public class Mule3625FunctionalTest extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "jdbc-mule-3625.xml";
32      }
33  
34      /**
35       * Test registering transaction manager for non-XA rtansaction
36       * 
37       * @throws Exception
38       */
39      @Test
40      public void testNonXaTx() throws Exception
41      {
42          DataSource dataSource = (DataSource) muleContext.getRegistry().lookupObject("hsqldbDataSource");
43          Connection connection = dataSource.getConnection();
44          Statement statement = connection.createStatement();
45          
46          // make sure other tests didnt leave anything behind
47          statement.execute("DROP SCHEMA PUBLIC CASCADE");        
48          
49          statement.executeUpdate("create table TABLE_A (value varchar(1))");
50          statement.executeUpdate("create table TABLE_B (value varchar(1))");
51          statement.executeUpdate("insert into TABLE_A(value) values('n')");
52          Thread.sleep(10000); //TODO DZ: sleeps in tests are not ideal
53          ResultSet resultSet = statement.executeQuery("select count(*) from TABLE_B where value='y'");
54          assertTrue(resultSet.next());
55          assertEquals(1, resultSet.getLong(1));
56          
57          // clean up for later tests
58          statement.execute("DROP SCHEMA PUBLIC CASCADE");
59          resultSet.close();
60          connection.close();
61      }
62  
63  }