Source Code Cross Referenced for DataSourcePropertiesTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbcapi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbcapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.derbyTesting.functionTests.tests.jdbcapi;
021:
022:        import java.lang.reflect.Method;
023:        import java.sql.Connection;
024:        import java.sql.SQLException;
025:        import javax.sql.ConnectionPoolDataSource;
026:        import javax.sql.DataSource;
027:        import javax.sql.PooledConnection;
028:        import javax.sql.XAConnection;
029:        import javax.sql.XADataSource;
030:        import junit.framework.Test;
031:        import junit.framework.TestSuite;
032:        import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
033:        import org.apache.derbyTesting.functionTests.util.TestUtil;
034:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
035:        import org.apache.derbyTesting.junit.JDBC;
036:
037:        /**
038:         * This class tests that properties of data sources are handled correctly.
039:         */
040:        public class DataSourcePropertiesTest extends BaseJDBCTestCase {
041:
042:            /**
043:             * Creates a new test case.
044:             * @param name name of test method
045:             */
046:            public DataSourcePropertiesTest(String name) {
047:                super (name);
048:            }
049:
050:            // SETUP
051:
052:            /** Creates a test suite with all test cases. */
053:            public static Test suite() {
054:
055:                TestSuite suite = new TestSuite();
056:
057:                // TODO: Run fixtures in J2ME and JDBC2 (with extensions)
058:                // that can be supported there. This disabling matches
059:                // the original _app.properties file. Concern was over
060:                // XA support (which is supported in JDBC 2 with extensions).
061:                if (JDBC.vmSupportsJDBC3()) {
062:
063:                    // Add all methods starting with 'test'.
064:                    //suite.addTestSuite(DataSourcePropertiesTest.class);
065:
066:                    if (usingEmbedded()) {
067:
068:                        // When using embedded, add all methods starting with 'embedded'.
069:                        Method[] methods = DataSourcePropertiesTest.class
070:                                .getMethods();
071:                        for (int i = 0; i < methods.length; i++) {
072:                            Method m = methods[i];
073:                            if (m.getParameterTypes().length > 0
074:                                    || m.getReturnType().equals(Void.TYPE)) {
075:                                continue;
076:                            }
077:                            String name = m.getName();
078:                            if (name.startsWith("embedded")) {
079:                                suite
080:                                        .addTest(new DataSourcePropertiesTest(
081:                                                name));
082:                            }
083:                        }
084:                    }
085:                }
086:                return suite;
087:            }
088:
089:            // HELPER METHODS
090:
091:            /**
092:             * Sets a property of a data source object.
093:             *
094:             * @param dataSource the data source
095:             * @param name name of the property to set
096:             * @param value property value
097:             * @param type property type (useful for setting <code>null</code> or
098:             * primitive types)
099:             */
100:            private void setDataSourceProperty(Object dataSource, String name,
101:                    Object value, Class type) throws Exception {
102:                Method setter = dataSource.getClass().getMethod(
103:                        TestUtil.getSetterName(name), new Class[] { type });
104:                setter.invoke(dataSource, new Object[] { value });
105:            }
106:
107:            /**
108:             * Sets a property of a data source object.
109:             *
110:             * @param dataSource the data source
111:             * @param name name of the property to set
112:             * @param value property value
113:             */
114:            private void setDataSourceProperty(Object dataSource, String name,
115:                    Object value) throws Exception {
116:                setDataSourceProperty(dataSource, name, value, value.getClass());
117:            }
118:
119:            // TEST METHODS
120:
121:            /**
122:             * Tests that the default password is not sent as an attribute string when
123:             * <code>attributesAsPassword</code> is <code>true</code>. The test is run
124:             * with a <code>DataSource</code>.
125:             */
126:            public void embeddedTestAttributesAsPasswordWithoutPassword_ds()
127:                    throws Exception {
128:                DataSource ds = TestDataSourceFactory.getDataSource();
129:                setDataSourceProperty(ds, "password", "mypassword");
130:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
131:                        Boolean.TYPE);
132:                Connection c = ds.getConnection();
133:                c.close();
134:            }
135:
136:            /**
137:             * Tests that the default password is not sent as an attribute string when
138:             * <code>attributesAsPassword</code> is <code>true</code>. The test is run
139:             * with a <code>ConnectionPoolDataSource</code>.
140:             */
141:            public void embeddedTestAttributesAsPasswordWithoutPassword_pooled()
142:                    throws Exception {
143:                ConnectionPoolDataSource ds = TestDataSourceFactory
144:                        .getConnectionPoolDataSource();
145:                setDataSourceProperty(ds, "password", "mypassword");
146:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
147:                        Boolean.TYPE);
148:                // DERBY-1586 caused a malformed url error here
149:                PooledConnection pc = ds.getPooledConnection();
150:                Connection c = pc.getConnection();
151:                c.close();
152:            }
153:
154:            /**
155:             * Tests that the default password is not sent as an attribute string when
156:             * <code>attributesAsPassword</code> is <code>true</code>. The test is run
157:             * with an <code>XADataSource</code>.
158:             */
159:            public void embeddedTestAttributesAsPasswordWithoutPassword_xa()
160:                    throws Exception {
161:                XADataSource ds = TestDataSourceFactory.getXADataSource();
162:                setDataSourceProperty(ds, "password", "mypassword");
163:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
164:                        Boolean.TYPE);
165:                XAConnection xa = ds.getXAConnection();
166:                Connection c = xa.getConnection();
167:                c.close();
168:            }
169:
170:            /**
171:             * Tests that the <code>attributesAsPassword</code> property of a
172:             * <code>DataSource</code> causes an explicitly specified password to be
173:             * sent as a property string.
174:             */
175:            public void embeddedTestAttributesAsPasswordWithPassword_ds()
176:                    throws Exception {
177:                DataSource ds = TestDataSourceFactory.getDataSource();
178:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
179:                        Boolean.TYPE);
180:                try {
181:                    Connection c = ds.getConnection("username", "mypassword");
182:                    fail("Expected getConnection to fail.");
183:                } catch (SQLException e) {
184:                    // expect error because of malformed url
185:                    assertSQLState("XJ028", e);
186:                }
187:            }
188:
189:            /**
190:             * Tests that the <code>attributesAsPassword</code> property of a
191:             * <code>ConnectionPoolDataSource</code> causes an explicitly specified
192:             * password to be sent as a property string.
193:             */
194:            public void embeddedTestAttributesAsPasswordWithPassword_pooled()
195:                    throws Exception {
196:                ConnectionPoolDataSource ds = TestDataSourceFactory
197:                        .getConnectionPoolDataSource();
198:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
199:                        Boolean.TYPE);
200:                try {
201:                    PooledConnection pc = ds.getPooledConnection("username",
202:                            "mypassword");
203:                    fail("Expected getPooledConnection to fail.");
204:                } catch (SQLException e) {
205:                    // expect error because of malformed url
206:                    assertSQLState("XJ028", e);
207:                }
208:            }
209:
210:            /**
211:             * Tests that the <code>attributesAsPassword</code> property of an
212:             * <code>XADataSource</code> causes an explicitly specified password to be
213:             * sent as a property string.
214:             */
215:            public void embeddedTestAttributesAsPasswordWithPassword_xa()
216:                    throws Exception {
217:                XADataSource ds = TestDataSourceFactory.getXADataSource();
218:                setDataSourceProperty(ds, "attributesAsPassword", Boolean.TRUE,
219:                        Boolean.TYPE);
220:                try {
221:                    XAConnection xa = ds.getXAConnection("username",
222:                            "mypassword");
223:                    fail("Expected getXAConnection to fail.");
224:                } catch (SQLException e) {
225:                    // expect error because of malformed url
226:                    assertSQLState("XJ028", e);
227:                }
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.