/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* $Id: ValidateProcDef.java 1930 2006-11-17 21:41:22Z mlipp $
*
* $Log$
* Revision 1.6 2006/10/13 13:58:32 drmlipp
* Adapted to new environment.
*
* Revision 1.5 2006/10/07 20:41:34 mlipp
* Merged J2EE 1.4 adaptions from test branch.
*
* Revision 1.4 2006/09/29 12:32:09 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3 2006/03/08 14:46:43 drmlipp
* Synchronized with 1.3.3p5.
*
* Revision 1.2 2005/04/08 11:28:06 drmlipp
* Merged changes from 1.3 branch up to 1.3p6.
*
* Revision 1.1.1.4.6.1 2005/03/03 16:32:47 drmlipp
* Added test.
*
* Revision 1.1.1.4 2004/08/18 15:18:46 drmlipp
* Update to 1.2
*
* Revision 1.39 2004/03/18 12:53:01 lipp
* Support for XML as actual parameter.
*
* Revision 1.38 2004/01/27 11:45:33 lipp
* Preserve newlines when reading process definitions.
*
* Revision 1.37 2003/10/21 21:00:45 lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.36 2003/10/07 15:55:57 lipp
* Made tests weblogic compatible.
*
* Revision 1.35 2003/07/11 10:49:26 huaiyang
* Fix the tip error with the error key.
*
* Revision 1.34 2003/07/11 10:30:24 huaiyang
* Error messages further improved.
*
* Revision 1.33 2003/07/10 12:44:17 huaiyang
* Fix the tip error of transition.
*
* Revision 1.32 2003/07/09 07:54:01 huaiyang
* compare the error message with its key.
*
* Revision 1.31 2003/06/27 09:44:13 lipp
* Fixed copyright/license information.
*
* Revision 1.30 2003/06/03 15:37:42 huaiyang
* add the tests of paramTypeMismatch.
*
* Revision 1.29 2003/05/31 18:30:57 lipp
* Fixed test case.
*
* Revision 1.28 2003/05/26 14:31:58 huaiyang
* add the check of loop activities.
*
* Revision 1.27 2003/05/26 12:43:22 huaiyang
* add the test of illegalScriptType and illegalScriptVersion.
*
* Revision 1.26 2003/05/13 08:38:40 huaiyang
* add the test for checking actual params in calling subflow.
*
* Revision 1.25 2003/05/12 09:14:26 huaiyang
* add the test of invalidPriority.
*
* Revision 1.24 2003/05/08 15:01:27 huaiyang
* add the test of emptyActivitySet.
*
* Revision 1.23 2003/04/26 16:46:55 lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.22 2003/04/16 19:25:04 lipp
* Adapted to jdk 1.4
*
* Revision 1.21 2003/03/31 16:50:29 huaiyang
* Logging using common-logging.
*
* Revision 1.20 2003/03/28 12:15:28 huaiyang
* the error text of noprocdata modified.
*
* Revision 1.19 2003/03/07 14:11:51 huaiyang
* set the default locale as chinese, then restore it.
*
* Revision 1.18 2003/03/07 09:35:42 huaiyang
* Changed because of the new ImportMessage.properties.
*
* Revision 1.17 2003/03/07 08:03:48 huaiyang
* retrieve the error message for the Locale.ENGLISH.
*
* Revision 1.16 2003/03/04 13:43:09 huaiyang
* add the test of invalidBlockActivityId.
*
* Revision 1.15 2003/02/17 09:53:53 lipp
* Fixed typo in filename.
*
* Revision 1.14 2002/12/04 16:05:49 lipp
* Fixed minor compilation problem.
*
* Revision 1.13 2002/12/02 16:19:31 huaiyang
* ImportProcessDefinition throws now ImportException.
*
* Revision 1.12 2002/11/25 09:28:53 huaiyang
* New test of validApplicationId.
*
* Revision 1.11 2002/11/13 11:25:43 huaiyang
* NMTOKEN compatible.
*
* Revision 1.10 2002/11/12 14:16:11 huaiyang
* Add test for validating transition restrictions of activity.
*
* Revision 1.9 2002/11/06 12:15:51 huaiyang
* Add the test of invalidExtendedAttribute.
*
* Revision 1.8 2002/11/04 10:57:29 huaiyang
* Add tests for validating transition of activitySet.
*
* Revision 1.7 2002/11/01 12:22:21 huaiyang
* Add the tests of invalidActivitySetTransRefId and invalidActivityTransRefId
*
* Revision 1.6 2002/09/24 12:21:04 huaiyang
* Add test of checking match of formal and actual parameter.
*
* Revision 1.5 2002/09/23 12:04:34 huaiyang
* Remove the test of invalidTool.
*
* Revision 1.4 2002/09/18 14:32:54 huaiyang
* Add testing of participant.
*
* Revision 1.3 2002/09/16 15:31:28 huaiyang
* Add the correct application class.
*
* Revision 1.2 2002/08/30 13:37:05 lipp
* Using Workflow engine facade now.
*
* Revision 1.1 2002/08/15 15:03:19 huaiyang
* Initial.
*
*
*/
package procdef;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.naming.InitialContext;
import javax.security.auth.login.LoginException;
import de.danet.an.util.EJBUtil;
import de.danet.an.util.junit.EJBClientTest;
import de.danet.an.workflow.api.ImportException;
import de.danet.an.workflow.api.PrioritizedMessage;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
import common.UTLoginContext;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* test the functionality of the class
* <code>de.danet.an.workflow.domain.ProcDefValidator</code>.
*/
public class ValidateProcDef extends TestCase {
/** logger of this class */
static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog(ValidateProcDef.class);
private static UTLoginContext plc = null;
static {
try {
plc = new UTLoginContext();
plc.login();
} catch (LoginException e) {
throw new IllegalStateException (e.getMessage ());
}
}
/**
* constructor of this test case.
* @param name name of this test case.
*/
public ValidateProcDef(String name) {
super (name);
}
/**
* build this test suite.
* @return the built test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ValidateProcDef("doubleActivityId"));
suite.addTest(new ValidateProcDef("doubleApplicationId"));
suite.addTest(new ValidateProcDef("doubleProcessId"));
suite.addTest(new ValidateProcDef("doubleTransitionId"));
suite.addTest(new ValidateProcDef("doubleTransitionIdOfActivitySet"));
suite.addTest(new ValidateProcDef("invalidRefActFromIdInTransition"));
suite.addTest(new ValidateProcDef
("invalidRefActFromIdInTransitionOfActivitySet"));
suite.addTest(new ValidateProcDef("invalidRefActToIdInTransition"));
suite.addTest(new ValidateProcDef
("invalidRefActToIdInTransitionOfActivitySet"));
suite.addTest(new ValidateProcDef("invalidRefToolIdInActivity"));
suite.addTest(new ValidateProcDef("invalidRefToolIdInActivitySet"));
suite.addTest(new ValidateProcDef("invalidActivitySetTransRefId"));
suite.addTest(new ValidateProcDef("invalidActivityTransRefId"));
suite.addTest(new ValidateProcDef("invalidBlockActivityId"));
suite.addTest(new ValidateProcDef("invalidExtendedAttribute"));
suite.addTest(new ValidateProcDef("invalidTransitionRestriction"));
suite.addTest(new ValidateProcDef("validApplicationId"));
suite.addTest(new ValidateProcDef("incompleteApplicationDef"));
suite.addTest(new ValidateProcDef("participantNotFound"));
suite.addTest(new ValidateProcDef("doubleParticipantId"));
suite.addTest(new ValidateProcDef("notMatchedFormalAndActualParams"));
suite.addTest(new ValidateProcDef("noProcDataForActualParam"));
suite.addTest(new ValidateProcDef("emptyActivitySet"));
suite.addTest(new ValidateProcDef("invalidPriority"));
suite.addTest(new ValidateProcDef
("noMatchedDataFieldInCallingSubFlow"));
suite.addTest(new ValidateProcDef
("noMatchedActualParamsInCallingSubFlow"));
suite.addTest(new ValidateProcDef
("noMatchedActualParamTypeCallingSubFlow"));
suite.addTest(new ValidateProcDef ("illegalScriptType"));
suite.addTest(new ValidateProcDef ("illegalScriptVersion"));
suite.addTest(new ValidateProcDef ("loopActivities"));
suite.addTest(new ValidateProcDef ("subFlowParamTypeMismatch"));
suite.addTest(new ValidateProcDef ("toolParamTypeMismatch"));
suite.addTest(new ValidateProcDef ("XMLParamsOK"));
suite.addTest(new ValidateProcDef ("XMLToolParamBuggy"));
suite.addTest(new ValidateProcDef ("XMLSubflowParamBuggy"));
suite.addTest(new ValidateProcDef ("invalidJavaType"));
suite.addTest(new ValidateProcDef ("illegalJavaType"));
suite.addTest(new ValidateProcDef ("incompatibleJavaType1"));
suite.addTest(new ValidateProcDef ("incompatibleJavaType2"));
return new EJBClientTest (plc, suite);
}
private ProcessDefinitionDirectory pdd = null;
/**
* Simple test to check the jndi settings
*/
private void connect() throws Exception {
InitialContext ic = new InitialContext();
assertTrue (ic != null);
pdd = getProcessDefinitionDirectory();
}
private ProcessDefinitionDirectory getProcessDefinitionDirectory()
throws Exception {
ProcessDefinitionDirectory pdd
= WorkflowServiceFactory.newInstance()
.newWorkflowService().processDefinitionDirectory();
return pdd;
}
/**
* validate the process definitions from a XPDL file doubleActivityId.xml
* using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void doubleActivityId() throws Exception {
validate("/procdef/doubleActivityId.xml",
"ImportMessages#procdef.activity.ununique");
}
/**
* validate the process definitions from a XPDL file doubleActivityId.xml
* using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void doubleActivityIdOfActivitySet() throws Exception {
validate("/procdef/doubleActivityIdOfActivitySet.xml",
"ImportMessages#procdef.activityset.activity.ununique");
}
/**
* validate the process definitions from a XPDL file
* doubleApplicationId.xml using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void doubleApplicationId() throws Exception {
validate("/procdef/doubleApplicationId.xml",
"ImportMessages#procdef.application.ununique");
}
/**
* validate the process definitions from a XPDL file
* validApplicationId.xml using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void validApplicationId() throws Exception {
validate("/procdef/validApplicationId.xml", null);
}
/**
* validate the process definitions from a XPDL file
* validApplicationId.xml using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void incompleteApplicationDef() throws Exception {
validate("/procdef/incompleteApplicationDef.xml",
"ImportMessages#procdef.application.toolAgentClass");
}
/**
* validate the process definitions from a XPDL file
* doubleProcessId.xml using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void doubleProcessId() throws Exception {
validate("/procdef/doubleProcessId.xml",
"ImportMessages#procdef.process.ununique");
}
/**
* validate the process definitions from a XPDL file
* doubleTransitionId.xml using the ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void doubleTransitionId() throws Exception {
validate("/procdef/doubleTransitionId.xml",
"ImportMessages#procdef.transition.ununique");
}
/**
* validate the process definitions from a XPDL file
* doubleTransitionIdOfActivitySet.xml using the ProcessDefinitionDirectory
* bean.
* @throws Exception if any eror ocurred.
*/
public void doubleTransitionIdOfActivitySet() throws Exception {
validate("/procdef/doubleTransitionIdOfActivitySet.xml",
"ImportMessages#procdef.activityset.transition.ununique");
}
/**
* validate the process definitions from a XPDL file
* invalidRefActFromIdInTransition.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefActFromIdInTransition() throws Exception {
validate("/procdef/invalidRefActFromIdInTransition.xml",
"ImportMessages#procdef.transition.activityid.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidRefActFromIdInTransitionOfActivitySet.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefActFromIdInTransitionOfActivitySet()
throws Exception {
validate ("/procdef/invalidRefActFromIdInTransitionOfActivitySet.xml",
"ImportMessages#procdef.activityset.transition.activityid.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidRefActToIdInTransition.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefActToIdInTransition() throws Exception {
validate("/procdef/invalidRefActToIdInTransition.xml",
"ImportMessages#procdef.transition.activityid.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidRefActToIdInTransitionOfActivitySet.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefActToIdInTransitionOfActivitySet()
throws Exception {
validate("/procdef/invalidRefActToIdInTransitionOfActivitySet.xml",
"ImportMessages#procdef.activityset.transition.activityid.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidRefToolIdInActivity.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefToolIdInActivity() throws Exception {
validate("/procdef/invalidRefToolIdInActivity.xml",
"ImportMessages#procdef.tool.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidRefToolIdInActivitySet.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidRefToolIdInActivitySet() throws Exception {
validate("/procdef/invalidRefToolIdInActivitySet.xml",
"ImportMessages#procdef.tool.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidActivitySetTransRefId.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidActivitySetTransRefId() throws Exception {
validate("/procdef/invalidActivitySetTransRefId.xml",
"ImportMessages#procdef.transitionid.notfound");
}
/**
* Check if all the referenced BlockActivity are defined.
* @throws Exception if any eror ocurred.
*/
public void invalidBlockActivityId() throws Exception {
validate("/procdef/invalidBlockActivityId.xml",
"ImportMessages#procdef.activity.activityset.invalid");
}
/**
* validate the process definitions from a XPDL file
* invalidActivitySetTransRefId.xml using the
* ProcessDefinitionDirectory bean.
* @throws Exception if any eror ocurred.
*/
public void invalidActivityTransRefId() throws Exception {
validate("/procdef/invalidActivityTransRefId.xml",
"ImportMessages#procdef.transitionid.notfound");
}
/**
* validate the process definitions from a XPDL file
* invalidExtendedAttribute.xml using the ProcessDefinitionDirectory bean.
* The extended attribute should have a value as AUTOMATIC or MANUAL,
* otherwise error raised.
* @throws Exception if any eror ocurred.
*/
public void invalidExtendedAttribute() throws Exception {
validate("/procdef/invalidExtendedAttribute.xml",
"ImportMessages#procdef.extendedattr.value.notallowed");
}
/**
* Check if all TransitionRestrictions are valid.
* @throws Exception if any eror ocurred.
*/
public void invalidTransitionRestriction() throws Exception {
validate("/procdef/invalidTransitionRestriction.xml",
"ImportMessages#procdef.activityset.split.transition.notcomplete");
}
/**
* Check if all defined Participant are valid.
* @throws Exception if any eror ocurred.
*/
public void participantNotFound() throws Exception {
validate("/procdef/ParticipantNotFound.xml",
"ImportMessages#procdef.performer.notfound");
}
/**
* Check if any duplicate Participant are defined.
* @throws Exception if any eror ocurred.
*/
public void doubleParticipantId() throws Exception {
validate("/procdef/doubleParticipantId.xml",
"ImportMessages#procdef.participant.ununique");
}
/**
* Check if ActualParameters and FormalParameters are matched.
* @throws Exception if any eror ocurred.
*/
public void notMatchedFormalAndActualParams() throws Exception {
validate("/procdef/notMatchedFormalAndActualParams.xml",
"ImportMessages#procdef.toolimpl.params.notmatched");
}
/**
* Check if all the defined ActualParameters have responding entries
* in DataFields.
* @throws Exception if any eror ocurred.
*/
public void noProcDataForActualParam() throws Exception {
validate("/procdef/noProcDataForActualParam.xml",
"ImportMessages#procdef.toolimpl.params.datanotfound");
}
/**
* Check if the process definition includes an empty activity set.
* @throws Exception if any eror ocurred.
*/
public void emptyActivitySet() throws Exception {
validate("/procdef/emptyActivitySet.xml",
"ImportMessages#procdef.process.activityset.empty");
}
/**
* Check if the process definition includes an invalid priority.
* @throws Exception if any eror ocurred.
*/
public void invalidPriority() throws Exception {
validate("/procdef/invalidPriority.xml",
"ImportMessages#procdef.activity.priority.notallowed");
}
/**
* Check if all the formal OUT- or INOUT- parameters of the called subflow
* reference an existing actual parameter with an existing Datafield.
*/
public void noMatchedDataFieldInCallingSubFlow() throws Exception {
validate("/procdef/noMatchedDataFieldInCallingSubFlow.xml",
"ImportMessages#procdef.activity.subflow.datanotfound");
}
/**
* Check if all the formal OUT- or INOUT- parameters of the called subflow
* reference an existing actual parameter with an existing Datafield.
*/
public void noMatchedActualParamTypeCallingSubFlow() throws Exception {
validate("/procdef/noMatchedActualParamTypeCallingSubFlow.xml",
"ImportMessages#procdef.activity.subflow.paramdatatype.notmatched");
}
/**
* Check if all the formal OUT- or INOUT- parameters of the called subflow
* reference an existing actual parameter.
*/
public void noMatchedActualParamsInCallingSubFlow() throws Exception {
validate("/procdef/noMatchedActualParamsInCallingSubFlow.xml",
"ImportMessages#procdef.activity.subflow.params.notmatched");
}
/**
* Check if the defined script is supported.
*/
public void illegalScriptType() throws Exception {
validate("/procdef/illegalScriptType.xml",
"ImportMessages#package.script.type.unsupported");
}
/**
* Check if the defined script is supported.
*/
public void illegalScriptVersion() throws Exception {
validate("/procdef/illegalScriptVersion.xml",
"ImportMessages#package.script.version.unsupported");
}
/**
* Check if all the activities build a loop
*/
public void loopActivities() throws Exception {
validate("/procdef/loopActivities.xml",
"ImportMessages#procdef.transition.noentry");
}
/**
* Check if formal- and actualParameters match in calling SubFlow.
*/
public void subFlowParamTypeMismatch () throws Exception {
validate("/procdef/subFlowParamTypeMismatch.xml",
"ImportMessages#procdef.activity.subflow.paramdatatype.notmatched");
}
/**
* Check if formal- and actualParameters match in calling tools.
*/
public void toolParamTypeMismatch () throws Exception {
validate("/procdef/toolParamTypeMismatch.xml",
"ImportMessages#procdef.toolimpl.paramsdatatype.notmatched");
}
/**
* Check validity of actual parameters as XML string
*/
public void XMLParamsOK () throws Exception {
validate("/procdef/xmlParamsOK.xml", null);
}
/**
* Check validity of actual parameters as XML string
*/
public void XMLToolParamBuggy () throws Exception {
validate("/procdef/xmlToolParamBuggy.xml",
"ImportMessages#procdef.toolimpl.params.invalidXML");
}
/**
* Check validity of actual parameters as XML string
*/
public void XMLSubflowParamBuggy () throws Exception {
validate("/procdef/xmlSubflowParamBuggy.xml",
"ImportMessages#procdef.subflow.params.invalidXML");
}
/**
* Check validity of actual parameters as XML string
*/
public void invalidJavaType () throws Exception {
validate("/procdef/invalidJavaType.xml",
"ImportMessages#procdef.data.invalidJavaType");
}
/**
* Check validity of actual parameters as XML string
*/
public void illegalJavaType () throws Exception {
validate("/procdef/illegalJavaType.xml",
"ImportMessages#procdef.data.notSerializable");
}
/**
* Check validity of actual parameters as XML string
*/
public void incompatibleJavaType1 () throws Exception {
validate("/procdef/incompatibleJavaType1.xml",
"ImportMessages#procdef.toolimpl.paramsdatatype.notmatched");
}
/**
* Check validity of actual parameters as XML string
*/
public void incompatibleJavaType2 () throws Exception {
validate("/procdef/incompatibleJavaType2.xml",
"ImportMessages#procdef.toolimpl.paramsdatatype.notmatched");
}
private void validate(String file, String errorMessage)
throws Exception {
boolean gotException = false;
// Create process definition directory bean
if (pdd == null) {
pdd = getProcessDefinitionDirectory();
}
InputStream is = getClass().getResourceAsStream(file);
assertTrue (is != null);
BufferedReader br = new BufferedReader
(new InputStreamReader(is, "ISO-8859-1"));
StringBuffer sb = new StringBuffer();
String st;
while ((st = br.readLine()) != null) {
sb.append(st + "\n");
}
List pms = null;
try {
pms = pdd.importProcessDefinitions(sb.toString());
if (pms.size() == 0 && errorMessage != null) {
fail("Failed to identify the errors in imported xpdl files");
}
} catch (ImportException pe) {
pms = pe.messages();
}
List unmappedPms = new ArrayList();
StringBuffer mb = new StringBuffer ();
for (Iterator i = pms.iterator(); i.hasNext(); ) {
PrioritizedMessage pm = (PrioritizedMessage)i.next();
unmappedPms.add(pm.unmappedMessage());
mb.append (" " + pm.unmappedMessage());
}
if (errorMessage != null) {
assertTrue("Expected " + errorMessage + ", got" + mb.toString(),
unmappedPms.contains(errorMessage));
}
}
}