View Javadoc

1   /*
2    * $Id: Mule3625FunctionalTest.java 22552 2011-07-25 07:18:19Z claude.mamo $
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.transport.jdbc.functional;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertTrue;
15  
16  import org.mule.tck.AbstractServiceAndFlowTestCase;
17  
18  import java.sql.Connection;
19  import java.sql.ResultSet;
20  import java.sql.Statement;
21  import java.util.Arrays;
22  import java.util.Collection;
23  
24  import javax.sql.DataSource;
25  
26  import org.junit.Test;
27  import org.junit.runners.Parameterized.Parameters;
28  
29  /**
30   * Test for MULE-3625, submitted by community member Guy Veraghtert
31   */
32  public class Mule3625FunctionalTest extends AbstractServiceAndFlowTestCase
33  {
34      public Mule3625FunctionalTest(ConfigVariant variant, String configResources)
35      {
36          super(variant, configResources);
37      }
38  
39      @Parameters
40      public static Collection<Object[]> parameters()
41      {
42          return Arrays.asList(new Object[][]{
43              {ConfigVariant.SERVICE, "jdbc-mule-3625-service.xml"},
44              {ConfigVariant.FLOW, "jdbc-mule-3625-flow.xml"}
45          });
46      }      
47      
48      /**
49       * Test registering transaction manager for non-XA rtansaction
50       *
51       * @throws Exception
52       */
53      @Test
54      public void testNonXaTx() throws Exception
55      {
56          DataSource dataSource = (DataSource) muleContext.getRegistry().lookupObject("hsqldbDataSource");
57          Connection connection = dataSource.getConnection();
58          Statement statement = connection.createStatement();
59  
60          // make sure other tests didnt leave anything behind
61          statement.execute("DROP SCHEMA PUBLIC CASCADE");
62  
63          statement.executeUpdate("create table TABLE_A (value varchar(1))");
64          statement.executeUpdate("create table TABLE_B (value varchar(1))");
65          statement.executeUpdate("insert into TABLE_A(value) values('n')");
66          Thread.sleep(10000); //TODO DZ: sleeps in tests are not ideal
67          ResultSet resultSet = statement.executeQuery("select count(*) from TABLE_B where value='y'");
68          assertTrue(resultSet.next());
69          assertEquals(1, resultSet.getLong(1));
70  
71          // clean up for later tests
72          statement.execute("DROP SCHEMA PUBLIC CASCADE");
73          resultSet.close();
74          connection.close();
75      }
76  }