Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions spec/examples/applicantrequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*
*/
import {WorkflowBuilder} from "../../src/model/workflow.builder";
import * as fs from "fs";
import {FunctionDefBuilder} from "../../src/model/function-def.builder";
import {DatabasedSwitchBuilder} from "../../src/model/databased-switch.builder";
import {TransitionDataConditionBuilder} from "../../src/model/transition-data-condition.builder";
import {OperationStateBuilder} from "../../src/model/operation-state.builder";
import {SubFlowStateBuilder} from "../../src/model/sub-flow-state.builder";
import {ActionBuilder} from "../../src/model/action.builder";
import {DefaultTransitionTypeBuilder} from "../../src/model/default-transition-type.builder";
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
import {WorkflowBuilder} from "../../src";
import {FunctionDefBuilder} from "../../src";
import {DatabasedSwitchBuilder} from "../../src";
import {TransitionDataConditionBuilder} from "../../src";
import {OperationStateBuilder} from "../../src";
import {SubFlowStateBuilder} from "../../src";
import {ActionBuilder} from "../../src";
import {DefaultTransitionTypeBuilder} from "../../src";
import {FunctionRefBuilder} from "../../src";


describe("applicationrequest workflow example", () => {
Expand Down
36 changes: 18 additions & 18 deletions spec/examples/booklending.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
import * as fs from 'fs';
import {
ActionBuilder,
DatabasedSwitchBuilder,
Expand All @@ -22,15 +23,14 @@ import {
TransitionDataConditionBuilder,
WorkflowBuilder,
} from '../../src';
import * as fs from 'fs';
import {StartBuilder} from '../../src/model/start.builder';
import {EventStateBuilder} from '../../src/model/event-state.builder';
import {OnEventBuilder} from '../../src/model/on-event.builder';
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
import {FunctionsBuilder} from '../../src/model/functions.builder';
import {EventBasedSwitchBuilder} from '../../src/model/event-based-switch.builder';
import {TransitionEventConditionBuilder} from '../../src/model/transition-event-condition.builder';
import {DelayStateBuilder} from '../../src/model/delay-state.builder';
import {StartBuilder} from "../../src";
import {EventStateBuilder} from "../../src";
import {OnEventBuilder} from "../../src";
import {FunctionRefBuilder} from "../../src";
import {FunctionsBuilder} from "../../src";
import {EventBasedSwitchBuilder} from "../../src";
import {TransitionEventConditionBuilder} from "../../src";
import {DelayStateBuilder} from "../../src";


describe("booklending workflow example", () => {
Expand Down Expand Up @@ -127,11 +127,11 @@ describe("booklending workflow example", () => {
])
.withTransition("Wait two weeks")
.build(),
new DelayStateBuilder()
.withName("Wait two weeks")
.withTimeDelay("PT2W")
.withTransition("Get Book Status")
.build(),
new DelayStateBuilder()
.withName("Wait two weeks")
.withTimeDelay("PT2W")
.withTransition("Get Book Status")
.build(),
new OperationStateBuilder()
.withName("Check Out Book")
.withActions([
Expand All @@ -140,7 +140,7 @@ describe("booklending workflow example", () => {
new FunctionRefBuilder()
.withRefName("Check out book with id")
.withArguments({
"bookid": "${ .book.id }"
"bookid": "${ .book.id }",
})
.build())
.build(),
Expand All @@ -150,14 +150,14 @@ describe("booklending workflow example", () => {
.withRefName("Notify Lender for checkout")
.withArguments({
"bookid": "${ .book.id }",
"lender": "${ .lender }"
"lender": "${ .lender }",
})
.build())
.build()
.build(),

])
.withEnd(true)
.build()
.build(),

])
.withFunctions(new FunctionsBuilder()
Expand Down
3 changes: 2 additions & 1 deletion spec/examples/carauctionbids.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
{
"name": "CarBidEvent",
"type": "carBidMadeType",
"source": "carBidEventSource"
"source": "carBidEventSource",
"kind": "consumed"
}
],
"states": [
Expand Down
12 changes: 6 additions & 6 deletions spec/examples/carauctionbids.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/
import {ActionBuilder, FunctionDefBuilder, WorkflowBuilder} from '../../src';
import * as fs from 'fs';
import {StartBuilder} from '../../src/model/start.builder';
import {EventsBuilder} from '../../src/model/events.builder';
import {EventBuilder} from '../../src/model/event.builder';
import {EventStateBuilder} from '../../src/model/event-state.builder';
import {OnEventBuilder} from '../../src/model/on-event.builder';
import {FunctionRefBuilder} from '../../src/model/function-ref.builder';
import {StartBuilder} from "../../src";
import {EventsBuilder} from "../../src";
import {EventBuilder} from "../../src";
import {EventStateBuilder} from "../../src";
import {OnEventBuilder} from "../../src";
import {FunctionRefBuilder} from "../../src";

describe("carauctionbids workflow example", () => {

Expand Down
45 changes: 45 additions & 0 deletions spec/examples/checkcarvitals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "checkcarvitals",
"name": "Check Car Vitals Workflow",
"version": "1.0",
"start": "WhenCarIsOn",
"states": [
{
"name": "WhenCarIsOn",
"type": "event",
"onEvents": [
{
"eventRefs": [
"CarTurnedOnEvent"
]
}
],
"transition": "DoCarVitalsChecks"
},
{
"name": "DoCarVitalsChecks",
"type": "subflow",
"workflowId": "vitalscheck",
"repeat": {
"stopOnEvents": [
"CarTurnedOffEvent"
]
},
"end": true
}
],
"events": [
{
"name": "CarTurnedOnEvent",
"type": "car.events",
"source": "my/car/start",
"kind": "consumed"
},
{
"name": "CarTurnedOffEvent",
"type": "car.events",
"source": "my/car/start",
"kind": "consumed"
}
]
}
78 changes: 78 additions & 0 deletions spec/examples/checkcarvitals.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2021-Present The Serverless Workflow Specification Authors
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {WorkflowBuilder} from "../../src/model/workflow.builder";
import * as fs from "fs";
import {SubFlowStateBuilder} from "../../src/model/sub-flow-state.builder";
import {EventBuilder, EventsBuilder, EventStateBuilder, OnEventBuilder, RepeatBuilder} from '../../src';


describe("checkcarvitals workflow example", () => {


it('should generate Workflow object', function () {

const workflow = new WorkflowBuilder()
.withId("checkcarvitals")
.withVersion("1.0")
.withName("Check Car Vitals Workflow")
.withStart("WhenCarIsOn")
.withStates([
new EventStateBuilder()
.withName("WhenCarIsOn")
.withOnEvents([
new OnEventBuilder()
.withEventsRef(["CarTurnedOnEvent"])
.build(),
])
.withTransition("DoCarVitalsChecks")
.build(),
new SubFlowStateBuilder()
.withName("DoCarVitalsChecks")
.withWorkflowId("vitalscheck")
.withRepeat(new RepeatBuilder()
.withStopOnEvents(["CarTurnedOffEvent"])
.build())
.withEnd(true)
.build(),
])
.withEvents(
new EventsBuilder()
.withEvents([
new EventBuilder()
.withName("CarTurnedOnEvent")
.withType("car.events")
.withSource("my/car/start")
.build(),
new EventBuilder()
.withName("CarTurnedOffEvent")
.withType("car.events")
.withSource("my/car/start")
.build(),

]).build(),
)
.build();


const expected = JSON.parse(fs.readFileSync("./spec/examples/checkcarvitals.json")
.toLocaleString()) as any;
expect(workflow).toEqual(expected);

});


});
73 changes: 73 additions & 0 deletions spec/examples/provisionorder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"id": "provisionorders",
"version": "1.0",
"name": "Provision Orders",
"description": "Provision Orders and handle errors thrown",
"start": "ProvisionOrder",
"functions": [
{
"name": "provisionOrderFunction",
"operation": "http://myapis.org/provisioningapi.json#doProvision",
"type": "rest"
}
],
"states": [
{
"name": "ProvisionOrder",
"type": "operation",
"actionMode": "sequential",
"actions": [
{
"functionRef": {
"refName": "provisionOrderFunction",
"arguments": {
"order": "${ .order }"
}
}
}
],
"stateDataFilter": {
"output": "${ .exceptions }"
},
"transition": "ApplyOrder",
"onErrors": [
{
"error": "Missing order id",
"transition": "MissingId"
},
{
"error": "Missing order item",
"transition": "MissingItem"
},
{
"error": "Missing order quantity",
"transition": "MissingQuantity"
}
]
},
{
"name": "MissingId",
"type": "subflow",
"workflowId": "handleMissingIdExceptionWorkflow",
"end": true
},
{
"name": "MissingItem",
"type": "subflow",
"workflowId": "handleMissingItemExceptionWorkflow",
"end": true
},
{
"name": "MissingQuantity",
"type": "subflow",
"workflowId": "handleMissingQuantityExceptionWorkflow",
"end": true
},
{
"name": "ApplyOrder",
"type": "subflow",
"workflowId": "applyOrderWorkflowId",
"end": true
}
]
}
Loading