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 static org.junit.Assert.assertEquals;
10  import static org.junit.Assert.fail;
11  
12  import org.mule.api.client.MuleClient;
13  
14  import java.sql.Connection;
15  import java.util.List;
16  
17  import org.apache.commons.dbutils.QueryRunner;
18  import org.apache.commons.dbutils.handlers.ArrayListHandler;
19  import org.junit.Test;
20  
21  /**
22   * Tests Mule disposal in the context of nested queries on JDBC endpoints. This test is related to MULE-6607.
23   */
24  public class JdbcEndpointWithNestedQueriesTestCase extends AbstractJdbcFunctionalTestCase
25  {
26      public JdbcEndpointWithNestedQueriesTestCase()
27      {
28          super();
29          setPopulateTestData(false);
30      }
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "jdbc-endpoint-with-nested-queries-test.xml";
36      }
37      
38      @Test
39      public void testDisposeAfterQueryExecution() throws Exception
40      {
41          QueryRunner queryRunner = jdbcConnector.getQueryRunner();
42          Connection connection = jdbcConnector.getConnection();
43  
44          // Send a message to trigger nested query on JDBC outbound endpoint to execute.
45          MuleClient client = muleContext.getClient();
46          client.send("vm://in", "some test data", null);
47  
48          // Assert that query executed correctly.
49          List<?> results = (List<?>) queryRunner.query(connection, "SELECT * FROM TEST", new ArrayListHandler());
50          assertEquals(1, results.size());
51  
52          // Try to dispose gracefully.
53          try
54          {
55              muleContext.dispose();
56          }
57          catch (Exception ex)
58          {
59              fail("Server disposal failed");
60          }
61      }
62  }