View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  	 * Tests the attempt to create a document from a non-existent document type.
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  	 * Tests the attempt to create a document from a document type with no routing path.
55  	 */
56  	@Test public void testCreateNonRoutableDocumentType() throws Exception {
57  		// the BlanketApproveTest is a parent document type that has no routing path defined.  Attempts to
58  		// create documents of this type should return a DocumentCreationException
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       * Tests the attempt to create a document from a document type with no routing path.
69       */
70      @Test public void testCreateInactiveDocumentType() throws Exception {
71          // the CreatedDocumentInactive document type is inactive and should not be able to 
72          // be initiated for a new document
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       * Tests creation of a simple document and verifies it's state.
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 }