1
package org.hisp.dhis.i18n;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.Collection;
31
import java.util.Locale;
33
import org.hisp.dhis.DhisSpringTest;
34
import org.hisp.dhis.dataelement.DataElement;
35
import org.hisp.dhis.organisationunit.OrganisationUnit;
38
* @author Oyvind Brucker
40
public class TranslationStoreTest extends DhisSpringTest
42
private TranslationStore translationStore;
44
// -------------------------------------------------------------------------
46
// -------------------------------------------------------------------------
49
public void setUpTest()
51
translationStore = (TranslationStore) getBean( TranslationStore.ID );
54
// -------------------------------------------------------------------------
56
// -------------------------------------------------------------------------
61
private String locale1 = Locale.UK.toString();
62
private String locale2 = Locale.US.toString();
63
private String locale3 = Locale.FRANCE.toString();
65
private String className1 = OrganisationUnit.class.getName();
66
private String className2 = DataElement.class.getName();
68
private Translation translation1a = new Translation( className1, id1, locale1, "name", "orgunitss" );
69
private Translation translation1b = new Translation( className1, id1, locale1, "shortName", "orgs" );
70
private Translation translation2a = new Translation( className1, id1, locale2, "name", "orgunitzz" );
71
private Translation translation2b = new Translation( className2, id1, locale2, "name", "dataelement1" );
72
private Translation translation2c = new Translation( className2, id2, locale2, "name", "dataelement2" );
73
private Translation translation3 = new Translation( className1, id1, locale3, "name", "orgunit" );
75
// -------------------------------------------------------------------------
77
// -------------------------------------------------------------------------
79
public void testAddGetUpdateDelete()
83
translationStore.addTranslation( translation1a );
84
translationStore.addTranslation( translation1b );
85
translationStore.addTranslation( translation2a );
86
translationStore.addTranslation( translation2b );
87
translationStore.addTranslation( translation2c );
88
translationStore.addTranslation( translation3 );
91
Translation savedTranslation1a = translationStore.getTranslation( className1, id1, Locale.UK, "name" );
92
Translation savedTranslation1b = translationStore.getTranslation( className1, id1, Locale.UK, "shortName" );
93
Translation savedTranslation2b = translationStore.getTranslation( className2, id1, Locale.US, "name" );
94
Translation savedTranslation2c = translationStore.getTranslation( className2, id2, Locale.US, "name" );
96
assertEquals( "orgunitss", savedTranslation1a.getValue() );
97
assertEquals( "orgs", savedTranslation1b.getValue() );
98
assertEquals( "dataelement1", savedTranslation2b.getValue() );
99
assertEquals( "dataelement2", savedTranslation2c.getValue() );
101
Collection<Translation> col = translationStore.getTranslations( className1, id1, Locale.UK );
103
assertEquals( "Unexpected amount of translations received", 2, col.size() );
106
translation1a.setValue( "org-unitssz" );
107
translation2c.setValue( "dataelement-2" );
109
translationStore.updateTranslation( translation1a );
110
translationStore.updateTranslation( translation2c );
112
Translation savedTranslationAfterUpdate1 =
113
translationStore.getTranslation( className1, id1, Locale.UK, "name" );
114
Translation savedTranslationAfterUpdate2 =
115
translationStore.getTranslation( className2, id2, Locale.US, "name" );
117
assertEquals( "org-unitssz", savedTranslationAfterUpdate1.getValue() );
118
assertEquals( "dataelement-2", savedTranslationAfterUpdate2.getValue() );
121
translationStore.deleteTranslation( translation3 );
123
Translation deletedTranslation = translationStore.getTranslation(className1, id1, Locale.FRANCE ,"name" );
125
assertNull(deletedTranslation);
127
translationStore.deleteTranslations(className1, id1);
129
col = translationStore.getAllTranslations();
131
assertEquals( "Unexpected amount of translations received after delete", 2, col.size() );
134
public void testGetAvailableLocales()
137
translationStore.addTranslation( translation1a );
138
translationStore.addTranslation( translation2a );
139
translationStore.addTranslation( translation3 );
141
Collection<Locale> locales = translationStore.getAvailableLocales();
143
assertEquals( "Unexpected size of available locales", 3, locales.size() );