1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.messages;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20 import org.kuali.rice.test.data.PerSuiteUnitTestData;
21 import org.kuali.rice.test.data.UnitTestData;
22 import org.kuali.rice.test.data.UnitTestFile;
23 import org.kuali.rice.krad.test.KRADTestCase;
24
25 import static org.junit.Assert.assertEquals;
26
27
28
29
30
31
32 @PerSuiteUnitTestData(
33 value = @UnitTestData(
34 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
35 sqlFiles = {@UnitTestFile(filename = "classpath:testExternalMessages.sql", delimiter = ";")}))
36 public class MessageServiceTest extends KRADTestCase {
37
38 private MessageService messageService;
39
40 @Override
41 public void setUp() throws Exception {
42 super.setUp();
43
44 messageService = KRADServiceLocatorWeb.getMessageService();
45 }
46
47
48
49
50 @Test
51 public void testRetrieveMessage_ResourceByKey() throws Exception {
52 String messageText = messageService.getMessageText("validation.test.error");
53
54 assertEquals("Validation message text not correct", "App Error found for {0}", messageText);
55 }
56
57
58
59
60 @Test
61 public void testRetrieveMessage_ResourceByNamespaceKey() throws Exception {
62 String messageText = messageService.getMessageText("TEST", "", "validation.test.error");
63
64 assertEquals("Validation message text not correct", "Error found for {0}", messageText);
65 }
66
67
68
69
70 @Test
71 public void testRetrieveMessage_ResourceByNamespaceComponentKey() throws Exception {
72 String messageText = messageService.getMessageText("TEST", "TestComponent", "validation.test.error");
73
74 assertEquals("Component validation message text not correct", "Component Error found", messageText);
75 }
76
77
78
79
80 @Test
81 public void testRetrieveMessage_DatabaseByKey() throws Exception {
82 String messageText = messageService.getMessageText("validation.test2.error");
83
84 assertEquals("Validation message text not correct", "App Error found for {0}", messageText);
85 }
86
87
88
89
90 @Test
91 public void testRetrieveMessage_DatabaseByNamespaceKey() throws Exception {
92 String messageText = messageService.getMessageText("TEST", "", "validation.test2.error");
93
94 assertEquals("Validation message text not correct", "Error found for {0}", messageText);
95 }
96
97
98
99
100 @Test
101 public void testRetrieveMessage_DatabaseByNamespaceComponentKey() throws Exception {
102 String messageText = messageService.getMessageText("TEST", "TestComponent", "validation.test2.error");
103
104 assertEquals("Validation message text not correct", "Component Error found", messageText);
105 }
106
107
108
109
110 @Test
111 public void testRetrieveMessage_Locale() throws Exception {
112 String messageText = messageService.getMessageText("TEST", "TestLocales", "message.key", "en-US");
113 assertEquals("Message text not correct for English US locale", "English US Message", messageText);
114
115 messageText = messageService.getMessageText("TEST", "TestLocales", "message.key", "fr-CA");
116 assertEquals("Message text not correct for French Canada locale", "French CA Message", messageText);
117
118 messageText = messageService.getMessageText("TEST", "TestLocales", "message.key", "de-AT");
119 assertEquals("Message text not correct for German locale", "German Message", messageText);
120
121 messageText = messageService.getMessageText("TEST", "TestLocales", "message.key", "de-DE");
122 assertEquals("Message text not correct for German locale", "German Message", messageText);
123
124 messageText = messageService.getMessageText("TEST", "TestLocales", "message.key2", "en-US");
125 assertEquals("Message text not correct for message with language only and language/country locale",
126 "English US Message", messageText);
127 }
128 }