View Javadoc

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