001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.edl.impl;
017
018 import static org.junit.Assert.assertTrue;
019
020 import org.apache.log4j.Logger;
021 import org.junit.Test;
022 import org.kuali.rice.edl.framework.workflow.EDocLitePostProcessor;
023 import org.kuali.rice.kew.test.KEWTestCase;
024
025
026 /**
027 * This is a Test class to verify the edoc lite post processor.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 *
031 */
032 public class EDocLitePostProcessorTest extends KEWTestCase {
033 private static final Logger LOG = Logger.getLogger(EDocLitePostProcessorTest.class);
034
035 private static final String CONTEXT_NAME = "/edl-test";
036
037 @Test
038 public void junk() {
039
040 }
041 /*
042 @Test
043 public void testPostEvent() throws Exception {
044 String dummyData = "testing this stuff";
045 Integer testServerPort = Integer.valueOf(getJettyServerPort() + 1);
046 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), "TestDocumentType");
047 String applicationContent = "<data><edlContent><edl><eventNotificationURL>" + ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.KEW_URL_HOST) + ":" + testServerPort + CONTEXT_NAME + "</eventNotificationURL><testThisData>" + dummyData + "</testThisData></edl></edlContent></data>";
048 document.setApplicationContent(applicationContent);
049 document.saveDocumentData();
050
051 JettyServer server = null;
052 try {
053 server = new JettyServer(testServerPort.intValue(), CONTEXT_NAME, EDocLiteTestServlet.class);
054 server.setTestMode(true);
055 server.setFailOnContextFailure(true);
056 server.start();
057
058 EDocLitePostProcessor postProcessor = new EDocLitePostProcessor();
059 postProcessor.doActionTaken(new ActionTakenEvent(document.getDocumentId(), document.getAppDocId(), new ActionTakenValue()));
060 String eventType = EDocLitePostProcessor.EVENT_TYPE_ACTION_TAKEN;
061 testPostProcessorMethod(document.getDocumentId(), dummyData, eventType);
062
063 postProcessor = new EDocLitePostProcessor();
064 postProcessor.doRouteLevelChange(new DocumentRouteLevelChange(document.getDocumentId(), document.getAppDocId(), 1, 2, null, null, null, null));
065 eventType = EDocLitePostProcessor.EVENT_TYPE_ROUTE_LEVEL_CHANGE;
066 testPostProcessorMethod(document.getDocumentId(), dummyData, eventType);
067
068 postProcessor = new EDocLitePostProcessor();
069 postProcessor.doRouteStatusChange(new DocumentRouteStatusChange(document.getDocumentId(), document.getAppDocId(), KewApiConstants.ROUTE_HEADER_INITIATED_CD, KewApiConstants.ROUTE_HEADER_ENROUTE_CD));
070 eventType = EDocLitePostProcessor.EVENT_TYPE_ROUTE_STATUS_CHANGE;
071 testPostProcessorMethod(document.getDocumentId(), dummyData, eventType);
072
073 postProcessor = new EDocLitePostProcessor();
074 postProcessor.doDeleteRouteHeader(new DeleteEvent(document.getDocumentId(), document.getAppDocId()));
075 eventType = EDocLitePostProcessor.EVENT_TYPE_DELETE_ROUTE_HEADER;
076 testPostProcessorMethod(document.getDocumentId(), dummyData, eventType);
077
078 } finally {
079 if (server != null) {
080 try {
081 server.stop();
082 } catch (Exception e) {
083 LOG.warn("Failed to shutdown one of the lifecycles!", e);
084 }
085 }
086 }
087 } */
088
089 private void testPostProcessorMethod(String documentId, String dummyData, String eventType) {
090 int maxWaitSeconds = EDocLitePostProcessor.SUBMIT_URL_MILLISECONDS_WAIT + 10000;
091 assertTrue("Test Servlet data map should not be null after wait period", waitForData(maxWaitSeconds, 5000));
092 testForStringExistence("Document Id", documentId);
093 testForStringExistence("Dummy Data", dummyData);
094 testForStringExistence("Event Type '" + eventType + "'", eventType);
095 }
096
097 private void testForStringExistence(String dataDescriptor, String dataToFind) {
098 assertTrue(dataDescriptor = " should come back as part of the post data but didn't", EDocLiteTestServlet.postData.contains(dataToFind));
099 }
100
101 public static boolean waitForData(int maxWaitMilliseconds, int pauseMilliseconds) {
102 boolean valueNotNull = false;
103 boolean interrupted = false;
104 long startTimeMs = System.currentTimeMillis();
105 long endTimeMs = startTimeMs + maxWaitMilliseconds;
106
107 try {
108 Thread.sleep(pauseMilliseconds / 10); // the first time through, sleep a fraction of the specified time
109 } catch (InterruptedException e) {
110 interrupted = true;
111 }
112 valueNotNull = EDocLiteTestServlet.postData != null;
113 LOG.debug("starting wait loop");
114 while (!interrupted && !valueNotNull && (System.currentTimeMillis() < endTimeMs)) {
115 try {
116 if (LOG.isDebugEnabled()) {
117 LOG.debug("sleeping for " + pauseMilliseconds + " ms");
118 }
119 Thread.sleep(pauseMilliseconds);
120 } catch (InterruptedException e) {
121 interrupted = true;
122 }
123 LOG.debug("checking wait loop sentinel");
124 valueNotNull = EDocLiteTestServlet.postData != null;
125 }
126 LOG.debug("finished wait loop (" + valueNotNull + ")");
127
128 return valueNotNull;
129 }
130 }