1
2
3
4
5
6
7
8
9
10
11
12
13
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
34
35
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
52
53 @Autowired
54 @Qualifier(value="localisationService")
55 private LocalisationService localisationService;
56
57
58
59
60 @Test
61 public void testPersist() {
62 localisationService.saveLocalisedString(MSG_CODE, getDummyStrings());
63 }
64
65
66
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
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 }