1 package org.apache.turbine.services.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.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.Mockito.mock;
26
27 import javax.servlet.ServletConfig;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 import org.apache.turbine.annotation.AnnotationProcessor;
32 import org.apache.turbine.services.TurbineServices;
33 import org.apache.turbine.services.rundata.RunDataService;
34 import org.apache.turbine.test.BaseTestCase;
35 import org.apache.turbine.util.RunData;
36 import org.apache.turbine.util.TurbineConfig;
37 import org.junit.AfterClass;
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41
42
43
44
45
46
47
48
49
50 public class LocalizationToolTest extends BaseTestCase
51 {
52 private static TurbineConfig tc = null;
53 private LocalizationTool lt;
54
55 @Before
56 public void initTool() throws Exception
57 {
58 lt = new LocalizationTool();
59 AnnotationProcessor.process(lt);
60 lt.init(getRunData());
61 }
62
63 @Test
64 public void testGet() throws Exception
65 {
66 assertEquals("value1", lt.get("key1"));
67 assertEquals("value3", lt.get("key3"));
68 }
69
70 @Test
71 public void testGetLocale() throws Exception
72 {
73 assertNotNull(lt.getLocale());
74 assertEquals("US", lt.getLocale().getCountry());
75 assertEquals("en", lt.getLocale().getLanguage());
76 }
77
78 @Test
79 public void testInit() throws Exception
80 {
81 assertNotNull(lt.getLocale());
82 }
83
84 @Test
85 public void testRefresh() throws Exception
86 {
87 assertNotNull(lt.getLocale());
88 lt.refresh();
89 assertNull(lt.getLocale());
90 }
91
92 private RunData getRunData() throws Exception
93 {
94 RunDataService rds = (RunDataService) TurbineServices.getInstance().getService(RunDataService.SERVICE_NAME);
95 ServletConfig config = mock(ServletConfig.class);
96 HttpServletRequest request = getMockRequest();
97 HttpServletResponse response = mock(HttpServletResponse.class);
98 RunData runData = rds.getRunData(request, response, config);
99 return runData;
100 }
101
102 @BeforeClass
103 public static void setUp() throws Exception
104 {
105 tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
106 tc.initialize();
107 }
108
109 @AfterClass
110 public static void tearDown() throws Exception
111 {
112 if (tc != null)
113 {
114 tc.dispose();
115 }
116 }
117 }