View Javadoc

1   /**
2    * Copyright 2005-2011 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.ken.test.util;
17  
18  import org.kuali.rice.core.api.membership.MemberType;
19  import org.kuali.rice.ken.bo.NotificationBo;
20  import org.kuali.rice.ken.bo.NotificationChannelBo;
21  import org.kuali.rice.ken.bo.NotificationChannelReviewerBo;
22  import org.kuali.rice.ken.bo.NotificationContentTypeBo;
23  import org.kuali.rice.ken.bo.NotificationPriorityBo;
24  import org.kuali.rice.ken.bo.NotificationProducerBo;
25  import org.kuali.rice.ken.bo.NotificationRecipientBo;
26  import org.kuali.rice.ken.bo.NotificationSenderBo;
27  import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes;
28  
29  import java.sql.Timestamp;
30  import java.util.List;
31  
32  /**
33   * This class helps to provide common mock objects for testing and also helper methods to build instances of objects.
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public final class MockObjectsUtil {
37  	
38  	private MockObjectsUtil() {
39  		throw new UnsupportedOperationException("do not call");
40  	}
41  	
42      /**
43       * This method is a helper to build a NotificationChannel instance.
44       * @param name
45       * @param description
46       * @param subscribable
47       * @return NotificationChannel
48       */
49      public static final NotificationChannelBo buildTestNotificationChannel(String name, String description, boolean subscribable) {
50          NotificationChannelBo channel = new NotificationChannelBo();
51          channel.setName(name);
52          channel.setDescription(description);
53          channel.setSubscribable(subscribable);
54          return channel;
55      }
56  
57      /**
58       * This method returns back a specific test mock object.
59       * @return NotificationChannel
60       */
61      public static final NotificationChannelBo getTestChannel1() {
62          return buildTestNotificationChannel("Test Channel 1", "Test Channel 1 - description", true);
63      }
64  
65      /**
66       * This method returns back a specific test mock object.
67       * @return NotificationChannel
68       */
69      public static final NotificationChannelBo getTestChannel2() {
70          return buildTestNotificationChannel("Test Channel 2", "Test Channel 2 - description", false);
71      }
72  
73      /**
74       * This method is a helper to build a NotificationProducer instance.
75       * @param name
76       * @param description
77       * @param contactInfo
78       * @return
79       */
80      public static final NotificationProducerBo buildTestNotificationProducer(String name, String description, String contactInfo) {
81          NotificationProducerBo producer = new NotificationProducerBo();
82          producer.setName(name);
83          producer.setDescription(description);
84          producer.setContactInfo(contactInfo);
85          return producer;
86      }
87  
88      /**
89       * This method is a helper to build a NotificationChannelReviewer instance.
90       * @param reviewerType
91       * @param reviewerId
92       * @return
93       */
94      public static final NotificationChannelReviewerBo buildTestNotificationChannelReviewer(MemberType reviewerType, String reviewerId) {
95          NotificationChannelReviewerBo reviewer = new NotificationChannelReviewerBo();
96          reviewer.setReviewerType(reviewerType.getCode());
97          reviewer.setReviewerId(reviewerId);
98          return reviewer;
99      }
100 
101     /**
102      * This method returns back a specific test mock object.
103      * @return NotificationProducer
104      */
105     public static final NotificationProducerBo 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 NotificationContentTypeBo buildTestNotificationContentType(String name, String description, String namespace, String xsd, String xsl) {
118         NotificationContentTypeBo contentType = new NotificationContentTypeBo();
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 NotificationContentTypeBo 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 NotificationPriorityBo buildTestNotificationPriority(String name, String description, Integer order) {
143         NotificationPriorityBo priority = new NotificationPriorityBo();
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 NotificationPriorityBo 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 NotificationRecipientBo buildTestNotificationRecipient(String recipientId, MemberType recipientType) {
165         NotificationRecipientBo recipient = new NotificationRecipientBo();
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 NotificationRecipientBo 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 NotificationRecipientBo 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 NotificationBo buildTestNotification(String deliveryType, Timestamp sendDateTime, Timestamp autoRemoveDateTime, NotificationContentTypeBo contentType,
194 	    String content, NotificationPriorityBo priority, NotificationProducerBo producer, NotificationChannelBo channel, List<NotificationRecipientBo> recipients,
195 	    List<NotificationSenderBo> senders) {
196         NotificationBo notification = new NotificationBo();
197         notification.setCreationDateTimeValue(new Timestamp(System.currentTimeMillis()));
198         notification.setDeliveryType(deliveryType);
199         notification.setSendDateTimeValue(sendDateTime);
200         notification.setAutoRemoveDateTimeValue(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 userId
215      * @return NotificationSender
216      */
217     public static final NotificationSenderBo buildTestNotificationSender(String userId) {
218         NotificationSenderBo sender = new NotificationSenderBo();
219         sender.setSenderName(userId);
220         return sender;
221     }
222 
223     /**
224      * This method returns back a specific test mock object.
225      * @return NotificationSender
226      */
227     public static final NotificationSenderBo getTestSender1() {
228         return buildTestNotificationSender("Joe Schmoe");
229     }
230 
231     /**
232      * This method returns back a specific test mock object.
233      * @return NotificationSender
234      */
235     public static final NotificationSenderBo getTestSender2() {
236 	return buildTestNotificationSender("John Doe");
237     }
238 }