001 /**
002 * Copyright 2005-2011 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.ken.test.util;
017
018 import org.kuali.rice.core.api.membership.MemberType;
019 import org.kuali.rice.ken.bo.Notification;
020 import org.kuali.rice.ken.bo.NotificationChannel;
021 import org.kuali.rice.ken.bo.NotificationChannelReviewer;
022 import org.kuali.rice.ken.bo.NotificationContentType;
023 import org.kuali.rice.ken.bo.NotificationPriority;
024 import org.kuali.rice.ken.bo.NotificationProducer;
025 import org.kuali.rice.ken.bo.NotificationRecipient;
026 import org.kuali.rice.ken.bo.NotificationSender;
027 import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes;
028
029 import java.sql.Timestamp;
030 import java.util.List;
031
032 /**
033 * This class helps to provide common mock objects for testing and also helper methods to build instances of objects.
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 public final class MockObjectsUtil {
037
038 private MockObjectsUtil() {
039 throw new UnsupportedOperationException("do not call");
040 }
041
042 /**
043 * This method is a helper to build a NotificationChannel instance.
044 * @param name
045 * @param description
046 * @param subscribable
047 * @return NotificationChannel
048 */
049 public static final NotificationChannel buildTestNotificationChannel(String name, String description, boolean subscribable) {
050 NotificationChannel channel = new NotificationChannel();
051 channel.setName(name);
052 channel.setDescription(description);
053 channel.setSubscribable(subscribable);
054 return channel;
055 }
056
057 /**
058 * This method returns back a specific test mock object.
059 * @return NotificationChannel
060 */
061 public static final NotificationChannel getTestChannel1() {
062 return buildTestNotificationChannel("Test Channel 1", "Test Channel 1 - description", true);
063 }
064
065 /**
066 * This method returns back a specific test mock object.
067 * @return NotificationChannel
068 */
069 public static final NotificationChannel getTestChannel2() {
070 return buildTestNotificationChannel("Test Channel 2", "Test Channel 2 - description", false);
071 }
072
073 /**
074 * This method is a helper to build a NotificationProducer instance.
075 * @param name
076 * @param description
077 * @param contactInfo
078 * @return
079 */
080 public static final NotificationProducer buildTestNotificationProducer(String name, String description, String contactInfo) {
081 NotificationProducer producer = new NotificationProducer();
082 producer.setName(name);
083 producer.setDescription(description);
084 producer.setContactInfo(contactInfo);
085 return producer;
086 }
087
088 /**
089 * This method is a helper to build a NotificationChannelReviewer instance.
090 * @param reviewerType
091 * @param reviewerId
092 * @return
093 */
094 public static final NotificationChannelReviewer buildTestNotificationChannelReviewer(MemberType reviewerType, String reviewerId) {
095 NotificationChannelReviewer reviewer = new NotificationChannelReviewer();
096 reviewer.setReviewerType(reviewerType.getCode());
097 reviewer.setReviewerId(reviewerId);
098 return reviewer;
099 }
100
101 /**
102 * This method returns back a specific test mock object.
103 * @return NotificationProducer
104 */
105 public static final NotificationProducer getTestProducer1() {
106 return buildTestNotificationProducer("Produer 1", "Producer 1 - description", "Producer 1 - contact info");
107 }
108
109 /**
110 * This method is a helper to build a NotificationContentType instance.
111 * @param name
112 * @param description
113 * @param namespace
114 * @param xsd
115 * @return NotificationContentType
116 */
117 public static final NotificationContentType buildTestNotificationContentType(String name, String description, String namespace, String xsd, String xsl) {
118 NotificationContentType contentType = new NotificationContentType();
119 contentType.setName(name);
120 contentType.setDescription(description);
121 contentType.setNamespace(namespace);
122 contentType.setXsd(xsd);
123 contentType.setXsl(xsl);
124 return contentType;
125 }
126
127 /**
128 * This method returns back a specific test mock object.
129 * @return NotificationContentType
130 */
131 public static final NotificationContentType getTestContentType1() {
132 return buildTestNotificationContentType("Content Type 1", "Content Type 1 - description", "Content Type 1 - namespace", "Simple.xsd", "Simple.xsl");
133 }
134
135 /**
136 * This method is a helper to build a NotificationPriority instance.
137 * @param name
138 * @param description
139 * @param order
140 * @return NotificationPriority
141 */
142 public static final NotificationPriority buildTestNotificationPriority(String name, String description, Integer order) {
143 NotificationPriority priority = new NotificationPriority();
144 priority.setName(name);
145 priority.setDescription(description);
146 priority.setOrder(order);
147 return priority;
148 }
149
150 /**
151 * This method returns back a specific test mock object.
152 * @return NotificationPriority
153 */
154 public static final NotificationPriority getTestPriority1() {
155 return buildTestNotificationPriority("Priority 1", "Priority 1 - description", new Integer(1));
156 }
157
158 /**
159 * This method is a helper to build a NotificationRecipient instance.
160 * @param recipientId
161 * @param recipientType
162 * @return NotificationRecipient
163 */
164 public static final NotificationRecipient buildTestNotificationRecipient(String recipientId, MemberType recipientType) {
165 NotificationRecipient recipient = new NotificationRecipient();
166 recipient.setRecipientId(recipientId);
167 recipient.setRecipientType(recipientType.getCode());
168 return recipient;
169 }
170
171 /**
172 * This method returns back a specific test mock object.
173 * @return NotificationRecipient
174 */
175 public static final NotificationRecipient getTestRecipient1() {
176 return buildTestNotificationRecipient("ag266", KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE);
177 }
178
179 /**
180 * This method returns back a specific test mock object.
181 * @return NotificationRecipient
182 */
183 public static final NotificationRecipient getTestRecipient2() {
184 return buildTestNotificationRecipient("Notification Team", KimGroupMemberTypes.GROUP_MEMBER_TYPE);
185 }
186
187 /**
188 * This method is a helper to build a Notification instance.
189 * @param recipientId
190 * @param recipientType
191 * @return Notification
192 */
193 public static final Notification buildTestNotification(String deliveryType, Timestamp sendDateTime, Timestamp autoRemoveDateTime, NotificationContentType contentType,
194 String content, NotificationPriority priority, NotificationProducer producer, NotificationChannel channel, List<NotificationRecipient> recipients,
195 List<NotificationSender> senders) {
196 Notification notification = new Notification();
197 notification.setCreationDateTime(new Timestamp(System.currentTimeMillis()));
198 notification.setDeliveryType(deliveryType);
199 notification.setSendDateTime(sendDateTime);
200 notification.setAutoRemoveDateTime(autoRemoveDateTime);
201 notification.setContentType(contentType);
202 notification.setContent(content);
203 notification.setPriority(priority);
204 notification.setProducer(producer);
205 notification.setChannel(channel);
206 notification.setRecipients(recipients);
207 notification.setSenders(senders);
208
209 return notification;
210 }
211
212 /**
213 * This method is a helper to build a NotificationSender instance.
214 * @param recipientId
215 * @param recipientType
216 * @return NotificationSender
217 */
218 public static final NotificationSender buildTestNotificationSender(String userId) {
219 NotificationSender sender = new NotificationSender();
220 sender.setSenderName(userId);
221 return sender;
222 }
223
224 /**
225 * This method returns back a specific test mock object.
226 * @return NotificationSender
227 */
228 public static final NotificationSender getTestSender1() {
229 return buildTestNotificationSender("Joe Schmoe");
230 }
231
232 /**
233 * This method returns back a specific test mock object.
234 * @return NotificationSender
235 */
236 public static final NotificationSender getTestSender2() {
237 return buildTestNotificationSender("John Doe");
238 }
239 }