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