001: // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: // Copyright (C) 2005 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 junit.framework.Test;
021: import junit.framework.TestSuite;
022: import net.sourceforge.jtds.jdbc.Messages;
023: import java.util.Enumeration;
024: import java.util.ResourceBundle;
025:
026: /**
027: * Unit tests for the <code>Messages.properties</code> file.
028: *
029: * @author David D. Kilzer
030: * @version $Id: MessagesPropertiesUnitTest.java,v 1.3 2005/09/23 21:44:08 ddkilzer Exp $
031: */
032: public class MessagesPropertiesUnitTest extends UnitTestBase {
033:
034: /**
035: * Construct a test suite for this class.
036: *
037: * @return The test suite to run.
038: */
039: public static Test suite() {
040:
041: final TestSuite testSuite = new TestSuite(
042: MessagesPropertiesUnitTest.class.getName());
043:
044: final ResourceBundle messages = (ResourceBundle) invokeStaticMethod(
045: Messages.class, "loadResourceBundle", new Class[] {},
046: new Object[] {});
047: final Enumeration keysEnumeration = messages.getKeys();
048:
049: while (keysEnumeration.hasMoreElements()) {
050: String key = (String) keysEnumeration.nextElement();
051: if (key.startsWith("prop.desc.")) {
052: final String propertyName = key.substring("prop.desc."
053: .length());
054: testSuite.addTest(new TestDescriptionHasProperty(
055: propertyName, messages));
056: } else if (key.startsWith("prop.")) {
057: final String propertyName = key.substring("prop."
058: .length());
059: testSuite.addTest(new TestPropertyHasDescription(
060: propertyName, messages));
061: }
062: }
063:
064: return testSuite;
065: }
066:
067: /**
068: * Constructor.
069: *
070: * @param name The name of the test.
071: */
072: public MessagesPropertiesUnitTest(final String name) {
073: super (name);
074: }
075:
076: /**
077: * Tests that a given description key has a matching property key in
078: * <code>Messages.properties</code>.
079: */
080: public static class TestDescriptionHasProperty extends UnitTestBase {
081:
082: private final ResourceBundle messages;
083: private final String property;
084:
085: /**
086: * Constructor.
087: *
088: * @param property The property name to test.
089: * @param messages The resource bundle containing all of the messages.
090: */
091: public TestDescriptionHasProperty(String property,
092: ResourceBundle messages) {
093: super ("testDescriptionHasProperty_" + property);
094: this .property = property;
095: this .messages = messages;
096: }
097:
098: /**
099: * Provides a null test suite so that JUnit will not try to instantiate this class directly.
100: *
101: * @return The test suite (always <code>null</code>).
102: */
103: public static final Test suite() {
104: return null;
105: }
106:
107: /**
108: * Runs the test that a given description key has a matching property key in
109: * <code>Messages.properties</code>.
110: *
111: * @throws Throwable on error.
112: */
113: protected void runTest() throws Throwable {
114: String property = (String) messages.getObject("prop."
115: + this .property);
116: assertTrue(property.trim().length() > 0);
117: }
118: }
119:
120: /**
121: * Tests that a given property key has a matching description key in
122: * <code>Messages.properties</code>.
123: */
124: public static class TestPropertyHasDescription extends UnitTestBase {
125:
126: private final ResourceBundle messages;
127: private final String property;
128:
129: /**
130: * Constructor.
131: *
132: * @param property The property name to test.
133: * @param messages The resource bundle containing all of the messages.
134: */
135: public TestPropertyHasDescription(String property,
136: ResourceBundle messages) {
137: super ("testPropertyHasDescription_" + property);
138: this .property = property;
139: this .messages = messages;
140: }
141:
142: /**
143: * Provides a null test suite so that JUnit will not try to instantiate this class directly.
144: *
145: * @return The test suite (always <code>null</code>).
146: */
147: public static final Test suite() {
148: return null;
149: }
150:
151: /**
152: * Runs the test that a given property key has a matching description key in
153: * <code>Messages.properties</code>.
154: *
155: * @throws Throwable on error.
156: */
157: protected void runTest() throws Throwable {
158: String description = (String) messages
159: .getObject("prop.desc." + this .property);
160: assertTrue(description.trim().length() > 0);
161: }
162: }
163: }
|