View Javadoc
1   /**
2    * Copyright 2005-2014 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.kew.actions;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertNull;
21  import static org.junit.Assert.fail;
22  
23  import org.junit.Test;
24  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
25  import org.kuali.rice.kew.api.WorkflowDocument;
26  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
27  import org.kuali.rice.kew.api.doctype.IllegalDocumentTypeException;
28  import org.kuali.rice.kew.api.document.Document;
29  import org.kuali.rice.kew.api.document.DocumentStatus;
30  import org.kuali.rice.kew.service.KEWServiceLocator;
31  import org.kuali.rice.kew.test.KEWTestCase;
32  
33  public class CreateDocumentTest extends KEWTestCase {
34  
35      @Override
36      protected void loadTestData() throws Exception {
37          loadXmlFile("ActionsConfig.xml");
38      }
39  
40      /**
41       * Tests the attempt to create a document from a non-existent document type.
42       */
43      @Test(expected=RiceIllegalArgumentException.class)
44      public void testCreateNonExistentDocumentType() throws Exception {
45          WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "flim-flam-flooey");
46      }
47  
48      /**
49       * Tests the attempt to create a document from a document type with no routing path.
50       */
51      @Test(expected=IllegalDocumentTypeException.class)
52      public void testCreateNonRoutableDocumentType() throws Exception {
53          // the BlanketApproveTest is a parent document type that has no routing path defined.  Attempts to
54          // create documents of this type should return a DocumentCreationException
55          WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveTest");
56      }
57  
58      /**
59       * Tests the attempt to create a document from a document type with no routing path.
60       */
61      @Test(expected=IllegalDocumentTypeException.class)
62      public void testCreateInactiveDocumentType() throws Exception {
63          // the CreatedDocumentInactive document type is inactive and should not be able to 
64          // be initiated for a new document
65          WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "CreatedDocumentInactive");
66      }
67  
68      /**
69       * Tests creation of a simple document and verifies it's state.
70       */
71      @Test
72      public void testCreateSimpleDocumentType() throws Exception {
73          String principalId = getPrincipalIdForName("ewestfal");
74          WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(principalId, "TestDocumentType");
75          assertNotNull(workflowDocument);
76  
77          assertNotNull(workflowDocument.getDocumentId());
78          Document document = workflowDocument.getDocument();
79          assertNotNull(document);
80  
81          assertNotNull(document.getDateCreated());
82          assertNotNull(document.getDateLastModified());
83          assertNull(document.getDateApproved());
84          assertNull(document.getDateFinalized());
85  
86          assertEquals("", document.getTitle());
87          assertNotNull(document.getDocumentTypeId());
88          assertEquals("TestDocumentType", document.getDocumentTypeName());
89          assertEquals(principalId, document.getInitiatorPrincipalId());
90          assertEquals(DocumentStatus.INITIATED, document.getStatus());
91  
92      }
93  
94      protected String getPrincipalIdForName(String principalName) {
95          return KEWServiceLocator.getIdentityHelperService().getIdForPrincipalName(principalName);
96      }
97  }