1 package org.apache.fulcrum.localization;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.fail;
24
25 import java.util.Locale;
26 import java.util.MissingResourceException;
27
28 import org.apache.fulcrum.testcontainer.BaseUnit5Test;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35
36
37
38
39
40 public class LocalizationTest extends BaseUnit5Test
41 {
42
43 private LocalizationService localizationService = null;
44
45 @BeforeEach
46 public void setUp() throws Exception
47 {
48 localizationService = (LocalizationService) lookup(LocalizationService.ROLE);
49 }
50
51
52
53
54
55
56 @Test
57 public void testLocalization() throws Exception
58 {
59
60 String s = localizationService.getString(null, null, "key1");
61 assertEquals("value1", s, "Unable to retrieve localized text for locale: default");
62
63 s = localizationService.getString(null, new Locale("en", "US"), "key2");
64 assertEquals("value2", s, "Unable to retrieve localized text for locale: en-US");
65
66 s = localizationService.getString("org.apache.fulcrum.localization.BarBundle", new Locale("ko", "KR"), "key3");
67 assertEquals(s, "[ko] value3", "Unable to retrieve localized text for locale: ko-KR");
68
69 try
70 {
71 localizationService.getString("DoesNotExist", new Locale("ko", ""), "key1");
72 fail();
73 }
74 catch (MissingResourceException expectedFailure)
75 {
76
77 }
78 catch( Throwable e )
79 {
80
81 fail();
82 }
83
84
85
86 s = localizationService.getString(null, new Locale("ko", "KR"), "key4");
87 assertEquals(s, "value4", "Unable to retrieve localized text for locale: default");
88
89 try
90 {
91 localizationService.getString(null, null, "NoSuchKey");
92 fail();
93 }
94 catch (MissingResourceException expectedFailure)
95 {
96
97 }
98 }
99
100 @Test
101 public void testGetString()
102 {
103 String key1 = "key1";
104 String value1 = "value1";
105 String key2 = "key2";
106 String value2 = "value2";
107 String key3 = "key3";
108 String value3 = "value3";
109 String key4 = "key4";
110 String value4 = "value4";
111
112 assertEquals(value1, localizationService.getString(key1));
113 assertEquals(value2, localizationService.getString(key2));
114 assertEquals(value3, localizationService.getString(key3));
115 assertEquals(value4, localizationService.getString(key4));
116
117 }
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 }