1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actions;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.fail;
23
24 import org.junit.Test;
25 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
26 import org.kuali.rice.kew.api.WorkflowDocument;
27 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
28 import org.kuali.rice.kew.api.doctype.IllegalDocumentTypeException;
29 import org.kuali.rice.kew.api.document.Document;
30 import org.kuali.rice.kew.api.document.DocumentStatus;
31 import org.kuali.rice.kew.service.KEWServiceLocator;
32 import org.kuali.rice.kew.test.KEWTestCase;
33
34 public class CreateDocumentTest extends KEWTestCase {
35
36 @Override
37 protected void loadTestData() throws Exception {
38 loadXmlFile("ActionsConfig.xml");
39 }
40
41
42
43
44 @Test public void testCreateNonExistentDocumentType() throws Exception {
45 try {
46 WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "flim-flam-flooey");
47 fail("A DocumentTypeNotFoundException exception should have been thrown.");
48 } catch (RiceIllegalArgumentException e) {
49 e.printStackTrace();
50 }
51 }
52
53
54
55
56 @Test public void testCreateNonRoutableDocumentType() throws Exception {
57
58
59 try {
60 WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveTest");
61 fail("A workflow exception should have been thrown.");
62 } catch (IllegalDocumentTypeException e) {
63 e.printStackTrace();
64 }
65 }
66
67
68
69
70 @Test public void testCreateInactiveDocumentType() throws Exception {
71
72
73 try {
74 WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "CreatedDocumentInactive");
75 fail("A workflow exception should have been thrown.");
76 } catch (IllegalDocumentTypeException e) {
77 e.printStackTrace();
78 }
79 }
80
81
82
83
84 @Test
85 public void testCreateSimpleDocumentType() throws Exception {
86 String principalId = getPrincipalIdForName("ewestfal");
87 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(principalId, "TestDocumentType");
88 assertNotNull(workflowDocument);
89
90 assertNotNull(workflowDocument.getDocumentId());
91 Document document = workflowDocument.getDocument();
92 assertNotNull(document);
93
94 assertNotNull(document.getDateCreated());
95 assertNotNull(document.getDateLastModified());
96 assertNull(document.getDateApproved());
97 assertNull(document.getDateFinalized());
98
99 assertEquals("", document.getTitle());
100 assertNotNull(document.getDocumentTypeId());
101 assertEquals("TestDocumentType", document.getDocumentTypeName());
102 assertEquals(principalId, document.getInitiatorPrincipalId());
103 assertEquals(DocumentStatus.INITIATED, document.getStatus());
104
105 }
106
107 protected String getPrincipalIdForName(String principalName) {
108 return KEWServiceLocator.getIdentityHelperService()
109 .getIdForPrincipalName(principalName);
110 }
111 }