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.store;
8   
9   import java.io.Serializable;
10  
11  import org.apache.commons.dbutils.QueryRunner;
12  import org.mule.api.config.ConfigurationBuilder;
13  import org.mule.api.store.ObjectStore;
14  import org.mule.config.spring.SpringXmlConfigurationBuilder;
15  import org.mule.util.store.AbstractObjectStoreContractTestCase;
16  
17  public class JdbcObjectStoreTestCase extends AbstractObjectStoreContractTestCase
18  {
19  
20      public JdbcObjectStoreTestCase()
21      {
22          this.setStartContext(true);
23      }
24  
25      @Override
26      protected void doSetUp() throws Exception
27      {
28          super.doSetUp();
29          JdbcObjectStore<?> store = muleContext.getRegistry().get("jdbcObjectStore");
30          QueryRunner qr = store.getJdbcConnector().getQueryRunner();
31          
32          try
33          {
34              qr.update(store.getJdbcConnector().getConnection(), "DELETE FROM IDS");
35          }
36          catch (Exception e)
37          {
38          }
39          
40          try
41          {
42              qr.update(store.getJdbcConnector().getConnection(),
43                  "CREATE TABLE IDS(K VARCHAR(255) NOT NULL PRIMARY KEY, VALUE VARCHAR(255))");
44          }
45          catch (Exception e)
46          {
47          }
48          
49          logger.debug("Table created");
50      }
51  
52      @Override
53      public ObjectStore getObjectStore()
54      {
55          JdbcObjectStore<?> store = muleContext.getRegistry().get("jdbcObjectStore");
56          return store;
57      }
58  
59      @Override
60      public Serializable getStorableValue()
61      {
62          return "1";
63      }
64  
65      @Override
66      protected String getConfigurationResources()
67      {
68          return "jdbc-connector.xml,jdbc-store.xml";
69      }
70  
71      @Override
72      protected ConfigurationBuilder getBuilder() throws Exception
73      {
74          return new SpringXmlConfigurationBuilder(getConfigurationResources());
75      }
76  }