1 21 22 package org.apache.derbyTesting.functionTests.tests.i18n; 23 24 import org.apache.derbyTesting.junit.BaseTestCase; 25 import org.apache.derby.shared.common.reference.SQLState; 26 import org.apache.derby.shared.common.reference.MessageId; 27 28 import java.util.HashSet ; 29 import java.lang.reflect.Field ; 30 import java.util.ResourceBundle ; 31 import java.util.Locale ; 32 import java.util.Iterator ; 33 34 42 public class MessageBundleTest extends BaseTestCase { 43 public MessageBundleTest(String name) { 44 super(name); 45 } 46 47 static HashSet sqlStateIds = new HashSet (); 49 static HashSet messageIdIds = new HashSet (); 50 static HashSet messageBundleIds = new HashSet (); 51 52 static { 53 try { 54 loadClassIds(SQLState.class, sqlStateIds); 56 57 loadClassIds(MessageId.class, messageIdIds); 59 60 loadMessageBundleIds(); 62 } catch ( Exception e ) { 63 e.printStackTrace(); 64 throw new RuntimeException (e.getMessage()); 65 } 66 } 67 68 static void loadClassIds(Class idclass, HashSet set) throws Exception { 69 Field [] fields = idclass.getFields(); 70 71 int length = fields.length; 72 for ( int i = 0; i < length ; i++ ) 73 { 74 String id = (String )fields[i].get(null); 75 76 if ( id.length() == 2 ) { 77 continue; 79 } 80 81 if ( id.equals("close.C.1") ) continue; 84 if ( id.equals("rwupd" ) ) continue; 85 if ( id.equals("02502" ) ) continue; 86 if ( id.equals("XSAX0") ) continue; 87 88 if ( ! set.add(id) ) 89 { 90 System.err.println("ERROR: The id " + id + 91 " was found twice in " + idclass.getName()); 92 } 93 } 94 } 95 96 100 static void loadMessageBundleIds() throws Exception { 101 ResourceBundle bundle; 102 103 int numBundles = 50; 106 107 for ( int i=0 ; i < numBundles ; i++ ) { 108 loadMessageBundle(i); 109 } 110 } 111 112 static void loadMessageBundle(int index) { 113 String bundleName = "org.apache.derby.loc.m" + index; 114 115 ResourceBundle bundle = 116 ResourceBundle.getBundle(bundleName, Locale.ENGLISH); 117 118 java.util.Enumeration keys = bundle.getKeys(); 119 120 while ( keys.hasMoreElements() ) { 121 String key = (String )keys.nextElement(); 122 123 if ( ! messageBundleIds.add(key) ) { 124 System.err.println("ERROR: the key " + key + 125 " exists twice in messages_en.properties"); 126 } 127 } 128 } 129 130 134 public void testSQLStateOrphanedIds() throws Exception { 135 Iterator it = sqlStateIds.iterator(); 136 137 while ( it.hasNext() ) { 138 String sqlStateId = (String )it.next(); 139 140 if ( ! messageBundleIds.contains(sqlStateId) ) { 141 System.err.println("ERROR: Message id " + sqlStateId + 144 " in SQLState.java was not found in" + 145 " messages_en.properties"); 146 } 147 } 148 } 149 150 154 public void testMessageIdOrphanedIds() throws Exception { 155 Iterator it = messageIdIds.iterator(); 156 157 while ( it.hasNext() ) { 158 String sqlStateId = (String )it.next(); 159 160 if ( ! messageBundleIds.contains(sqlStateId) ) { 161 System.err.println("ERROR: Message id " + sqlStateId + 164 " in MessageId.java was not found in" + 165 " messages_en.properties"); 166 } 167 } 168 } 169 170 174 public void testMessageBundleOrphanedMessages() throws Exception { 175 Iterator it = messageBundleIds.iterator(); 176 177 while (it.hasNext() ) { 178 String msgid = (String )it.next(); 179 180 if ( sqlStateIds.contains(msgid)) { 181 continue; 182 } 183 184 if ( messageIdIds.contains(msgid)) { 185 continue; 186 } 187 188 System.err.println("WARNING: Message id " + msgid + 191 " in messages_en.properties is not " + 192 "referenced in either SQLState.java or MessageId.java"); 193 } 194 } 195 } 196 | Popular Tags |