View Javadoc

1   /*
2    * $Id: JdbcDataSourceNamespaceHandlerTestCase.java 22123 2011-06-06 11:11:23Z dirk.olmes $
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.config;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  import java.sql.Connection;
16  
17  import org.enhydra.jdbc.standard.StandardDataSource;
18  
19  public class JdbcDataSourceNamespaceHandlerTestCase extends FunctionalTestCase
20  {
21      public JdbcDataSourceNamespaceHandlerTestCase()
22      {
23          super();
24          setStartContext(false);
25      }
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "jdbc-data-source-namespace-config.xml";
31      }
32  
33      public void testSingleton()
34      {
35          StandardDataSource ds1 = lookupDataSource("default-oracle");
36          StandardDataSource ds2 = lookupDataSource("default-oracle");
37          assertSame(ds1, ds2);
38      }
39  
40      public void testCustomDataSourceProperties()
41      {
42          StandardDataSource source = lookupDataSource("custom-ds-properties");
43          assertEquals(Connection.TRANSACTION_SERIALIZABLE, source.getTransactionIsolation());
44          assertEquals(42, source.getLoginTimeout());
45      }
46  
47      public void testOracleDefaults()
48      {
49          StandardDataSource source = lookupDataSource("default-oracle");
50          assertEquals("jdbc:oracle:thin:@localhost:1521:orcl", source.getUrl());
51          assertEquals("oracle.jdbc.driver.OracleDriver", source.getDriverName());
52          assertEquals(-1, source.getTransactionIsolation());
53          assertEquals("scott", source.getUser());
54          assertEquals("tiger", source.getPassword());
55      }
56  
57      public void testOracleCustomUrl()
58      {
59          StandardDataSource source = lookupDataSource("custom-url-oracle");
60          assertEquals("jdbc:oracle:thin:@some-other-host:1522:mule", source.getUrl());
61      }
62  
63      public void testOracleCustomHost()
64      {
65          StandardDataSource source = lookupDataSource("custom-host-oracle");
66          assertEquals("jdbc:oracle:thin:@some-other-host:1521:orcl", source.getUrl());
67      }
68  
69      public void testOracleCustomPort()
70      {
71          StandardDataSource source = lookupDataSource("custom-port-oracle");
72          assertEquals("jdbc:oracle:thin:@localhost:1522:orcl", source.getUrl());
73      }
74  
75      public void testOracleCustomInstance()
76      {
77          StandardDataSource source = lookupDataSource("custom-instance-oracle");
78          assertEquals("jdbc:oracle:thin:@localhost:1521:mule", source.getUrl());
79      }
80  
81      public void testMysqlDefaults()
82      {
83          StandardDataSource source = lookupDataSource("default-mysql");
84          assertEquals("jdbc:mysql://localhost/mule", source.getUrl());
85          assertEquals("com.mysql.jdbc.Driver", source.getDriverName());
86          assertEquals("mysql", source.getUser());
87          assertEquals("secret", source.getPassword());
88      }
89  
90      public void testMysqlCustomUrl()
91      {
92          StandardDataSource source = lookupDataSource("custom-url-mysql");
93          assertEquals("jdbc:mysql://mule-db-host:3306/mule", source.getUrl());
94      }
95  
96      public void testMysqlCustomHost()
97      {
98          StandardDataSource source = lookupDataSource("custom-host-mysql");
99          assertEquals("jdbc:mysql://some-other-host/mule", source.getUrl());
100     }
101 
102     public void testMysqlCustomPort()
103     {
104         StandardDataSource source = lookupDataSource("custom-port-mysql");
105         assertEquals("jdbc:mysql://localhost:4242/mule", source.getUrl());
106     }
107 
108     public void testPostgresqlDefaults()
109     {
110         StandardDataSource source = lookupDataSource("default-postgresql");
111         assertEquals("jdbc:postgresql://localhost/mule", source.getUrl());
112         assertEquals("org.postgresql.Driver", source.getDriverName());
113         assertEquals("postgres", source.getUser());
114         assertEquals("secret", source.getPassword());
115     }
116 
117     public void testPostgresqlCustomUrl()
118     {
119         StandardDataSource source = lookupDataSource("custom-url-postgresql");
120         assertEquals("jdbc:postgresql://mule-db-host:5432/mule", source.getUrl());
121     }
122 
123     public void testPostgresqlCustomHost()
124     {
125         StandardDataSource source = lookupDataSource("custom-host-postgresql");
126         assertEquals("jdbc:postgresql://some-other-host/mule", source.getUrl());
127     }
128 
129     public void testPostgresqlCustomPort()
130     {
131         StandardDataSource source = lookupDataSource("custom-port-postgresql");
132         assertEquals("jdbc:postgresql://localhost:5433/mule", source.getUrl());
133     }
134 
135     public void testDerbyDefaults()
136     {
137         StandardDataSource source = lookupDataSource("default-derby");
138         assertEquals("jdbc:derby:memory:mule", source.getUrl());
139         assertEquals("org.apache.derby.jdbc.EmbeddedDriver", source.getDriverName());
140     }
141 
142     public void testDerbyCustomUrl()
143     {
144         StandardDataSource source = lookupDataSource("custom-url-derby");
145         assertEquals("jdbc:derby:muleEmbedded", source.getUrl());
146     }
147 
148     public void testDerbyCreateDatabase()
149     {
150         StandardDataSource source = lookupDataSource("create-database-derby");
151         assertEquals("jdbc:derby:memory:mule;create=true", source.getUrl());
152     }
153 
154     private StandardDataSource lookupDataSource(String key)
155     {
156         Object object = muleContext.getRegistry().lookupObject(key);
157         assertNotNull(object);
158         assertTrue(object instanceof StandardDataSource);
159 
160         return (StandardDataSource) object;
161     }
162 }