📄 parsetest.java
字号:
package org.jbpm.par;
import java.io.*;
import java.util.*;
import junit.framework.*;
import org.apache.commons.logging.*;
import org.jbpm.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.definition.impl.*;
public class ParseTest extends TestCase {
static { TestHelper.initLogging(); }
public ParseTest(String name) {
super(name);
}
public void testDefinitionParsing() throws Exception {
InputStream inputStream = ParseTest.class.getClassLoader().getResourceAsStream("process/completeprocess.xml");
DefinitionImpl definition = DefinitionParser.parse( inputStream );
assertEquals( "complete process", definition.getName());
assertEquals( "complete process description", definition.getDescription() );
// check the actors
SwimlaneImpl actor = definition.getSwimlane( "initiator" );
assertNull( actor.getAssignmentDelegation() );
actor = definition.getSwimlane( "boss" );
assertEquals( "boss.AssignmentHandler", actor.getAssignmentDelegation().getClassName() );
actor = definition.getSwimlane( "hr mgr" );
assertEquals( "hr mgr.AssignmentHandler", actor.getAssignmentDelegation().getClassName() );
// check the variables
List types = definition.getTypes();
assertNotNull( types );
assertEquals( 3, types.size() );
TypeImpl transientType = (TypeImpl) types.get(0);
assertNull( transientType.getSerializerDelegation() );
TypeImpl dateType = (TypeImpl) types.get(1);
assertEquals( "java.util.Date", dateType.getJavaType() );
assertEquals( "date type description", dateType.getDescription() );
assertEquals( "date type serializer configuration", dateType.getSerializerDelegation().getConfiguration() );
assertEquals( 4, definition.getVariables().size() );
Collection expectedVariableNames = Arrays.asList( new String[] { "start.date", "end.date", "do.not.store", "dont.store.this.either" } );
Iterator iter = definition.getVariables().keySet().iterator();
while (iter.hasNext()) {
assertTrue( expectedVariableNames.contains( iter.next() ) );
}
TypeImpl booleanType = (TypeImpl) types.get(2);
assertEquals( "java.lang.Boolean", booleanType.getJavaType() );
assertEquals( "boolean type serializer configuration", booleanType.getSerializerDelegation().getConfiguration() );
// check the startstate
assertSame( definition.getStartState(), definition.getNode( "request" ) );
assertEquals( "initiator", definition.getStartState().getSwimlane().getName() );
assertEquals( 1, definition.getStartState().getLeavingTransitions().size() );
// check one node of every type
NodeImpl node = definition.getNode("enough holidays left ?");
assertEquals( DecisionImpl.class, node.getClass() );
assertEquals( 2, node.getLeavingTransitions().size() );
assertEquals( "evaluation", node.getLeavingTransition( "enough holidays" ).getTo().getName() );
assertEquals( "end", node.getLeavingTransition( "not enough holidays" ).getTo().getName() );
assertEquals( "check.in.ErpSystem", ((DecisionImpl)node).getDecisionDelegation().getClassName() );
node = definition.getNode("evaluation");
assertEquals( StateImpl.class, node.getClass() );
assertEquals( "boss", ((StateImpl)node).getSwimlane().getName() );
assertEquals( 3, node.getLeavingTransitions().size() );
assertEquals( "fork", node.getLeavingTransition( "approve" ).getTo().getName() );
assertEquals( "change request", node.getLeavingTransition( "disapprove" ).getTo().getName() );
assertEquals( "end", node.getLeavingTransition( "refuse" ).getTo().getName() );
List actions = node.getLeavingTransition( "refuse" ).getActions();
assertEquals( 2, actions.size() );
assertEquals( "send.notification.Email", ((ActionImpl)actions.get(0)).getActionDelegation().getClassName() );
assertSame( EventType.TRANSITION, ((ActionImpl)actions.get(0)).getEventType() );
assertEquals( "send.another.notification.Email", ((ActionImpl)actions.get(1)).getActionDelegation().getClassName() );
assertSame( EventType.TRANSITION, ((ActionImpl)actions.get(1)).getEventType() );
node = definition.getNode("fork");
assertEquals( ForkImpl.class, node.getClass() );
assertEquals( 2, node.getLeavingTransitions().size() );
// check the endstate
assertSame( definition.getEndState(), definition.getNode( "end" ) );
assertNull( definition.getEndState().getSwimlane() );
// check the process action
ActionImpl action = (ActionImpl) definition.getActions().get(0);
assertSame( EventType.PROCESS_END, action.getEventType() );
assertEquals( "send.notification.email.to.boss.and.Requester", action.getActionDelegation().getClassName() );
}
public void testNoSwimlaneInStartStateTest() throws Exception {
InputStream inputStream = ParseTest.class.getClassLoader().getResourceAsStream("process/noswimlaneprocess.xml");
DefinitionParser.parse( inputStream );
}
public void testNonExistingReferenceTest() throws Exception {
InputStream inputStream = ParseTest.class.getClassLoader().getResourceAsStream("process/faultyreferenceprocess.xml");
try {
DefinitionParser.parse( inputStream );
fail( "expected JpdlException" );
} catch (JpdlException e) {
// OK
}
}
private static Log log = LogFactory.getLog(ParseTest.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -