📄 defaultpropertiestestlibrary.java
字号:
// jTDS JDBC Driver for Microsoft SQL Server and Sybase// Copyright (C) 2004 The jTDS Project//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//package net.sourceforge.jtds.test;import java.util.Properties;import junit.framework.Test;import junit.framework.TestCase;import net.sourceforge.jtds.jdbc.DefaultProperties;import net.sourceforge.jtds.jdbc.Driver;import net.sourceforge.jtds.jdbc.Messages;/** * Library for testing default properties. * <p/> * Uses a {@link DefaultPropertiesTester} object to test different methods * in different classes. * <p/> * To extend this class, the programmer must implement the following items: * <ol> * <li>Set the {@link #tester} field in a <code>public</code> default * constructor that takes no arguments.</li> * <li>A <code>public static Test suite()</code> method that takes one or more * arguments. (The {@link #suite()} method in this class should * <em>not</em> be overridden.)</li> * </ol> * * @author David D. Kilzer * @version $Id: DefaultPropertiesTestLibrary.java,v 1.19 2005/06/16 09:32:27 alin_sinpalean Exp $ */public abstract class DefaultPropertiesTestLibrary extends TestCase { /** Test JDBC URL for SQL Server. */ private static final String URL_SQLSERVER = "jdbc:jtds:" + DefaultProperties.SERVER_TYPE_SQLSERVER + "://servername"; /** Test JDBC URL for Sybase. */ private static final String URL_SYBASE = "jdbc:jtds:" + DefaultProperties.SERVER_TYPE_SYBASE + "://servername"; /** Object used to run all of the tests. */ private DefaultPropertiesTester tester; /** If true, only run tests for SQL Server, not Sybase. */ private boolean onlySqlServerTests = false; /** If true, only run tests for TDS 7.0. */ private boolean onlyTds70Tests = false; /** * Provides a null test suite so that JUnit will not try to instantiate * this class directly. * * @return The test suite (always <code>null</code>). */ public static final Test suite() { return null; } /** * Default constructor. * <p/> * The extender of this class is required to set the {@link #tester} * field in a <code>public</code> default constructor. */ public DefaultPropertiesTestLibrary() { } /** * Test the <code>serverType</code> property. * <p/> * Different values are set depending on whether SQL Server or * Sybase is used. */ public void test_serverType() { String fieldName = "serverType"; String messageKey = Driver.SERVERTYPE; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, String.valueOf(Driver.SQLSERVER)); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, String.valueOf(Driver.SYBASE)); } } /** * Test the <code>tds</code> (version) property. */ public void test_tds() { String fieldName = "tdsVersion"; String messageKey = Driver.TDS; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, DefaultProperties.TDS_VERSION_80); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, DefaultProperties.TDS_VERSION_50); } } /** * Test the <code>portNumber</code> property. * <p/> * Different values are set depending on whether SQL Server or * Sybase is used. */ public void test_portNumber() { String fieldName = "portNumber"; String messageKey = Driver.PORTNUMBER; assertDefaultPropertyByServerType( URL_SQLSERVER, messageKey, fieldName, DefaultProperties.PORT_NUMBER_SQLSERVER); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType( URL_SYBASE, messageKey, fieldName, DefaultProperties.PORT_NUMBER_SYBASE); } } /** * Test the <code>databaseName</code> property. */ public void test_databaseName() { String fieldName = "databaseName"; String messageKey = Driver.DATABASENAME; String expectedValue = DefaultProperties.DATABASE_NAME; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>appName</code> property. */ public void test_appName() { String fieldName = "appName"; String messageKey = Driver.APPNAME; String expectedValue = DefaultProperties.APP_NAME; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>lastUpdateCount</code> property. */ public void test_lastUpdateCount() { String fieldName = "lastUpdateCount"; String messageKey = Driver.LASTUPDATECOUNT; String expectedValue = DefaultProperties.LAST_UPDATE_COUNT; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>lobBuffer</code> property. */ public void test_lobBuffer() { String fieldName = "lobBuffer"; String messageKey = Driver.LOBBUFFER; String expectedValue = DefaultProperties.LOB_BUFFER_SIZE; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>loginTimeout</code> property. */ public void test_loginTimeout() { String fieldName = "loginTimeout"; String messageKey = Driver.LOGINTIMEOUT; String expectedValue = DefaultProperties.LOGIN_TIMEOUT; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>macAddress</code> property. */ public void test_macAddress() { String fieldName = "macAddress"; String messageKey = Driver.MACADDRESS; String expectedValue = DefaultProperties.MAC_ADDRESS; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>namedPipe</code> property. */ public void test_namedPipe() { String fieldName = "namedPipe"; String messageKey = Driver.NAMEDPIPE; String expectedValue = DefaultProperties.NAMED_PIPE; assertDefaultPropertyByServerType(URL_SQLSERVER, messageKey, fieldName, expectedValue); if (!isOnlySqlServerTests()) { assertDefaultPropertyByServerType(URL_SYBASE, messageKey, fieldName, expectedValue); } } /** * Test the <code>packetSize</code> property. */ public void test_packetSize() { String fieldName = "packetSize"; String messageKey = Driver.PACKETSIZE; if (!isOnlyTds70Tests()) { String expectedValue = DefaultProperties.PACKET_SIZE_42_50; assertDefaultPropertyByTdsVersion( URL_SQLSERVER, DefaultProperties.TDS_VERSION_42, messageKey, fieldName, expectedValue); assertDefaultPropertyByTdsVersion( URL_SYBASE, DefaultProperties.TDS_VERSION_50, messageKey, fieldName, expectedValue); } String expectedValue = DefaultProperties.PACKET_SIZE_70_80; assertDefaultPropertyByTdsVersion( URL_SQLSERVER, DefaultProperties.TDS_VERSION_70, messageKey, fieldName, expectedValue); if (!isOnlyTds70Tests()) { assertDefaultPropertyByTdsVersion( URL_SQLSERVER, DefaultProperties.TDS_VERSION_80, messageKey, fieldName, expectedValue); } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -