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
20 import java.util.ArrayList;
21 import java.util.Collection;
22
23 import static org.junit.Assert.*;
24
25
26
27
28
29
30 public class MessageServiceImplTest {
31
32
33
34
35
36 @Test
37 public void testMergeMessages() {
38 Collection<Message> messages1 = new ArrayList<Message>();
39 Collection<Message> messages2 = new ArrayList<Message>();
40
41 MessageBuilder builder = MessageBuilder.create("Default", "All", "Test Message");
42
43 Message message1 = builder.build();
44
45 builder.setKey("Test Message 2");
46 Message message2 = builder.build();
47
48 builder.setComponentCode("TestView");
49 Message message3 = builder.build();
50
51 builder.setNamespaceCode("KR-SAP");
52 Message message4 = builder.build();
53
54 Message message5 = builder.build();
55
56 messages1.add(message1);
57 messages1.add(message2);
58 messages1.add(message4);
59
60 messages2.add(message1);
61 messages2.add(message3);
62 messages2.add(message4);
63 messages2.add(message5);
64
65 MessageServiceImpl messageServiceImpl = new MessageServiceImpl();
66 messageServiceImpl.mergeMessages(messages1, messages2);
67
68 assertEquals("Merged map is not correct size", 5, messages1.size());
69
70 }
71
72 public static class MessageBuilder {
73 private String namespaceCode;
74 private String componentCode;
75 private String key;
76 private String locale;
77 private String description;
78 private String text;
79
80 public MessageBuilder(String namespaceCode, String componentCode, String key) {
81 setNamespaceCode(namespaceCode);
82 setComponentCode(componentCode);
83 setKey(key);
84 }
85
86 public static MessageBuilder create(String namespaceCode, String componentCode, String key) {
87 return new MessageBuilder(namespaceCode, componentCode, key);
88 }
89
90 public Message build() {
91 Message message = new Message();
92
93 message.setNamespaceCode(getNamespaceCode());
94 message.setComponentCode(getComponentCode());
95 message.setKey(getKey());
96 message.setText(getText());
97 message.setDescription(getDescription());
98 message.setLocale(getLocale());
99
100 return message;
101 }
102
103 public String getNamespaceCode() {
104 return namespaceCode;
105 }
106
107 public void setNamespaceCode(String namespaceCode) {
108 this.namespaceCode = namespaceCode;
109 }
110
111 public String getComponentCode() {
112 return componentCode;
113 }
114
115 public void setComponentCode(String componentCode) {
116 this.componentCode = componentCode;
117 }
118
119 public String getKey() {
120 return key;
121 }
122
123 public void setKey(String key) {
124 this.key = key;
125 }
126
127 public String getLocale() {
128 return locale;
129 }
130
131 public void setLocale(String locale) {
132 this.locale = locale;
133 }
134
135 public String getDescription() {
136 return description;
137 }
138
139 public void setDescription(String description) {
140 this.description = description;
141 }
142
143 public String getText() {
144 return text;
145 }
146
147 public void setText(String text) {
148 this.text = text;
149 }
150 }
151 }