1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34
35
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
44
45
46
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
60
61
62
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
75
76
77
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
91
92
93
94
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 }