dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15711
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5763: I18n db testing
------------------------------------------------------------
revno: 5763
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-01-20 10:47:13 +0100
message:
I18n db testing
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java
resources/sql/integritychecks.sql
--
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-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-19 14:20:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-20 09:47:13 +0000
@@ -84,7 +84,7 @@
{
if ( isCollection( object ) )
{
- internationaliseCollection( (Collection<?>) object );
+ internationaliseCollection( (Collection<?>) object, localeManager.getCurrentLocale() );
}
else
{
@@ -129,11 +129,6 @@
}
}
- private void internationaliseCollection( Collection<?> objects )
- {
- internationaliseCollection( objects, localeManager.getCurrentLocale() );
- }
-
private void internationaliseCollection( Collection<?> objects, Locale locale )
{
if ( objects == null || objects.size() == 0 || DHIS_STANDARD_LOCALE.equals( locale ) )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2012-01-15 08:44:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2012-01-20 09:47:13 +0000
@@ -259,8 +259,8 @@
executeSql( "ALTER TABLE chart DROP COLUMN size" );
executeSql( "ALTER TABLE chart DROP COLUMN verticallabels" );
executeSql( "ALTER TABLE chart DROP COLUMN horizontalplotorientation" );
- executeSql( "ALTER TABLE chart ADD COLUMN targetline boolean NOT NULL DEFAULT false");
- executeSql( "ALTER TABLE chart ADD COLUMN hidesubtitle boolean NOT NULL DEFAULT false");
+ executeSql( "ALTER TABLE chart ADD COLUMN targetline boolean NOT NULL DEFAULT false" );
+ executeSql( "ALTER TABLE chart ADD COLUMN hidesubtitle boolean NOT NULL DEFAULT false" );
executeSql( "ALTER TABLE chart DROP COLUMN monthsLastYear" );
executeSql( "ALTER TABLE chart DROP COLUMN quartersLastYear" );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java 2012-01-19 11:43:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/i18n/I18nServiceTest.java 2012-01-20 09:47:13 +0000
@@ -27,14 +27,27 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.mock.MockLocaleManager;
import org.junit.Before;
import org.junit.Test;
/**
- * @author Oyvind Brucker
+ * @author Lars Helge Overland
*/
public class I18nServiceTest
extends DhisSpringTest
@@ -55,6 +68,8 @@
localeManager = new MockLocaleManager();
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+
setDependency( i18nService, "localeManager", localeManager );
}
@@ -66,6 +81,116 @@
public void testUpdateTranslation()
throws Exception
{
-
+ Locale locale = Locale.FRANCE;
+ String className = DataElement.class.getSimpleName();
+
+ DataElement dataElementA = createDataElement( 'A' );
+ int idA = dataElementService.addDataElement( dataElementA );
+
+ Map<String, String> translationsA = new HashMap<String, String>();
+ translationsA.put( "name", "frenchNameA" );
+ translationsA.put( "shortName", "frenchShortNameA" );
+ translationsA.put( "description", "frenchDescriptionA" );
+
+ i18nService.updateTranslation( className, idA, locale, translationsA );
+
+ Map<String, String> actual = i18nService.getTranslations( className, idA, locale );
+
+ assertNotNull( actual );
+ assertEquals( 3, actual.size() );
+ assertTrue( actual.keySet().contains( "name" ) );
+ assertTrue( actual.values().contains( "frenchNameA" ) );
+ }
+
+ @Test
+ public void testInternationaliseObject()
+ {
+ Locale locale = Locale.FRANCE;
+ String className = DataElement.class.getSimpleName();
+
+ DataElement dataElementA = createDataElement( 'A' );
+ int idA = dataElementService.addDataElement( dataElementA );
+
+ Map<String, String> translationsA = new HashMap<String, String>();
+ translationsA.put( "name", "frenchNameA" );
+ translationsA.put( "shortName", "frenchShortNameA" );
+ translationsA.put( "description", "frenchDescriptionA" );
+
+ i18nService.updateTranslation( className, idA, locale, translationsA );
+
+ assertEquals( "DataElementA", dataElementA.getDisplayName() );
+ assertEquals( "DataElementShortA", dataElementA.getDisplayShortName() );
+ assertEquals( "DataElementDescriptionA", dataElementA.getDisplayDescription() );
+
+ i18nService.localise( dataElementA, locale );
+
+ assertEquals( "frenchNameA", dataElementA.getDisplayName() );
+ assertEquals( "frenchShortNameA", dataElementA.getDisplayShortName() );
+ assertEquals( "frenchDescriptionA", dataElementA.getDisplayDescription() );
+ }
+
+ @Test
+ public void testInternationaliseCollection()
+ {
+ Locale locale = Locale.FRANCE;
+ String className = DataElement.class.getSimpleName();
+
+ DataElement dataElementA = createDataElement( 'A' );
+ int idA = dataElementService.addDataElement( dataElementA );
+
+ DataElement dataElementB = createDataElement( 'B' );
+ int idB = dataElementService.addDataElement( dataElementB );
+
+ DataElement dataElementC = createDataElement( 'C' );
+ int idC = dataElementService.addDataElement( dataElementC );
+
+ List<DataElement> elements = new ArrayList<DataElement>();
+ elements.add( dataElementA );
+ elements.add( dataElementB );
+ elements.add( dataElementC );
+
+ Map<String, String> translationsA = new HashMap<String, String>();
+ translationsA.put( "name", "frenchNameA" );
+ translationsA.put( "shortName", "frenchShortNameA" );
+ translationsA.put( "description", "frenchDescriptionA" );
+
+ Map<String, String> translationsB = new HashMap<String, String>();
+ translationsB.put( "name", "frenchNameB" );
+ translationsB.put( "shortName", "frenchShortNameB" );
+ translationsB.put( "description", "frenchDescriptionB" );
+
+ Map<String, String> translationsC = new HashMap<String, String>();
+ translationsC.put( "name", "frenchNameC" );
+ translationsC.put( "shortName", "frenchShortNameC" );
+ translationsC.put( "description", "frenchDescriptionC" );
+
+ i18nService.updateTranslation( className, idA, locale, translationsA );
+ i18nService.updateTranslation( className, idB, locale, translationsB );
+ i18nService.updateTranslation( className, idC, locale, translationsC );
+
+ i18nService.localise( elements, locale );
+
+ Iterator<DataElement> elementIter = elements.iterator();
+
+ assertEquals( "frenchNameA", elementIter.next().getDisplayName() );
+ assertEquals( "frenchNameB", elementIter.next().getDisplayName() );
+ assertEquals( "frenchNameC", elementIter.next().getDisplayName() );
+ }
+
+ @Test
+ public void testGetObjectPropertyValues()
+ {
+ DataElement dataElementA = createDataElement( 'A' );
+
+ Map<String, String> values = i18nService.getObjectTranslations( dataElementA );
+
+ assertNotNull( values );
+ assertEquals( 3, values.size() );
+ assertTrue( values.keySet().contains( "name" ) );
+ assertTrue( values.keySet().contains( "shortName" ) );
+ assertTrue( values.keySet().contains( "description" ) );
+ assertTrue( values.values().contains( "DataElementA" ) );
+ assertTrue( values.values().contains( "DataElementShortA" ) );
+ assertTrue( values.values().contains( "DataElementDescriptionA" ) );
}
}
\ No newline at end of file
=== modified file 'resources/sql/integritychecks.sql'
--- resources/sql/integritychecks.sql 2011-11-10 19:24:16 +0000
+++ resources/sql/integritychecks.sql 2012-01-20 09:47:13 +0000
@@ -45,6 +45,12 @@
where sc.datasetid=ds.datasetid)
order by ds.name, de.name;
+-- Get categories with category memberships
+
+select co.name, c.name from dataelementcategory c
+join categories_categoryoptions using(categoryid)
+join dataelementcategoryoption co using(categoryoptionid) order by co.name, c.name;
+
-- Get orgunit groups which an orgunit is member of
select * from orgunitgroup g
@@ -105,11 +111,11 @@
select * from categorycombo where categorycomboid not in (select distinct categorycomboid from categorycombos_categories);
--- Get category options present in more than one category
+-- Get category options with count of memberships in categories (should only be 1)
-select categoryoptionid, (
+select cc.categoryoptionid, co.name, (
select count(categoryoptionid) from categories_categoryoptions where categoryoptionid=cc.categoryoptionid )
-as categorycount from categories_categoryoptions as cc order by categorycount desc;
+as categorycount from categories_categoryoptions as cc join dataelementcategoryoption co on(cc.categoryoptionid=co.categoryoptionid) order by categorycount desc;
-- Get category option combos without data values (not an error)