View Javadoc
1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.l10n.service;
16  
17  import static org.junit.Assert.*;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.collections.map.HashedMap;
23  import org.junit.Test;
24  import org.junit.runner.RunWith;
25  import org.kuali.mobility.l10n.entity.LocalisedString;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.beans.factory.annotation.Qualifier;
28  import org.springframework.test.annotation.DirtiesContext;
29  import org.springframework.test.context.ContextConfiguration;
30  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31  
32  /**
33   * A unit test for the localisation service
34   * @author Kuali Mobility Team (mobility.collab@kuali.org)
35   * @since 
36   */
37  @RunWith(SpringJUnit4ClassRunner.class)
38  @DirtiesContext
39  @ContextConfiguration("classpath:/LocalisationSpringBeans.xml")
40  public class LocalisationServiceTest {
41  
42  	private static final String EN = "en";
43  	private static final String AF = "af";
44  	private static final String MSG_AF = "Afrikaans is die beste";
45  	private static final String MSG_EN = "English is the best";
46  	private static final String MSG_CODE = "my.message";
47  	private static final String MSG2_AF = "Afrikaans is die pad on te stap";
48  	private static final String MSG2_EN = "English is the way to go";
49  	
50  	/**
51  	 * A reference to the <code>LocalisationService</code>.
52  	 */
53  	@Autowired
54  	@Qualifier(value="localisationService")
55  	private LocalisationService localisationService;
56  	
57  	/**
58  	 * Test that we can save a localised String
59  	 */
60  	@Test
61  	public void testPersist() {
62  		localisationService.saveLocalisedString(MSG_CODE, getDummyStrings());
63  	}
64  	
65  	/**
66  	 * Test that we can save a localised Strings and get back what we are expecting
67  	 */
68  	@Test
69  	public void testPersistAndRetrieve() {
70  		localisationService.saveLocalisedString(MSG_CODE, getDummyStrings());
71  		
72  		LocalisedString string = localisationService.getLocalisedString(MSG_CODE, EN);
73  		assertEquals(MSG_EN, string.getContent());
74  		
75  		string = localisationService.getLocalisedString(MSG_CODE, AF);
76  		assertEquals(MSG_AF, string.getContent());
77  	}
78  	
79  	/**
80  	 * Test that we can update a persisted localised string
81  	 */
82  	@Test
83  	public void testUpdateLocalisedString(){
84  		localisationService.saveLocalisedString(MSG_CODE, getDummyStrings());
85  		localisationService.saveLocalisedString(MSG_CODE, getDummyStrings2());
86  		
87  		LocalisedString string = localisationService.getLocalisedString(MSG_CODE, EN);
88  		assertEquals(MSG2_EN, string.getContent());
89  		
90  		string = localisationService.getLocalisedString(MSG_CODE, AF);
91  		assertEquals(MSG2_AF, string.getContent());
92  	}
93  	
94  	
95  	private Map<String, String> getDummyStrings(){
96  		Map<String, String> localisedStrings = new HashMap<String, String>();
97  		localisedStrings.put(EN, MSG_EN);
98  		localisedStrings.put(AF, MSG_AF);
99  		return localisedStrings;
100 	}
101 	
102 	private Map<String, String> getDummyStrings2(){
103 		Map<String, String> localisedStrings = new HashMap<String, String>();
104 		localisedStrings.put(EN, MSG2_EN);
105 		localisedStrings.put(AF, MSG2_AF);
106 		return localisedStrings;
107 	}
108 
109 }