~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-i18n/dhis-i18n-translationstore-hibernate/src/test/java/org/hisp/dhis/i18n/TranslationStoreTest.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.i18n;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 */
 
29
 
 
30
import java.util.Collection;
 
31
import java.util.Locale;
 
32
 
 
33
import org.hisp.dhis.DhisSpringTest;
 
34
import org.hisp.dhis.dataelement.DataElement;
 
35
import org.hisp.dhis.organisationunit.OrganisationUnit;
 
36
 
 
37
/**
 
38
 * @author Oyvind Brucker
 
39
 */
 
40
public class TranslationStoreTest extends DhisSpringTest
 
41
{
 
42
    private TranslationStore translationStore;
 
43
 
 
44
    // -------------------------------------------------------------------------
 
45
    // Set up/tear down
 
46
    // -------------------------------------------------------------------------
 
47
 
 
48
    @Override
 
49
    public void setUpTest()
 
50
    {
 
51
        translationStore = (TranslationStore) getBean( TranslationStore.ID );
 
52
    }
 
53
 
 
54
    // -------------------------------------------------------------------------
 
55
    // Testdata
 
56
    // -------------------------------------------------------------------------
 
57
 
 
58
    private int id1 = 0;
 
59
    private int id2 = 1;
 
60
 
 
61
    private String locale1 = Locale.UK.toString();
 
62
    private String locale2 = Locale.US.toString();
 
63
    private String locale3 = Locale.FRANCE.toString();
 
64
 
 
65
    private String className1 = OrganisationUnit.class.getName();
 
66
    private String className2 = DataElement.class.getName();
 
67
 
 
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" );
 
74
 
 
75
    // -------------------------------------------------------------------------
 
76
    // Tests
 
77
    // -------------------------------------------------------------------------
 
78
 
 
79
    public void testAddGetUpdateDelete()
 
80
        throws Exception
 
81
    {
 
82
        // Add
 
83
        translationStore.addTranslation( translation1a );
 
84
        translationStore.addTranslation( translation1b );
 
85
        translationStore.addTranslation( translation2a );
 
86
        translationStore.addTranslation( translation2b );
 
87
        translationStore.addTranslation( translation2c );
 
88
        translationStore.addTranslation( translation3 );
 
89
 
 
90
        // Get
 
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" );
 
95
 
 
96
        assertEquals( "orgunitss", savedTranslation1a.getValue() );
 
97
        assertEquals( "orgs", savedTranslation1b.getValue() );
 
98
        assertEquals( "dataelement1", savedTranslation2b.getValue() );
 
99
        assertEquals( "dataelement2", savedTranslation2c.getValue() );
 
100
 
 
101
        Collection<Translation> col = translationStore.getTranslations( className1, id1, Locale.UK );
 
102
 
 
103
        assertEquals( "Unexpected amount of translations received", 2, col.size() );
 
104
 
 
105
        // Update
 
106
        translation1a.setValue( "org-unitssz" );
 
107
        translation2c.setValue( "dataelement-2" );
 
108
 
 
109
        translationStore.updateTranslation( translation1a );
 
110
        translationStore.updateTranslation( translation2c );
 
111
 
 
112
        Translation savedTranslationAfterUpdate1 =
 
113
            translationStore.getTranslation( className1, id1, Locale.UK, "name" );
 
114
        Translation savedTranslationAfterUpdate2 =
 
115
            translationStore.getTranslation( className2, id2, Locale.US, "name" );
 
116
 
 
117
        assertEquals( "org-unitssz", savedTranslationAfterUpdate1.getValue() );
 
118
        assertEquals( "dataelement-2", savedTranslationAfterUpdate2.getValue() );
 
119
 
 
120
        // Delete
 
121
        translationStore.deleteTranslation( translation3 );
 
122
 
 
123
        Translation deletedTranslation = translationStore.getTranslation(className1, id1, Locale.FRANCE ,"name" );
 
124
 
 
125
        assertNull(deletedTranslation);
 
126
 
 
127
        translationStore.deleteTranslations(className1, id1);
 
128
 
 
129
        col = translationStore.getAllTranslations();
 
130
 
 
131
        assertEquals( "Unexpected amount of translations received after delete", 2, col.size() );
 
132
    }
 
133
 
 
134
    public void testGetAvailableLocales()
 
135
        throws Exception
 
136
    {
 
137
        translationStore.addTranslation( translation1a );
 
138
        translationStore.addTranslation( translation2a );
 
139
        translationStore.addTranslation( translation3 );
 
140
 
 
141
        Collection<Locale> locales = translationStore.getAvailableLocales();
 
142
 
 
143
        assertEquals( "Unexpected size of available locales", 3, locales.size() );
 
144
    }
 
145
}