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 org.junit.Test;
19 import org.kuali.rice.test.data.PerSuiteUnitTestData;
20 import org.kuali.rice.test.data.UnitTestData;
21 import org.kuali.rice.test.data.UnitTestFile;
22 import org.kuali.rice.krad.test.KRADTestCase;
23 import org.springframework.util.AutoPopulatingList;
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:testValidationMessages.sql", delimiter = ";")}))
36 public class ValidationMessageRetrievalTest extends KRADTestCase {
37
38 private MessageMap messageMap;
39
40 @Override
41 public void setUp() throws Exception {
42 super.setUp();
43
44 messageMap = new MessageMap();
45 }
46
47
48
49
50
51 @Test
52 public void testRetrieveMessage_keyOnly() throws Exception {
53 messageMap.putError("field1", "testErrorKey");
54
55 AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
56 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
57
58 ErrorMessage message = fieldErrors.get(0);
59 String messageText = KRADUtils.getMessageText(message, true);
60 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
61 }
62
63
64
65
66
67 @Test
68 public void testRetrieveMessage_namespaceKey() throws Exception {
69 ErrorMessage errorMessage = new ErrorMessage();
70 errorMessage.setNamespaceCode("KR-NS");
71 errorMessage.setErrorKey("testErrorKey");
72
73 messageMap.putError("field1", errorMessage);
74
75 AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
76 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
77
78 ErrorMessage message = fieldErrors.get(0);
79 String messageText = KRADUtils.getMessageText(message, true);
80 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
81 }
82
83
84
85
86
87 @Test
88 public void testRetrieveMessage_componentKey() throws Exception {
89 ErrorMessage errorMessage = new ErrorMessage();
90 errorMessage.setNamespaceCode("KR-NS");
91 errorMessage.setComponentCode("GeneralGroup");
92 errorMessage.setErrorKey("testErrorKey");
93
94 messageMap.putError("field1", errorMessage);
95
96 AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1");
97 assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size());
98
99 ErrorMessage message = fieldErrors.get(0);
100 String messageText = KRADUtils.getMessageText(message, true);
101 assertEquals("Message for field1 is not correct", "Error on field1", messageText);
102 }
103 }