db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davi...@apache.org
Subject svn commit: r410975 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/SqlException.java testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml
Date Thu, 01 Jun 2006 21:54:33 GMT
Author: davidvc
Date: Thu Jun  1 14:54:32 2006
New Revision: 410975

URL: http://svn.apache.org/viewvc?rev=410975&view=rev
Log:
DERBY-1186 - Add a new test that does a sanity check of our message ids,
looking for duplicates and orphans.  Not part of derbyall yet because
there are a number of failures I need to track down.  The failures will
be fixed as a separate JIRA

No test suites run, as this is a new test and has no interaction with
existing code.

This checkin also has a rider which is a small javadoc fix to 
SqlException.java

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=410975&r1=410974&r2=410975&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Thu Jun 
1 14:54:32 2006
@@ -162,9 +162,6 @@
      *      using initCause().  On JDK 1.3, since initCause() does not exist,
      *      a non-SQL exception can not be chained.  Instead, the exception class
      *      and message text is appended to the message for this exception.
-     *
-     * @return 
-     *      An instance of SqlException that you can throw to your heart's content.
      */
     public SqlException(LogWriter logwriter, 
         ClientMessageId msgid, Object[] args, Throwable cause)

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java?rev=410975&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/MessageBundleTest.java
Thu Jun  1 14:54:32 2006
@@ -0,0 +1,214 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.i18n.MessageBundleTest
+ 
+   Copyright (c) 2001, 2006 The Apache Software Foundation or its licensors, where applicable.
+ 
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+
+package org.apache.derbyTesting.functionTests.tests.i18n;
+
+import org.apache.derbyTesting.functionTests.util.BaseTestCase;
+import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.shared.common.reference.MessageId;
+
+import java.util.HashSet;
+import java.lang.reflect.Field;
+import java.util.ResourceBundle;
+import java.util.Locale;
+import java.util.Iterator;
+
+/**
+ * This class does everything we can to validate that the messages_en.properties
+ * file is in synch with SQLState.java and MessageId.java.  We want to make sure
+ * that message ids defined in SQLState and MessageId have matching messages
+ * in the messages properties file, and also find out if there are any messages
+ * that don't have matching ids in the SQLState and MessageId files.   The
+ * first is a bug, the second is something to be aware of.
+ */
+public class MessageBundleTest extends BaseTestCase {
+    public MessageBundleTest(String name) {
+        super(name);
+    }
+
+    // The list of ids.  We use a HashSet so we can detect duplicates easily
+    static HashSet sqlStateIds          = new HashSet();
+    static HashSet messageIdIds         = new HashSet();
+    static HashSet messageBundleIds     = new HashSet();
+    
+    static {
+        try {
+            // Load all the ids for the SQLState class
+            loadClassIds(SQLState.class, sqlStateIds);
+
+            // Load all the ids for the MessageId class
+            loadClassIds(MessageId.class, messageIdIds);
+
+            // Load all the ids for the messages_en properties file
+            loadMessageBundleIds();
+        } catch ( Exception e ) {
+            e.printStackTrace();
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+    
+    static void loadClassIds(Class idclass, HashSet set) throws Exception {
+        Field[] fields = idclass.getFields();
+        
+        int length = fields.length;
+        for ( int i = 0; i < length ; i++ )
+        {
+            String id = (String)fields[i].get(null);
+            
+            if ( id.length() == 2 ) {
+                // Skip past identifiers that are just categories
+                continue;
+            }
+            
+            if ( id.equals("close.C.1") ) {
+                // This one is not expected to have a message string
+                continue;
+            }
+            if ( ! set.add(id) )
+            {
+                System.err.println("ERROR: The id " + id + 
+                    " was found twice in " + idclass.getName());
+            }
+        }
+    }
+            
+    /** 
+     * Load all the message ids from messages_en.properties into a HashSet.
+     * This assumes its available on the classpath
+     */
+    static void loadMessageBundleIds() throws Exception {
+        ResourceBundle bundle;
+        
+        // The messages_*.properties files are split into fifty separate
+        // message bundle files.  We need to load each one in turn
+        int numBundles = 50;
+        
+        for ( int i=0 ; i < numBundles ; i++ ) {
+            loadMessageBundle(i);
+        }
+    }
+    
+    static void loadMessageBundle(int index) {
+        String bundleName = "org.apache.derby.loc.m" + index;
+        
+        ResourceBundle bundle = 
+            ResourceBundle.getBundle(bundleName, Locale.ENGLISH);
+
+        java.util.Enumeration keys = bundle.getKeys();
+
+        while ( keys.hasMoreElements() ) {
+            String key = (String)keys.nextElement();                
+
+            if ( ! messageBundleIds.add(key) ) {
+                System.err.println("ERROR: the key " + key +
+                    " exists twice in messages_en.properties");
+            }
+        }        
+    }
+
+    /**
+     * See if there are any message ids in SQLState.java that are
+     * not in the message bundle
+     */
+    public void testSQLStateOrphanedIds() throws Exception {
+        Iterator it = sqlStateIds.iterator();
+        boolean success = true;
+        
+        while ( it.hasNext() ) {
+            String sqlStateId = (String)it.next();
+            
+            if ( ! messageBundleIds.contains(sqlStateId) ) {
+                // Don't fail out on the first one, we want to catch
+                // all of them.  Just note there was a failure and continue
+                System.err.println("ERROR: Message id " + sqlStateId +
+                    " in SQLState.java was not found in" +
+                    " messages_en.properties");     
+                
+                success = false;
+             }
+        }
+
+        if ( ! success ) {
+            fail("One or more message ids in MessageId.java was not found " +
+                "in messages_en.properties");
+        }
+    }
+
+    /**
+     * See if there are any message ids in MessageId.java not in
+     * the message bundle
+     */
+    public void testMessageIdOrphanedIds() throws Exception {
+        Iterator it = messageIdIds.iterator();
+        boolean success = true;
+        
+        while ( it.hasNext() ) {
+            String sqlStateId = (String)it.next();
+            
+            if ( ! messageBundleIds.contains(sqlStateId) ) {
+                // Don't fail out on the first one, we want to catch
+                // all of them.  Just note there was a failure and continue
+                System.err.println("ERROR: Message id " + sqlStateId +
+                    " in MessageId.java was not found in" +
+                    " messages_en.properties");    
+                
+                success = false;
+             }
+        }
+        
+        if ( ! success ) {
+            fail("One or more message ids in MessageId.java was not found " +
+                "in messages_en.properties");
+        }
+    }
+     
+    /**
+     * See if there are any message ids in the message bundle that
+     * are <b>not</b> in SQLState.java or MessageId.java
+     */
+    public void testMessageBundleOrphanedMessages() throws Exception {
+        Iterator it = messageBundleIds.iterator();
+        boolean success = true;
+        
+        while (it.hasNext() ) {
+            String msgid = (String)it.next();
+            
+            if ( sqlStateIds.contains(msgid)) {
+                continue;
+            }
+            
+            if ( messageIdIds.contains(msgid)) {
+                continue;
+            }
+            
+            // Don't fail out on the first one, we want to catch
+            // all of them.  Just note there was a failure and continue
+            System.err.println("WARNING: Message id " + msgid + 
+                " in messages_en.properties is not " +
+                "referenced in either SQLState.java or MessageId.java");
+            success = false;
+        }
+        
+        if ( ! success ) {
+            fail("One or more message ids in messages_en.properties was not " +
+                "found in SQLState.java or MessageId.java");
+        }
+    }
+}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml?rev=410975&r1=410974&r2=410975&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/i18n/build.xml
Thu Jun  1 14:54:32 2006
@@ -50,7 +50,6 @@
   </target>
 
   <target name="compile">
-    <echo message="junit is ${junit}"/>
     <javac
       source="1.3"
       target="1.3"



Mime
View raw message