View Javadoc

1   /*
2    * Copyright 2007 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 java.sql.Timestamp;
19  import java.util.List;
20  
21  import org.kuali.rice.ken.bo.Notification;
22  import org.kuali.rice.ken.bo.NotificationChannel;
23  import org.kuali.rice.ken.bo.NotificationChannelReviewer;
24  import org.kuali.rice.ken.bo.NotificationContentType;
25  import org.kuali.rice.ken.bo.NotificationPriority;
26  import org.kuali.rice.ken.bo.NotificationProducer;
27  import org.kuali.rice.ken.bo.NotificationRecipient;
28  import org.kuali.rice.ken.bo.NotificationSender;
29  import org.kuali.rice.ken.util.NotificationConstants;
30  import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes;
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 class MockObjectsUtil {
37      /**
38       * This method is a helper to build a NotificationChannel instance.
39       * @param name
40       * @param description
41       * @param subscribable
42       * @return NotificationChannel
43       */
44      public static final NotificationChannel buildTestNotificationChannel(String name, String description, boolean subscribable) {
45          NotificationChannel channel = new NotificationChannel();
46          channel.setName(name);
47          channel.setDescription(description);
48          channel.setSubscribable(subscribable);
49          return channel;
50      }
51  
52      /**
53       * This method returns back a specific test mock object.
54       * @return NotificationChannel
55       */
56      public static final NotificationChannel getTestChannel1() {
57          return buildTestNotificationChannel("Test Channel 1", "Test Channel 1 - description", true);
58      }
59  
60      /**
61       * This method returns back a specific test mock object.
62       * @return NotificationChannel
63       */
64      public static final NotificationChannel getTestChannel2() {
65          return buildTestNotificationChannel("Test Channel 2", "Test Channel 2 - description", false);
66      }
67  
68      /**
69       * This method is a helper to build a NotificationProducer instance.
70       * @param name
71       * @param description
72       * @param contactInfo
73       * @return
74       */
75      public static final NotificationProducer buildTestNotificationProducer(String name, String description, String contactInfo) {
76          NotificationProducer producer = new NotificationProducer();
77          producer.setName(name);
78          producer.setDescription(description);
79          producer.setContactInfo(contactInfo);
80          return producer;
81      }
82  
83      /**
84       * This method is a helper to build a NotificationChannelReviewer instance.
85       * @param reviewerType
86       * @param reviewerId
87       * @return
88       */
89      public static final NotificationChannelReviewer buildTestNotificationChannelReviewer(String reviewerType, String reviewerId) {
90          NotificationChannelReviewer reviewer = new NotificationChannelReviewer();
91          reviewer.setReviewerType(reviewerType);
92          reviewer.setReviewerId(reviewerId);
93          return reviewer;
94      }
95  
96      /**
97       * This method returns back a specific test mock object.
98       * @return NotificationProducer
99       */
100     public static final NotificationProducer getTestProducer1() {
101         return buildTestNotificationProducer("Produer 1", "Producer 1 - description", "Producer 1 - contact info");
102     }
103 
104     /**
105      * This method is a helper to build a NotificationContentType instance.
106      * @param name
107      * @param description
108      * @param namespace
109      * @param xsd
110      * @return NotificationContentType
111      */
112     public static final NotificationContentType buildTestNotificationContentType(String name, String description, String namespace, String xsd, String xsl) {
113         NotificationContentType contentType = new NotificationContentType();
114         contentType.setName(name);
115         contentType.setDescription(description);
116         contentType.setNamespace(namespace);
117         contentType.setXsd(xsd);
118         contentType.setXsl(xsl);
119         return contentType;
120     }
121 
122     /**
123      * This method returns back a specific test mock object.
124      * @return NotificationContentType
125      */
126     public static final NotificationContentType getTestContentType1() {
127         return buildTestNotificationContentType("Content Type 1", "Content Type 1 - description", "Content Type 1 - namespace", "Simple.xsd", "Simple.xsl");
128     }
129 
130     /**
131      * This method is a helper to build a NotificationPriority instance.
132      * @param name
133      * @param description
134      * @param order
135      * @return NotificationPriority
136      */
137     public static final NotificationPriority buildTestNotificationPriority(String name, String description, Integer order) {
138         NotificationPriority priority = new NotificationPriority();
139         priority.setName(name);
140         priority.setDescription(description);
141         priority.setOrder(order);
142         return priority;
143     }
144 
145     /**
146      * This method returns back a specific test mock object.
147      * @return NotificationPriority
148      */
149     public static final NotificationPriority getTestPriority1() {
150         return buildTestNotificationPriority("Priority 1", "Priority 1 - description", new Integer(1));
151     }
152 
153     /**
154      * This method is a helper to build a NotificationRecipient instance.
155      * @param recipientId
156      * @param recipientType
157      * @return NotificationRecipient
158      */
159     public static final NotificationRecipient buildTestNotificationRecipient(String recipientId, String recipientType) {
160         NotificationRecipient recipient = new NotificationRecipient();
161         recipient.setRecipientId(recipientId);
162         recipient.setRecipientType(recipientType);
163         return recipient;
164     }
165 
166     /**
167      * This method returns back a specific test mock object.
168      * @return NotificationRecipient
169      */
170     public static final NotificationRecipient getTestRecipient1() {
171         return buildTestNotificationRecipient("ag266", KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE);
172     }
173 
174     /**
175      * This method returns back a specific test mock object.
176      * @return NotificationRecipient
177      */
178     public static final NotificationRecipient getTestRecipient2() {
179 	 return buildTestNotificationRecipient("Notification Team", KimGroupMemberTypes.GROUP_MEMBER_TYPE);
180     }
181 
182     /**
183      * This method is a helper to build a Notification instance.
184      * @param recipientId
185      * @param recipientType
186      * @return Notification
187      */
188     public static final Notification buildTestNotification(String deliveryType, Timestamp sendDateTime, Timestamp autoRemoveDateTime, NotificationContentType contentType,
189 	    String content, NotificationPriority priority, NotificationProducer producer, NotificationChannel channel, List<NotificationRecipient> recipients,
190 	    List<NotificationSender> senders) {
191         Notification notification = new Notification();
192         notification.setCreationDateTime(new Timestamp(System.currentTimeMillis()));
193         notification.setDeliveryType(deliveryType);
194         notification.setSendDateTime(sendDateTime);
195         notification.setAutoRemoveDateTime(autoRemoveDateTime);
196         notification.setContentType(contentType);
197         notification.setContent(content);
198         notification.setPriority(priority);
199         notification.setProducer(producer);
200         notification.setChannel(channel);
201         notification.setRecipients(recipients);
202         notification.setSenders(senders);
203 
204         return notification;
205     }
206 
207     /**
208      * This method is a helper to build a NotificationSender instance.
209      * @param recipientId
210      * @param recipientType
211      * @return NotificationSender
212      */
213     public static final NotificationSender buildTestNotificationSender(String userId) {
214         NotificationSender sender = new NotificationSender();
215         sender.setSenderName(userId);
216         return sender;
217     }
218 
219     /**
220      * This method returns back a specific test mock object.
221      * @return NotificationSender
222      */
223     public static final NotificationSender getTestSender1() {
224         return buildTestNotificationSender("Joe Schmoe");
225     }
226 
227     /**
228      * This method returns back a specific test mock object.
229      * @return NotificationSender
230      */
231     public static final NotificationSender getTestSender2() {
232 	return buildTestNotificationSender("John Doe");
233     }
234 }