1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.util.List;
21
22 import org.junit.Test;
23 import org.kuali.rice.krad.test.KRADTestCase;
24 import org.kuali.rice.test.data.PerSuiteUnitTestData;
25 import org.kuali.rice.test.data.UnitTestData;
26 import org.kuali.rice.test.data.UnitTestFile;
27
28
29
30
31
32
33 @PerSuiteUnitTestData(
34 value = @UnitTestData(
35 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
36 sqlFiles = {@UnitTestFile(filename = "classpath:testValidationMessages.sql", delimiter = ";")}))
37 public class ValidationMessageRetrievalTest extends KRADTestCase {
38
39 private MessageMap messageMap;
40
41 @Override
42 public void setUp() throws Exception {
43 super.setUp();
44
45 messageMap = new MessageMap();
46 }
47
48
49
50
51
52 @Test
53 public void testRetrieveMessage_keyOnly() throws Exception {
54 messageMap.putError("field1", "testErrorKey");
55
56 List<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
57 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
58
59 ErrorMessage message = fieldErrors.get(0);
60 String messageText = KRADUtils.getMessageText(message, true);
61 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
62 }
63
64
65
66
67
68 @Test
69 public void testRetrieveMessage_namespaceKey() throws Exception {
70 ErrorMessage errorMessage = new ErrorMessage();
71 errorMessage.setNamespaceCode("KR-NS");
72 errorMessage.setErrorKey("testErrorKey");
73
74 messageMap.putError("field1", errorMessage);
75
76 List<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
77 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
78
79 ErrorMessage message = fieldErrors.get(0);
80 String messageText = KRADUtils.getMessageText(message, true);
81 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
82 }
83
84
85
86
87
88 @Test
89 public void testRetrieveMessage_componentKey() throws Exception {
90 ErrorMessage errorMessage = new ErrorMessage();
91 errorMessage.setNamespaceCode("KR-NS");
92 errorMessage.setComponentCode("GeneralGroup");
93 errorMessage.setErrorKey("testErrorKey");
94
95 messageMap.putError("field1", errorMessage);
96
97 List<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
98 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
99
100 ErrorMessage message = fieldErrors.get(0);
101 String messageText = KRADUtils.getMessageText(message, true);
102 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
103 }
104 }