001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.messages; 017 018 import org.junit.Test; 019 020 import java.util.ArrayList; 021 import java.util.Collection; 022 023 import static org.junit.Assert.*; 024 025 /** 026 * Test cases for {@link MessageServiceImpl} 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030 public class MessageServiceImplTest { 031 032 /** 033 * Test that list of messages are being correctly merged, messages of same 034 * type should not be overridden 035 */ 036 @Test 037 public void testMergeMessages() { 038 Collection<Message> messages1 = new ArrayList<Message>(); 039 Collection<Message> messages2 = new ArrayList<Message>(); 040 041 MessageBuilder builder = MessageBuilder.create("Default", "All", "Test Message"); 042 043 Message message1 = builder.build(); 044 045 builder.setKey("Test Message 2"); 046 Message message2 = builder.build(); 047 048 builder.setComponentCode("TestView"); 049 Message message3 = builder.build(); 050 051 builder.setNamespaceCode("KR-SAP"); 052 Message message4 = builder.build(); 053 054 Message message5 = builder.build(); 055 056 messages1.add(message1); 057 messages1.add(message2); 058 messages1.add(message4); 059 060 messages2.add(message1); 061 messages2.add(message3); 062 messages2.add(message4); 063 messages2.add(message5); 064 065 MessageServiceImpl messageServiceImpl = new MessageServiceImpl(); 066 messageServiceImpl.mergeMessages(messages1, messages2); 067 068 assertEquals("Merged map is not correct size", 5, messages1.size()); 069 070 } 071 072 public static class MessageBuilder { 073 private String namespaceCode; 074 private String componentCode; 075 private String key; 076 private String locale; 077 private String description; 078 private String text; 079 080 public MessageBuilder(String namespaceCode, String componentCode, String key) { 081 setNamespaceCode(namespaceCode); 082 setComponentCode(componentCode); 083 setKey(key); 084 } 085 086 public static MessageBuilder create(String namespaceCode, String componentCode, String key) { 087 return new MessageBuilder(namespaceCode, componentCode, key); 088 } 089 090 public Message build() { 091 Message message = new Message(); 092 093 message.setNamespaceCode(getNamespaceCode()); 094 message.setComponentCode(getComponentCode()); 095 message.setKey(getKey()); 096 message.setText(getText()); 097 message.setDescription(getDescription()); 098 message.setLocale(getLocale()); 099 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 }