Author: closettop_nightlybuild Date: 2012-06-21 22:49:50-0700 New Revision: 19889
Added: trunk/tools/test-i18n-properties/ trunk/tools/test-i18n-properties/.gitignore trunk/tools/test-i18n-properties/pom.xml trunk/tools/test-i18n-properties/src/ trunk/tools/test-i18n-properties/src/org/ trunk/tools/test-i18n-properties/src/org/argouml/ trunk/tools/test-i18n-properties/src/org/argouml/i18n/ trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java Log: Common part for test of i18n files. Added a test case to be parameterized with all property bundles to be tested. Submitted-by: Linus Tolke Change-Id: Idcc51f3e7b1c40fbbb2215fe9e5c96c5f3c55294 Added: trunk/tools/test-i18n-properties/.gitignore Url: http://argouml.tigris.org/source/browse/argouml/trunk/tools/test-i18n-properties/.gitignore?view=markup&pathrev=19889 ============================================================================== --- (empty file) +++ trunk/tools/test-i18n-properties/.gitignore 2012-06-21 22:49:50-0700 @@ -0,0 +1 @@ +/target Added: trunk/tools/test-i18n-properties/pom.xml Url: http://argouml.tigris.org/source/browse/argouml/trunk/tools/test-i18n-properties/pom.xml?view=markup&pathrev=19889 ============================================================================== --- (empty file) +++ trunk/tools/test-i18n-properties/pom.xml 2012-06-21 22:49:50-0700 @@ -0,0 +1,36 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.argouml</groupId> + <artifactId>parentpom</artifactId> + <version>0.35.2</version> + <relativePath>../maven/parentpom.xml</relativePath> + </parent> + + <artifactId>test-i18n-properties</artifactId> + <version>0.35.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.8.2</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + </dependencies> + + <name>test-i18n-properties</name> + <description> +This is a project with test cases for internationalization. + </description> +</project> Added: trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java?view=markup&pathrev=19889 ============================================================================== --- (empty file) +++ trunk/tools/test-i18n-properties/src/org/argouml/i18n/CheckKey.java 2012-06-21 22:49:50-0700 @@ -0,0 +1,136 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2012 Contributors - see below + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Linus Tolke + ******************************************************************************* + */ + +package org.argouml.i18n; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.MissingResourceException; + +import static org.junit.Assert.*; +import org.junit.Test; + + +/** + * Checks the contents of the internationalization property files. + * + * This is a test case for property files. + */ +public abstract class CheckKey { + /** + * Create the list of objects to test. + * + * @param currentLocale the Locale to test. + * @return a Collection of arrays of Objects. + */ + public static Collection<Object[]> getKeysFor(Locale currentLocale) { + Collection<Object[]> retval = new ArrayList(); + for (String bundleName : Arrays.asList( + "aboutbox", + "action", + "button", + "checkbox", + "checklist", + "combobox", + "critics", + "dialog", + "filechooser", + "label", + "menu", + "message", + "misc", + "mnemonic", + "optionpane", + "parsing", + "profile", + "statusmsg", + "tab", + "UMLResourceBundle", + "wfr", + "cpp" // from cpp project + )) { + try { + ResourceBundle labels = + ResourceBundle.getBundle("org.argouml.i18n." + bundleName, + currentLocale); + ResourceBundle rootLabels = + ResourceBundle.getBundle("org.argouml.i18n." + bundleName, + Locale.ROOT); + for (String key : labels.keySet()) { + retval.add(new Object[] { key, currentLocale, labels, rootLabels }); + } + } catch (MissingResourceException e) { + // There is no such file. + } + } + + return retval; + } + + private String key; + private Locale currentLocale; + private ResourceBundle labels; + private ResourceBundle rootLabels; + + public CheckKey(String theKey, Locale theLocale, + ResourceBundle theLabels, + ResourceBundle theRootLabels) { + key = theKey; + currentLocale = theLocale; + labels = theLabels; + rootLabels = theRootLabels; + } + + /** + * Check that the key exists among the base keys. + */ + @Test public void localizedKeyIsInOrigin() { + try { + assertTrue("Key " + key + " is in use by the underlying application.", + rootLabels.getString(key) instanceof String); + } catch (MissingResourceException e) { + fail("Key " + key + " does not exist in root bundle."); + } + } + + /** + * Check that the key is localized. + */ + @Test public void keyIsLocalized() { + assertTrue("Key " + key + " localized for " + currentLocale + ".", + labels.getString(key) != rootLabels.getString(key)); + } + + /** + * Check the validity of the localized contents. + */ + @Test public void valueValid() { + String str = labels.getString(key); + + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) == '\n') { + continue; + } + if (str.charAt(i) >= 32 && str.charAt(i) < 128) { + continue; + } + fail("Char " + i + " of key " + key + " is " + + str.charAt(i) + + " outside of allowed range in locale " + + currentLocale + "."); + } + } +} ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2972567 To unsubscribe from this discussion, e-mail: [[email protected]].
