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