View Javadoc

1   /**
2    * Copyright 2005-2013 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.services.impl;
17  
18  import org.junit.Test;
19  import org.kuali.rice.ken.bo.NotificationBo;
20  import org.kuali.rice.ken.bo.NotificationMessageDelivery;
21  import org.kuali.rice.ken.test.KENTestCase;
22  import org.kuali.rice.ken.test.TestConstants;
23  import org.kuali.rice.ken.util.NotificationConstants;
24  import org.kuali.rice.ken.util.Util;
25  import org.kuali.rice.kew.api.KewApiServiceLocator;
26  import org.kuali.rice.kew.api.document.Document;
27  import org.kuali.rice.kew.api.exception.WorkflowException;
28  import org.kuali.rice.test.BaselineTestCase;
29  
30  import static org.junit.Assert.assertEquals;
31  
32  /**
33   * This class tests the notification workflow document service service impl.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
38  public class NotificationWorkflowDocumentServiceImplTest extends KENTestCase {
39  
40      private static final String CUSTOM_NOTIFICATION_DOC_TYPE = "CustomNotification";
41  
42      /**
43       * Tests whether the default KEW document type {@code KualiNotification} is used when set in this
44       * {@code Notification}.
45       *
46       * @throws WorkflowException when KEW cannot find the document
47       */
48      @Test
49      public void createAndAdHocRouteNotificationWorkflowDocument_defaultKEW() throws WorkflowException {
50          NotificationBo notification = services.getNotificationService().getNotification(TestConstants.NOTIFICATION_1);
51          notification.setDocTypeName(NotificationConstants.KEW_CONSTANTS.NOTIFICATION_DOC_TYPE);
52  
53          Document document = createNotificationWorkflowDocument(notification);
54  
55          assertEquals(NotificationConstants.KEW_CONSTANTS.NOTIFICATION_DOC_TYPE, document.getDocumentTypeName());
56      }
57  
58      /**
59       * Tests whether the default KEW document type {@code KualiNotification} is used when nothing is set in this
60       * {@code Notification}.
61       *
62       * @throws WorkflowException when KEW cannot find the document
63       */
64      @Test
65      public void createAndAdHocRouteNotificationWorkflowDocument_undefinedKEW() throws WorkflowException {
66          NotificationBo notification = services.getNotificationService().getNotification(TestConstants.NOTIFICATION_1);
67  
68          Document document = createNotificationWorkflowDocument(notification);
69  
70          assertEquals(NotificationConstants.KEW_CONSTANTS.NOTIFICATION_DOC_TYPE, document.getDocumentTypeName());
71      }
72  
73      /**
74       * Tests whether the custom KEW document type {@code CustomNotification} is used when set in this
75       * {@code Notification}.
76       *
77       * @throws WorkflowException when KEW cannot find the document
78       */
79      @Test
80      public void createAndAdHocRouteNotificationWorkflowDocument_customKEW() throws WorkflowException {
81          NotificationBo notification = services.getNotificationService().getNotification(TestConstants.NOTIFICATION_1);
82          notification.setDocTypeName(CUSTOM_NOTIFICATION_DOC_TYPE);
83  
84          Document document = createNotificationWorkflowDocument(notification);
85  
86          assertEquals(CUSTOM_NOTIFICATION_DOC_TYPE, document.getDocumentTypeName());
87      }
88  
89      /**
90       * Helper method for creating a {@code Notification} workflow document.
91       *
92       * @param notification the {@code Notification} to include in the workflow document
93       *
94       * @return a KEW workflow document
95       */
96      protected Document createNotificationWorkflowDocument(NotificationBo notification) {
97          NotificationMessageDelivery messageDelivery = new NotificationMessageDelivery();
98          messageDelivery.setId(0L);
99          messageDelivery.setMessageDeliveryStatus(NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
100         messageDelivery.setNotification(notification);
101         messageDelivery.setUserRecipientId(TestConstants.TEST_USER_FIVE);
102 
103         String documentId =
104                 services.getNotificationWorkflowDocumentService().createAndAdHocRouteNotificationWorkflowDocument(
105                         messageDelivery, Util.getNotificationSystemUser(), messageDelivery.getUserRecipientId(),
106                         NotificationConstants.KEW_CONSTANTS.GENERIC_DELIVERY_ANNOTATION);
107         Document document = KewApiServiceLocator.getWorkflowDocumentService().getDocument(documentId);
108 
109         return document;
110     }
111 }