001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.postprocessor;
018:
019: import org.junit.Test;
020: import org.kuali.workflow.test.WorkflowTestCase;
021:
022: import edu.iu.uis.eden.DocumentRouteLevelChange;
023: import edu.iu.uis.eden.DocumentRouteStatusChange;
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.clientapp.WorkflowDocument;
027: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
028:
029: public class PostProcessorTest extends WorkflowTestCase {
030:
031: private static final String APPLICATION_CONTENT = "<some><application>content</application></some>";
032: private static final String DOC_TITLE = "The Doc Title";
033:
034: protected void loadTestData() throws Exception {
035: loadXmlFile("PostProcessorConfig.xml");
036: }
037:
038: /**
039: * Tests that modifying a document in the post processor works. This test will do a few things:
040: *
041: * 1) Change the document content in the post processor
042: * 2) Send an app specific FYI request to the initiator of the document
043: * 3) Modify the document title.
044: *
045: * This test is meant to expose the bug KULWF-668 where it appears an OptimisticLockException is
046: * being thrown after returning from the EPIC post processor.
047: */
048: @Test
049: public void testModifyDocumentInPostProcessor() throws Exception {
050: WorkflowDocument document = new WorkflowDocument(
051: new NetworkIdVO("ewestfal"),
052: "testModifyDocumentInPostProcessor");
053: document.saveDocument("");
054: assertEquals("application content should be empty initially",
055: "", document.getApplicationContent());
056: assertNull("Doc title should be empty initially", document
057: .getTitle());
058:
059: // now route the document, it should through a 2 nodes, then go PROCESSED then FINAL
060: document.routeDocument("");
061: assertEquals("Should have transitioned nodes twice", 2,
062: DocumentModifyingPostProcessor.levelChanges);
063: assertTrue("SHould have called the processed status change",
064: DocumentModifyingPostProcessor.processedChange);
065: assertTrue("Document should be final.", document.stateIsFinal());
066: assertEquals(
067: "Application content should have been sucessfully modified.",
068: APPLICATION_CONTENT, document.getApplicationContent());
069:
070: // check that the title was modified successfully
071: assertEquals("Wrong doc title", DOC_TITLE, document.getTitle());
072:
073: // check that the document we routed from the post processor exists
074: assertNotNull(
075: "SHould have routed a document from the post processor.",
076: DocumentModifyingPostProcessor.routedDocumentId);
077: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
078: DocumentModifyingPostProcessor.routedDocumentId);
079: assertTrue("document should be enroute", document
080: .stateIsEnroute());
081: assertEquals("Document should have 1 pending request.", 1,
082: KEWServiceLocator.getActionRequestService()
083: .findPendingByDoc(document.getRouteHeaderId())
084: .size());
085: assertTrue("ewestfal should have an approve request.", document
086: .isApprovalRequested());
087: document.approve("");
088: assertTrue("Document should be final.", document.stateIsFinal());
089: }
090:
091: public static class DocumentModifyingPostProcessor extends
092: DefaultPostProcessor {
093:
094: public static boolean processedChange = false;
095: public static int levelChanges = 0;
096: public static Long routedDocumentId;
097:
098: public ProcessDocReport doRouteStatusChange(
099: DocumentRouteStatusChange statusChangeEvent)
100: throws Exception {
101: if (EdenConstants.ROUTE_HEADER_PROCESSED_CD
102: .equals(statusChangeEvent.getNewRouteStatus())) {
103: WorkflowDocument document = new WorkflowDocument(
104: new NetworkIdVO("ewestfal"), statusChangeEvent
105: .getRouteHeaderId());
106: document.setApplicationContent(APPLICATION_CONTENT);
107: document.setTitle(DOC_TITLE);
108: document.saveRoutingData();
109: // now route another document from the post processor, sending it an adhoc request
110: WorkflowDocument ppDocument = new WorkflowDocument(
111: new NetworkIdVO("user1"),
112: "testModifyDocumentInPostProcessor");
113: routedDocumentId = ppDocument.getRouteHeaderId();
114: ppDocument.appSpecificRouteDocumentToUser(
115: EdenConstants.ACTION_REQUEST_APPROVE_REQ,
116: "AdHoc", "", new NetworkIdVO("ewestfal"), "",
117: true);
118: ppDocument.routeDocument("");
119: processedChange = true;
120: }
121: return new ProcessDocReport(true);
122: }
123:
124: public ProcessDocReport doRouteLevelChange(
125: DocumentRouteLevelChange levelChangeEvent)
126: throws Exception {
127: levelChanges++;
128: WorkflowDocument document = new WorkflowDocument(
129: new NetworkIdVO("ewestfal"), levelChangeEvent
130: .getRouteHeaderId());
131: document.setTitle("Current level change: " + levelChanges);
132: document.saveRoutingData();
133: return new ProcessDocReport(true);
134: }
135:
136: }
137:
138: }
|