View Javadoc

1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Test cases for {@link MessageServiceImpl}
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class MessageServiceImplTest {
31  
32      /**
33       * Test that list of messages are being correctly merged, messages of same
34       * type should not be overridden
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 }