⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdefinitioncycle.java

📁 一个很好的微工作流内核
💻 JAVA
字号:
package com.microworkflow.test;import com.microworkflow.execution.Performer;import com.microworkflow.process.*;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;/** * JUnit test * @author Ringo De Smet */public class TestDefinitionCycle extends TestCase {	public int i = 0;	public static final int MAX=10000;		public static Test suite() {		return new TestSuite(TestDefinitionCycle.class);	}	public void testStackOverFlow() {		try {			Workflow workflow = new Workflow();			workflow.setDefinition(this.getDefinition());			WorkflowContext wc = new WorkflowContext();			wc.put("Object1", "foo");			wc.put("Object2", "bar");			workflow.executeWith(wc);		} catch (StackOverflowError soe) {			fail("Endless loop detected!");		}		assertTrue(i==MAX);	}	/**	 * The chain of activity is: work1, test1, work2, test2, back to work1, etc.	 * 	 * @return the workflow definition.	 */	protected Activity getDefinition() {		Activity performer1 = new Primitive("Object1", new Performer() {			public Object execute() {				i=i+2;				return null;			}		});		Activity performer2 = new Primitive("Object2", new Performer() {			public Object execute() {				i=i-1;				return null;			}		});		Activity loopFrom2BackTo1 = performer2.addStep(performer1);		Activity end = new NullActivity();		Conditional test1 =			new Conditional(new SomeCondition(MAX), null, end);		Conditional test2 =			new Conditional(new SomeCondition(MAX), null, end);		Activity performer1PlusTest = performer1.addStep(test1);		Activity performer2PlusTest = performer2.addStep(test2);		test1.setThenBranch(performer2PlusTest);		test2.setThenBranch(performer1PlusTest);		return performer1PlusTest;	}	protected class SomeCondition extends TestCondition {		protected int max;		public SomeCondition(int max) {			this.max = max;		}		public boolean evaluate() {			return i < max;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -