Source Code Cross Referenced for DefaultPropertiesUnitTest.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » 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 JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002:        // Copyright (C) 2004 The jTDS Project
003:        //
004:        // This library is free software; you can redistribute it and/or
005:        // modify it under the terms of the GNU Lesser General Public
006:        // License as published by the Free Software Foundation; either
007:        // version 2.1 of the License, or (at your option) any later version.
008:        //
009:        // This library is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:        // Lesser General Public License for more details.
013:        //
014:        // You should have received a copy of the GNU Lesser General Public
015:        // License along with this library; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:        //
018:        package net.sourceforge.jtds.test;
019:
020:        import net.sourceforge.jtds.jdbc.DefaultProperties;
021:        import net.sourceforge.jtds.jdbc.Messages;
022:        import net.sourceforge.jtds.jdbc.Driver;
023:        import java.util.Properties;
024:        import java.util.Map;
025:        import java.util.HashMap;
026:
027:        /**
028:         * Unit tests for the {@link net.sourceforge.jtds.jdbc.DefaultProperties} class.
029:         *
030:         * @author David D. Kilzer
031:         * @version $Id: DefaultPropertiesUnitTest.java,v 1.9 2007/07/08 18:08:54 bheineman Exp $
032:         */
033:        public class DefaultPropertiesUnitTest extends UnitTestBase {
034:
035:            /**
036:             * Constructor.
037:             *
038:             * @param name The name of the test.
039:             */
040:            public DefaultPropertiesUnitTest(String name) {
041:                super (name);
042:            }
043:
044:            /**
045:             * Tests that
046:             * <code>DefaultProperties.addDefaultPropertyIfNotSet(java.util.Properties, java.lang.String, java.lang.String)</code>
047:             * sets a default property if the property is not already set.
048:             */
049:            public void test_addDefaultPropertyIfNotSet_PropertyNotSet() {
050:                final Properties properties = new Properties();
051:                final String key = Driver.DATABASENAME;
052:                final String defaultValue = "foobar";
053:                invokeStaticMethod(DefaultProperties.class,
054:                        "addDefaultPropertyIfNotSet", new Class[] {
055:                                Properties.class, String.class, String.class },
056:                        new Object[] { properties, key, defaultValue });
057:                assertEquals(defaultValue, properties.get(Messages.get(key)));
058:            }
059:
060:            /**
061:             * Tests that
062:             * <code>DefaultProperties.addDefaultPropertyIfNotSet(java.util.Properties, java.lang.String, java.lang.String)</code>
063:             * does <em>not</em> set a default property if the property is already set.
064:             */
065:            public void test_addDefaultPropertyIfNotSet_PropertyAlreadySet() {
066:                final Properties properties = new Properties();
067:                final String key = Driver.DATABASENAME;
068:                final String presetValue = "barbaz";
069:                final String defaultValue = "foobar";
070:                properties.setProperty(Messages.get(key), presetValue);
071:                invokeStaticMethod(DefaultProperties.class,
072:                        "addDefaultPropertyIfNotSet", new Class[] {
073:                                Properties.class, String.class, String.class },
074:                        new Object[] { properties, key, defaultValue });
075:                assertEquals(presetValue, properties.get(Messages.get(key)));
076:            }
077:
078:            /**
079:             * Tests that
080:             * <code>DefaultProperties.addDefaultPropertyIfNotSet(java.util.Properties, java.lang.String, java.lang.String, java.util.Map)</code>
081:             * does <em>not</em> set a default property if the <code>defaultKey</code> is not set.
082:             */
083:            public void test_addDefaultPropertyIfNotSet_DefaultKeyNotSet() {
084:                final Properties properties = new Properties();
085:                final String defaultKey = Driver.SERVERTYPE;
086:                final String key = Driver.PORTNUMBER;
087:                final HashMap defaults = new HashMap();
088:                invokeStaticMethod(DefaultProperties.class,
089:                        "addDefaultPropertyIfNotSet", new Class[] {
090:                                Properties.class, String.class, String.class,
091:                                Map.class }, new Object[] { properties, key,
092:                                defaultKey, defaults });
093:                assertEquals(0, properties.size());
094:            }
095:
096:            /**
097:             * Tests that
098:             * <code>DefaultProperties.addDefaultPropertyIfNotSet(java.util.Properties, java.lang.String, java.lang.String, java.util.Map)</code>
099:             * sets a default property if the property is not already set.
100:             */
101:            public void test_addDefaultPropertyIfNotSet_DefaultKeySet_PropertyNotSet() {
102:                final Properties properties = new Properties();
103:                final String defaultKey = Driver.SERVERTYPE;
104:                final String defaultKeyValue = "foobar";
105:                properties.put(Messages.get(defaultKey), defaultKeyValue);
106:                final String key = Driver.PORTNUMBER;
107:                final String defaultValue = "2004";
108:                final HashMap defaults = new HashMap();
109:                defaults.put(defaultKeyValue, defaultValue);
110:                invokeStaticMethod(DefaultProperties.class,
111:                        "addDefaultPropertyIfNotSet", new Class[] {
112:                                Properties.class, String.class, String.class,
113:                                Map.class }, new Object[] { properties, key,
114:                                defaultKey, defaults });
115:                assertEquals(defaultValue, properties.get(Messages.get(key)));
116:            }
117:
118:            /**
119:             * Tests that
120:             * <code>DefaultProperties.addDefaultPropertyIfNotSet(java.util.Properties, java.lang.String, java.lang.String, java.util.Map)</code>
121:             * does <em>not</em> set a default property if the property is already set.
122:             */
123:            public void test_addDefaultPropertyIfNotSet_DefaultKeySet_PropertyAlreadySet() {
124:                final Properties properties = new Properties();
125:                final String defaultKey = Driver.SERVERTYPE;
126:                final String defaultKeyValue = "foobar";
127:                properties.put(Messages.get(defaultKey), defaultKeyValue);
128:                final String key = Driver.PORTNUMBER;
129:                final String presetValue = "2020";
130:                properties.put(Messages.get(key), presetValue);
131:                final String defaultValue = "2004";
132:                final HashMap defaults = new HashMap();
133:                defaults.put(defaultKeyValue, defaultValue);
134:                invokeStaticMethod(DefaultProperties.class,
135:                        "addDefaultPropertyIfNotSet", new Class[] {
136:                                Properties.class, String.class, String.class,
137:                                Map.class }, new Object[] { properties, key,
138:                                defaultKey, defaults });
139:                assertEquals(presetValue, properties.get(Messages.get(key)));
140:            }
141:
142:            public void test_getServerType_intToString_Null() {
143:                final String message = "Did not return null for unknown server type ";
144:                final int[] testValues = new int[] { -99, -1, 0, 3, 99 };
145:                for (int i = 0; i < testValues.length; i++) {
146:                    assertNull(message + String.valueOf(testValues[i]),
147:                            DefaultProperties.getServerType(testValues[i]));
148:                }
149:            }
150:
151:            public void test_getServerType_intToString_SQLSERVER() {
152:                assertEquals(
153:                        "Server type for SQL Server did not map correctly",
154:                        DefaultProperties.SERVER_TYPE_SQLSERVER,
155:                        DefaultProperties.getServerType(Driver.SQLSERVER));
156:            }
157:
158:            public void test_getServerType_intToString_SYBASE() {
159:                assertEquals("Server type for Sybase did not map correctly",
160:                        DefaultProperties.SERVER_TYPE_SYBASE, DefaultProperties
161:                                .getServerType(Driver.SYBASE));
162:            }
163:
164:            public void test_getServerType_StringToInteger_Null() {
165:                final String message = "Did not return null for unknown server type: ";
166:                final String[] testValues = new String[] { null, "",
167:                        "SQLServer", "Sybase", "sibase", "sq1server" };
168:                for (int i = 0; i < testValues.length; i++) {
169:                    assertNull(message + String.valueOf(testValues[i]),
170:                            DefaultProperties.getServerType(testValues[i]));
171:                }
172:            }
173:
174:            public void test_getServerType_StringToInteger_SQLSERVER() {
175:                assertEquals(
176:                        "Server type for SQL Server did not map correctly",
177:                        new Integer(Driver.SQLSERVER),
178:                        DefaultProperties
179:                                .getServerType(DefaultProperties.SERVER_TYPE_SQLSERVER));
180:            }
181:
182:            public void test_getServerType_StringToInteger_SYBASE() {
183:                assertEquals(
184:                        "Server type for Sybase did not map correctly",
185:                        new Integer(Driver.SYBASE),
186:                        DefaultProperties
187:                                .getServerType(DefaultProperties.SERVER_TYPE_SYBASE));
188:            }
189:
190:            public void test_getTdsVersion_StringToInteger_Null() {
191:                final String message = "Did not return null for unknown TDS version: ";
192:                final String[] testValues = new String[] { null, "", "4.0",
193:                        "5.2", "0.0", "8:0" };
194:                for (int i = 0; i < testValues.length; i++) {
195:                    assertNull(message + String.valueOf(testValues[i]),
196:                            DefaultProperties.getTdsVersion(testValues[i]));
197:                }
198:            }
199:
200:            public void test_getTdsVersion_StringToInteger_TDS42() {
201:                assertEquals(
202:                        "Tds version for TDS 4.2 did not map correctly",
203:                        new Integer(Driver.TDS42),
204:                        DefaultProperties
205:                                .getTdsVersion(DefaultProperties.TDS_VERSION_42));
206:            }
207:
208:            public void test_getTdsVersion_StringToInteger_TDS50() {
209:                assertEquals(
210:                        "Tds version for TDS 5.0 did not map correctly",
211:                        new Integer(Driver.TDS50),
212:                        DefaultProperties
213:                                .getTdsVersion(DefaultProperties.TDS_VERSION_50));
214:            }
215:
216:            public void test_getTdsVersion_StringToInteger_TDS70() {
217:                assertEquals(
218:                        "Tds version for TDS 7.0 did not map correctly",
219:                        new Integer(Driver.TDS70),
220:                        DefaultProperties
221:                                .getTdsVersion(DefaultProperties.TDS_VERSION_70));
222:            }
223:
224:            public void test_getTdsVersion_StringToInteger_TDS80() {
225:                assertEquals(
226:                        "Tds version for TDS 8.0 did not map correctly",
227:                        new Integer(Driver.TDS80),
228:                        DefaultProperties
229:                                .getTdsVersion(DefaultProperties.TDS_VERSION_80));
230:            }
231:
232:            public void test_getNamedPipePath_DEFAULT() {
233:                assertEquals(
234:                        "Default named pipe path for default (0) did not map correctly",
235:                        DefaultProperties.NAMED_PIPE_PATH_SQLSERVER,
236:                        DefaultProperties.getNamedPipePath(0));
237:            }
238:
239:            public void test_getNamedPipePath_INVALID() {
240:                try {
241:                    DefaultProperties.getNamedPipePath(3);
242:                    fail("IllegalArgumentException was expected to be thrown");
243:                } catch (IllegalArgumentException expected) {
244:                }
245:            }
246:
247:            public void test_getNamedPipePath_SQLSERVER() {
248:                assertEquals(
249:                        "Default named pipe path for SQL Server did not map correctly",
250:                        DefaultProperties.NAMED_PIPE_PATH_SQLSERVER,
251:                        DefaultProperties
252:                                .getNamedPipePath(DefaultProperties
253:                                        .getServerType(
254:                                                DefaultProperties.SERVER_TYPE_SQLSERVER)
255:                                        .intValue()));
256:            }
257:
258:            public void test_getNamedPipePath_SYBASE() {
259:                assertEquals(
260:                        "Default named pipe path for Sybase did not map correctly",
261:                        DefaultProperties.NAMED_PIPE_PATH_SYBASE,
262:                        DefaultProperties.getNamedPipePath(DefaultProperties
263:                                .getServerType(
264:                                        DefaultProperties.SERVER_TYPE_SYBASE)
265:                                .intValue()));
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.