dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03018
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1014: Work in progress on new test class for i18n service.
------------------------------------------------------------
revno: 1014
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-11-10 01:02:57 +0100
message:
Work in progress on new test class for i18n service.
added:
dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTranslationTest.java
modified:
dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-09 23:22:20 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 00:02:57 +0000
@@ -332,7 +332,7 @@
String key = translationEntry.getKey();
String value = translationEntry.getValue();
- if ( value != null && value.trim().length() > 0 )
+ if ( value != null && !value.trim().isEmpty() )
{
Translation translation = translationService.getTranslation( className, id, locale, key );
@@ -352,9 +352,7 @@
public Map<String, String> getTranslations( String className, int id, Locale locale )
{
- Collection<Translation> translationsCol = translationService.getTranslations( className, id, locale );
-
- return convertTranslations( translationsCol );
+ return convertTranslations( translationService.getTranslations( className, id, locale ) );
}
// -------------------------------------------------------------------------
@@ -423,11 +421,13 @@
// -------------------------------------------------------------------------
/**
- * Returns property/value pairs of translations for one object matching id.
+ * Returns a map representing Translations for an object matching the given
+ * id where the key is the translation property and the value is the translation
+ * value.
*
- * @param translations Collection to search
- * @param id Object id
- * @return Map of property/value pairs
+ * @param translations Collection to search.
+ * @param id the object id.
+ * @return Map of property/value pairs.
*/
private Map<String, String> getTranslationsForObject( Collection<Translation> translations, int id )
{
@@ -445,10 +445,11 @@
}
/**
- * Returns property/value pairs of a collection of translations as a map
+ * Returns a map for a collection of Translations where the key is the
+ * translation property and the value is the translation value.
*
- * @param translations
- * @return Map containing translations
+ * @param translations the Collection of translations.
+ * @return Map containing translations.
*/
private Map<String, String> convertTranslations( Collection<Translation> translations )
{
@@ -466,11 +467,10 @@
}
/**
- * Converts the property to a i18n keystring
- * alternativeName produces alternative_name
+ * Converts the property to a i18n keystring alternativeName produces alternative_name.
*
- * @param propName string to parse
- * @return Modified string
+ * @param propName string to parse.
+ * @return the modified string.
*/
private String convertPropertyToKey( String propName )
{
@@ -494,10 +494,10 @@
}
/**
- * Test if an object is enabled for i18n
+ * Test if an object is enabled for i18n.
*
- * @param object Object to check
- * @return true if the object is enabled for i18n
+ * @param object Object to check.
+ * @return true if the object is enabled for i18n.
*/
private boolean isI18nObject( Object object )
{
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java 2009-11-09 23:22:20 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java 2009-11-10 00:02:57 +0000
@@ -82,7 +82,7 @@
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
-
+
@Test
public void testUpdateTranslation()
throws Exception
=== added file 'dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTranslationTest.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTranslationTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/test/java/org/hisp/dhis/i18n/I18nServiceTranslationTest.java 2009-11-10 00:02:57 +0000
@@ -0,0 +1,84 @@
+package org.hisp.dhis.i18n;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.i18n.locale.LocaleManager;
+import org.hisp.dhis.translation.TranslationService;
+import org.junit.Before;
+import org.junit.Test;
+
+public class I18nServiceTranslationTest
+ extends DhisSpringTest
+{
+ private I18nService i18nService;
+
+ private LocaleManager localeManager;
+
+ private TranslationService translationService;
+
+ private DataElement dataElementA;
+
+ private int dataElementIdA;
+
+ private Map<String, String> translationsA;
+
+ private Locale localeA = Locale.UK;
+
+ // -------------------------------------------------------------------------
+ // Fixture
+ // -------------------------------------------------------------------------
+
+ @Before
+ public void setUpTest()
+ {
+ i18nService = (I18nService) getBean( I18nService.ID );
+
+ localeManager = (LocaleManager) getBean( "org.hisp.dhis.i18n.locale.LocaleManagerDb" );
+
+ translationService = (TranslationService) getBean( TranslationService.ID );
+
+ localeManager.setCurrentLocale( localeA );
+
+ dataElementA = createDataElement( 'A' );
+ dataElementA.setId( dataElementIdA );
+
+ translationsA = new HashMap<String, String>();
+ translationsA.put( "name", "DataElementUkA" );
+ translationsA.put( "shortName", "ShortNameUkA" );
+ translationsA.put( "code", "CodeUkA" );
+ }
+
+ // -------------------------------------------------------------------------
+ // Tests
+ // -------------------------------------------------------------------------
+
+ @Test
+ public void updateTranslation()
+ {
+ // No existing translations exist
+
+ i18nService.updateTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, translationsA );
+
+ assertEquals( "DataElementUkA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "name" ).getValue() );
+ assertEquals( "ShortNameUkA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "shortName" ).getValue() );
+ assertEquals( "CodeUkA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "code" ).getValue() );
+
+ // There are existing translations
+
+ translationsA.put( "name", "DataElementUpdatedA" );
+ translationsA.put( "shortName", "ShortNameUpdatedA" );
+ translationsA.put( "code", "CodeUpdatedA" );
+
+ i18nService.updateTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, translationsA );
+
+ assertEquals( "DataElementUpdatedA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "name" ).getValue() );
+ assertEquals( "ShortNameUpdatedA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "shortName" ).getValue() );
+ assertEquals( "CodeUpdatedA", translationService.getTranslation( DataElement.class.getSimpleName(), dataElementIdA, localeA, "code" ).getValue() );
+ }
+}