Source Code Cross Referenced for SetObjectUnsupportedTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbc4 » 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.jdbc4 
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.jdbc4;
021:
022:        import java.sql.Connection;
023:        import java.sql.PreparedStatement;
024:        import java.sql.SQLException;
025:        import java.sql.SQLFeatureNotSupportedException;
026:        import java.sql.Types;
027:        import junit.framework.Test;
028:        import junit.framework.TestSuite;
029:
030:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
031:
032:        /**
033:         * Tests that calling <code>setObject()</code> and <code>setNull()</code> with
034:         * <code>sqlTargetType</code> set to an unsupported type fails with
035:         * <code>SQLFeatureNotSupportedException</code>.
036:         *
037:         * <p> The test is run as part of <code>PreparedStatementTest</code>
038:         * and <code>CallableStatementTest</code>.
039:         */
040:        public class SetObjectUnsupportedTest extends BaseJDBCTestCase {
041:            /** Name and id of the target type used in the test. */
042:            private final TypeInfo typeInfo;
043:            /** Flag indicating whether the test should use a
044:             * CallableStatement instead of a PreparedStatement. */
045:            private final boolean callable;
046:
047:            /**
048:             * Creates a new <code>SetObjectUnsupportedTest</code> instance.
049:             *
050:             * @param name name of the test
051:             * @param typeInfo description of the target type to use in the test
052:             * @param callable if <code>true</code>, use a
053:             * <code>CallableStatement</code> instead of a
054:             * <code>PreparedStatement</code>.
055:             */
056:            private SetObjectUnsupportedTest(String name, TypeInfo typeInfo,
057:                    boolean callable) {
058:                super (name);
059:                this .typeInfo = typeInfo;
060:                this .callable = callable;
061:            }
062:
063:            /**
064:             * Returns the name of the test.
065:             */
066:            public String getName() {
067:                return super .getName() + "_" + typeInfo.name;
068:            }
069:
070:            /**
071:             * Prepares a <code>PreparedStatement</code> or a
072:             * <code>CallableStatement</code> to use in the test.
073:             *
074:             * @return a statement (prepared or callable)
075:             * @exception SQLException if a database error occurs
076:             */
077:            private PreparedStatement prepare() throws SQLException {
078:                String sql = "values (CAST (? AS VARCHAR(128)))";
079:                return callable ? prepareCall(sql) : prepareStatement(sql);
080:            }
081:
082:            /**
083:             * Test that <code>setObject()</code> with the specified
084:             * <code>sqlTargetType</code> throws
085:             * <code>SQLFeatureNotSupportedException</code>.
086:             *
087:             * @exception SQLException if a database error occurs
088:             */
089:            public void testUnsupportedSetObject() throws SQLException {
090:                PreparedStatement ps = prepare();
091:                try {
092:                    ps.setObject(1, null, typeInfo.type);
093:                    fail("No exception thrown.");
094:                } catch (SQLFeatureNotSupportedException e) {
095:                    // expected exception
096:                }
097:                ps.close();
098:            }
099:
100:            /**
101:             * Test that <code>setObject()</code> with the specified
102:             * <code>sqlTargetType</code> throws
103:             * <code>SQLFeatureNotSupportedException</code>.
104:             *
105:             * @exception SQLException if a database error occurs
106:             */
107:            public void testUnsupportedSetObjectWithScale() throws SQLException {
108:                PreparedStatement ps = prepare();
109:                try {
110:                    ps.setObject(1, null, typeInfo.type, 0);
111:                    fail("No exception thrown.");
112:                } catch (SQLFeatureNotSupportedException e) {
113:                    // expected exception
114:                }
115:                ps.close();
116:            }
117:
118:            /**
119:             * Test that <code>setNull()</code> with the specified
120:             * <code>sqlTargetType</code> throws
121:             * <code>SQLFeatureNotSupportedException</code>.
122:             *
123:             * @exception SQLException if a database error occurs
124:             */
125:            public void testUnsupportedSetNull() throws SQLException {
126:                PreparedStatement ps = prepare();
127:                try {
128:                    ps.setNull(1, typeInfo.type);
129:                    fail("No exception thrown.");
130:                } catch (SQLFeatureNotSupportedException e) {
131:                    // expected exception
132:                }
133:                ps.close();
134:            }
135:
136:            /**
137:             * Test that <code>setNull()</code> with the specified
138:             * <code>sqlTargetType</code> throws
139:             * <code>SQLFeatureNotSupportedException</code>.
140:             *
141:             * @exception SQLException if a database error occurs
142:             */
143:            public void testUnsupportedSetNullWithTypeName()
144:                    throws SQLException {
145:                PreparedStatement ps = prepare();
146:                try {
147:                    ps.setNull(1, typeInfo.type, typeInfo.name);
148:                    fail("No exception thrown.");
149:                } catch (SQLFeatureNotSupportedException e) {
150:                    // expected exception
151:                }
152:                ps.close();
153:            }
154:
155:            /**
156:             * The target types to test.
157:             */
158:            private static final TypeInfo[] TYPES = {
159:                    new TypeInfo("ARRAY", Types.ARRAY),
160:                    new TypeInfo("DATALINK", Types.DATALINK),
161:                    new TypeInfo("NCHAR", Types.NCHAR),
162:                    new TypeInfo("NCLOB", Types.NCLOB),
163:                    new TypeInfo("NVARCHAR", Types.NVARCHAR),
164:                    new TypeInfo("LONGNVARCHAR", Types.LONGNVARCHAR),
165:                    new TypeInfo("REF", Types.REF),
166:                    new TypeInfo("ROWID", Types.ROWID),
167:                    new TypeInfo("SQLXML", Types.SQLXML),
168:                    new TypeInfo("STRUCT", Types.STRUCT), };
169:
170:            /**
171:             * Build a test suite which tests <code>setObject()</code> with
172:             * each of the types in <code>TYPES</code>.
173:             *
174:             * @param callable if <code>true</code>, test with a
175:             * <code>CallableStatement</code>; otherwise, test with a
176:             * <code>PreparedStatement</code>
177:             * @return a test suite
178:             */
179:            static Test suite(boolean callable) {
180:                TestSuite suite = new TestSuite();
181:                for (TypeInfo typeInfo : TYPES) {
182:                    suite.addTest(new SetObjectUnsupportedTest(
183:                            "testUnsupportedSetObject", typeInfo, callable));
184:                    suite.addTest(new SetObjectUnsupportedTest(
185:                            "testUnsupportedSetObjectWithScale", typeInfo,
186:                            callable));
187:                    suite.addTest(new SetObjectUnsupportedTest(
188:                            "testUnsupportedSetNull", typeInfo, callable));
189:                    suite.addTest(new SetObjectUnsupportedTest(
190:                            "testUnsupportedSetNullWithTypeName", typeInfo,
191:                            callable));
192:                }
193:                return suite;
194:            }
195:
196:            /** Class with name and id for the target type used in a test. */
197:            private static class TypeInfo {
198:                final String name;
199:                final int type;
200:
201:                TypeInfo(String name, int type) {
202:                    this.name = name;
203:                    this.type = type;
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.