public void SingleStartAndEndNode() { var builder = new WorkflowDefinitionBuilder(); bool executed = false; var workflowDefinition = builder .AddNode() .WithName("start") .IsStartNode() .AddTransition() .WithName("transition") .To("end") .BuildTransition() .BuildMockNode(e => executed = e) .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); var instance = new WorkflowEngineBuilder().Build().StartNewInstance(workflowDefinition); Assert.That(executed); Assert.That(instance.IsFinished); }
public void PersistSingleExecution() { var builder = new WorkflowDefinitionBuilder(); var workflowDefinition = builder .WithIdentifier("testWorkflowDefinition") .AddNode() .WithName("start") .WithOperation<TestOperation>() .IsStartNode() .AddTransition() .WithName("transition") .To("end") .BuildTransition() .BuildNode() .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow<TestData>(); var instance = new WorkflowEngineBuilder().ConfigureServiceLocator() .ImportModule(new SqlPersistenceTestModule(SessionFactory)) .Build() .StartNewInstance(workflowDefinition, new TestData()); using (var session = SessionFactory.OpenSession()) Assert.That(session.QueryOver<WorkflowDefinitionModel>().Where(d => d.Identifier == workflowDefinition.Identifier).SingleOrDefault(), Is.Not.Null); Assert.False(instance.IsFinished); }
public void SingleTask() { var builder = new WorkflowDefinitionBuilder(); var workflowDefinition = builder .AddNode() .WithName("myTask") .IsStartNode() .AddTransition() .WithName("transition") .To("end") .BuildTransition() .BuildUserTask() .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); var workflowEngine = new WorkflowEngineBuilder().ConfigureServiceLocator().ImportModule(new Neo4jPersistenceModule()).Build(); var instance = workflowEngine.StartNewInstance(workflowDefinition); Assert.False(instance.IsFinished); var userTask = workflowEngine.FindTask("myTask", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask); instance = workflowEngine.Load(instance.Identifier); Assert.That(instance.IsFinished); }
public void SingleTask() { var builder = new WorkflowDefinitionBuilder(); bool executed = false; var workflowDefinition = builder .AddNode() .WithName("myTask") .IsStartNode() .AddTransition() .WithName("transition") .To("end") .BuildTransition() .BuildUserTask() .AddNode() .WithName("end") .IsEndNode() .BuildMockNode(e => executed = e) .BuildWorkflow(); var workflowEngine = new WorkflowEngineBuilder().Build(); var instance = workflowEngine.StartNewInstance(workflowDefinition); Assert.False(executed); var userTask = workflowEngine.FindTask("myTask", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask); Assert.That(executed); Assert.That(instance.IsFinished); }
public void TransformsEmptyWorkflowDefinition() { var transformer = new Transform.WorkflowDefinitionTransformer(); var emptyWorkflow = new WorkflowDefinitionBuilder().BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(emptyWorkflow); Assert.That(result, Is.Not.Null); Assert.That(!result.Nodes.Any()); }
public void TwoParallelTasks() { var builder = new WorkflowDefinitionBuilder(); var workflowDefinition = builder .AddNode() .WithName("start") .IsStartNode() .AddTransition() .To("task1") .BuildTransition() .AddTransition() .To("task2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("task1") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("task2") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("join") .AddTransition() .To("end") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); var workflowEngine = new WorkflowEngineBuilder().ConfigureServiceLocator().ImportModule(new Neo4jPersistenceTestModule(GraphClient)).Build(); var instance = workflowEngine.StartNewInstance(workflowDefinition); Assert.False(instance.IsFinished); var userTask = workflowEngine.FindTask("task1", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask); Assert.False(instance.IsFinished); var userTask2 = workflowEngine.FindTask("task2", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask2); instance = workflowEngine.Load(instance.Identifier); Assert.That(instance.IsFinished); }
public void SetsWorkflowOperationTypeProperty() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .AddNode() .WithName("node") .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); Assert.That(result.OperationType, Is.EqualTo(workflow.Operation.AssemblyQualifiedName)); }
public void SetsInitialNodeProperty() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .AddNode() .WithName("node") .IsStartNode() .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); Assert.That(result.Nodes.First().IsInitialNode); }
public void SingleBranch_ExecutesNodeAfterJoin() { var builder = new WorkflowDefinitionBuilder(); bool executed = false; var workflowDefinition = builder .AddNode() .WithName("split") .IsStartNode() .AddTransition() .WithName("transition1") .To("subNode1") .BuildTransition() .AddTransition() .WithName("transition2") .To("subNode2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("subNode1") .AddTransition() .WithName("subNodeToEnd") .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("subNode2") .AddTransition() .WithName("subNode2ToEnd") .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("join") .AddTransition() .WithName("joinToEnd") .To("end") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("end") .IsEndNode() .BuildMockNode(e => executed = e) .BuildWorkflow(); var instance = new WorkflowEngineBuilder().Build().StartNewInstance(workflowDefinition); Assert.That(executed); Assert.That(instance.IsFinished); }
public void SingleBranch_ExecutesNodeAfterJoin() { var builder = new WorkflowDefinitionBuilder(); bool executed = false; var workflowDefinition = builder .AddNode() .WithName("split") .IsStartNode() .AddTransition() .WithName("transition1") .To("subNode1") .BuildTransition() .AddTransition() .WithName("transition2") .To("subNode2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("subNode1") .AddTransition() .WithName("subNodeToEnd") .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("subNode2") .AddTransition() .WithName("subNode2ToEnd") .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("join") .AddTransition() .WithName("joinToEnd") .To("end") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); new WorkflowEngineBuilder().ConfigureServiceLocator() .ImportModule(new Neo4jPersistenceTestModule(GraphClient)) .Build() .StartNewInstance(workflowDefinition); }
public void TransformsSingleNodeWorkflowDefinition() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .AddNode() .WithName("node") .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); Assert.That(result, Is.Not.Null); Assert.That(result.Nodes.Count, Is.EqualTo(1)); Assert.That(result.Nodes.First().Identifier, Is.EqualTo("node")); }
public void PersistNestedWorkflow() { var builder = new WorkflowDefinitionBuilder(); var workflowDefinition = builder .WithIdentifier("testWorkflowDefinition") .AddNode() .WithName("start") .WithOperation<TestOperation>() .IsStartNode() .AddTransition() .WithName("transition") .To("nested") .BuildTransition() .BuildNode() .AddNode() .WithName("nested") .AddTransition() .WithName("nestedToEnd") .To("end") .BuildTransition() .BuildSubWorkflow(new WorkflowDefinitionBuilder() .WithIdentifier("subWorkflowDefinition") .AddNode() .IsStartNode() .IsEndNode() .WithName("subWorkflowNode") .WithOperation<TestOperation>() .BuildNode() .AsDefinitionBuilder()) .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); var instance = new WorkflowEngineBuilder().ConfigureServiceLocator() .ImportModule(new Neo4jPersistenceTestModule(GraphClient)) .Build() .StartNewInstance(workflowDefinition); }
public void JoinWaitsOnNestedTask() { var builder = new WorkflowDefinitionBuilder(); bool executed = false; var workflowDefinition = builder .AddNode() .WithName("start") .IsStartNode() .AddTransition() .To("task1") .BuildTransition() .AddTransition() .To("path2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("task1") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("path2") .AddTransition() .To("nestedSplit") .BuildTransition() .BuildNode() .AddNode() .WithName("nestedSplit") .AddTransition() .To("nestedTask") .BuildTransition() .AddTransition() .To("nestedPath2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("nestedTask") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("nestedPath2") .AddTransition() .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("join") .AddTransition() .To("end") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("end") .IsEndNode() .BuildMockNode(e => executed = e) .BuildWorkflow(); var workflowEngine = new WorkflowEngineBuilder().Build(); var instance = workflowEngine.StartNewInstance(workflowDefinition); Assert.False(executed); var userTask = workflowEngine.FindTask("task1", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask); Assert.False(executed); var nestedTask = workflowEngine.FindTask("nestedTask", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(nestedTask); Assert.That(instance.IsFinished); }
public void AddsOutgoingTransition() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .AddNode() .WithName("node") .AddTransition() .WithName("toEnd") .To("end") .BuildTransition() .BuildNode() .AddNode() .WithName("end") .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); var startNode = result.Nodes.First(n => n.Identifier == "node"); Assert.That(startNode.OutgoingTransitions.Count, Is.EqualTo(1)); var transition = startNode.OutgoingTransitions.First(); Assert.That(transition.Identifier, Is.EqualTo("toEnd")); Assert.That(transition.Source, Is.EqualTo("node")); Assert.That(transition.Destination, Is.EqualTo("end")); Assert.False(transition.IsDefault); }
public void SetDefaultPropertyOnTransition() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .AddNode() .WithName("node") .AddTransition() .WithName("toEnd") .To("end") .IsDefault() .BuildTransition() .BuildNode() .AddNode() .WithName("end") .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); var startNode = result.Nodes.First(n => n.Identifier == "node"); var transition = startNode.OutgoingTransitions.First(); Assert.That(transition.IsDefault); }
public void TransformsNestedWorkflow() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .WithIdentifier("testWorkflowDefinition") .AddNode() .WithName("start") .IsStartNode() .AddTransition() .WithName("transition") .To("nested") .BuildTransition() .BuildNode() .AddNode() .WithName("nested") .AddTransition() .WithName("nestedToEnd") .To("end") .BuildTransition() .BuildSubWorkflow(new WorkflowDefinitionBuilder() .WithIdentifier("subWorkflowDefinition") .AddNode() .IsStartNode() .IsEndNode() .WithName("subWorkflowNode") .BuildNode() .AsDefinitionBuilder()) .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); var nestedWorkflowNode = result.Nodes.First(n => n.Identifier == "nested"); Assert.That(nestedWorkflowNode, Is.InstanceOf<WorkflowDefinitionModel>()); }
private WorkflowDefinitionBuilder BuildWorkflowDefinition(WorkflowDefinitionBuilder builder, WorkflowDefinitionModel model) { builder.WithIdentifier(model.Identifier); foreach (var node in model.Nodes) { NodeBuilder nodeBuilder = builder.AddNode() .WithName(node.Identifier); if (node.OperationType != null) { nodeBuilder.WithOperation(Type.GetType(node.OperationType)); } if (node.IsInitialNode) { nodeBuilder.IsStartNode(); } if (node.IsEndNode) { nodeBuilder.IsEndNode(); } foreach (var transition in node.OutgoingTransitions) { TransitionBuilder transitionBuilder = nodeBuilder.AddTransition() .WithName(transition.Identifier) .To(transition.Destination); if (transition.IsDefault) { transitionBuilder.IsDefault(); } transitionBuilder.BuildTransition(); } BuildNode(builder, nodeBuilder, (dynamic) node); } return builder; }
public IWorkflowDefinition TransformBack(WorkflowDefinitionModel model) { var builder = new WorkflowDefinitionBuilder(); return BuildWorkflowDefinition(builder, model).BuildWorkflow(); }
private void BuildNode(WorkflowDefinitionBuilder workflowBuilder, NodeBuilder nodeBuilder, WorkflowDefinitionModel node) { nodeBuilder.BuildSubWorkflow(BuildWorkflowDefinition(workflowBuilder, node)); }
private void BuildNode(WorkflowDefinitionBuilder workflowBuilder, NodeBuilder nodeBuilder, NodeModel node) { nodeBuilder.BuildNode(); }
public void SetsIdentifierProperty() { var transformer = new Transform.WorkflowDefinitionTransformer(); var workflow = new WorkflowDefinitionBuilder() .WithIdentifier("ident") .AddNode() .WithName("node") .BuildNode() .BuildWorkflow(); WorkflowDefinitionModel result = transformer.Transform(workflow); Assert.That(result.Identifier, Is.EqualTo("ident")); }
public void JoinWaitsOnNestedTask() { var builder = new WorkflowDefinitionBuilder(); var workflowDefinition = builder .AddNode() .WithName("start") .IsStartNode() .AddTransition() .To("task1") .BuildTransition() .AddTransition() .To("path2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("task1") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("path2") .AddTransition() .To("nestedSplit") .BuildTransition() .BuildNode() .AddNode() .WithName("nestedSplit") .AddTransition() .To("nestedTask") .BuildTransition() .AddTransition() .To("nestedPath2") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("nestedTask") .AddTransition() .To("join") .BuildTransition() .BuildUserTask() .AddNode() .WithName("nestedPath2") .AddTransition() .To("join") .BuildTransition() .BuildNode() .AddNode() .WithName("join") .AddTransition() .To("end") .BuildTransition() .BuildParallelGateway() .AddNode() .WithName("end") .IsEndNode() .BuildNode() .BuildWorkflow(); var workflowEngine = new WorkflowEngineBuilder().ConfigureServiceLocator().ImportModule(new SqlPersistenceTestModule(SessionFactory)).Build(); var instance = workflowEngine.StartNewInstance(workflowDefinition); Assert.False(instance.IsFinished); var userTask = workflowEngine.FindTask("task1", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(userTask); instance = workflowEngine.Load(instance.Identifier); Assert.That(instance.IsFinished); var nestedTask = workflowEngine.FindTask("nestedTask", instance.WorkflowInstanceIdentifier); workflowEngine.Complete(nestedTask); instance = workflowEngine.Load(instance.Identifier); Assert.That(instance.IsFinished); }