use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.
the class ServerlessWorkflowParsingTest method testSpecExamplesParsing.
@ParameterizedTest
@ValueSource(strings = { "/examples/applicantworkflow.sw.json", "/exec/error.sw.json", "/exec/callback.sw.json", "/exec/compensation.sw.json", "/exec/compensation.end.sw.json", "/exec/foreach.sw.json" })
public void testSpecExamplesParsing(String workflowLocation) throws IOException {
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
assertNotNull(workflow);
assertNotNull(workflow.getId());
assertNotNull(workflow.getName());
assertNotNull(workflow.getStates());
assertTrue(workflow.getStates().size() > 0);
RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation);
assertNotNull(process);
assertNotNull(process.getId());
}
use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.
the class ServerlessWorkflowParsingTest method testSpecOpenApiFunctionParsing.
@ParameterizedTest
@ValueSource(strings = { "/exec/openapi-greeting-operation.sw.json" })
public void testSpecOpenApiFunctionParsing(String workflowLocation) throws IOException {
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
assertNotNull(workflow);
assertNotNull(workflow.getId());
assertNotNull(workflow.getName());
assertNotNull(workflow.getStates());
assertTrue(workflow.getStates().size() > 0);
assertEquals(1, workflow.getFunctions().getFunctionDefs().size());
RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation);
assertNotNull(process);
assertNotNull(process.getId());
}
use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.
the class ServerlessWorkflowParsingTest method testMinimumWorkflow.
@Test
public void testMinimumWorkflow() {
Workflow workflow = new Workflow();
workflow.setId("javierito");
Start start = new Start();
start.setStateName("javierito");
End end = new End();
end.setTerminate(true);
SleepState startState = new SleepState();
startState.setType(Type.SLEEP);
startState.setDuration("1s");
startState.setName("javierito");
startState.setEnd(end);
workflow.setStates(Collections.singletonList(startState));
workflow.setStart(start);
ServerlessWorkflowParser parser = ServerlessWorkflowParser.of(workflow, JavaKogitoBuildContext.builder().build());
Process process = parser.getProcessInfo().info();
assertSame(process, parser.getProcessInfo().info());
assertEquals(ServerlessWorkflowParser.DEFAULT_NAME, process.getName());
assertEquals(ServerlessWorkflowParser.DEFAULT_VERSION, process.getVersion());
assertEquals(ServerlessWorkflowParser.DEFAULT_PACKAGE, process.getPackageName());
}
use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.
the class ServerlessWorkflowParser method parseProcess.
private GeneratedInfo<KogitoWorkflowProcess> parseProcess() {
String workflowStartStateName = workflow.getStart().getStateName();
if (workflowStartStateName == null || workflowStartStateName.trim().isEmpty()) {
throw new IllegalArgumentException("workflow does not define a starting state");
}
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess(workflow.getId()).name(workflow.getName() == null ? DEFAULT_NAME : workflow.getName()).version(workflow.getVersion() == null ? DEFAULT_VERSION : workflow.getVersion()).packageName(workflow.getMetadata() != null ? workflow.getMetadata().getOrDefault("package", DEFAULT_PACKAGE) : DEFAULT_PACKAGE).visibility("Public").variable(DEFAULT_WORKFLOW_VAR, new ObjectDataType(JsonNode.class), ObjectMapperFactory.get().createObjectNode());
ParserContext parserContext = new ParserContext(idGenerator, factory, context);
Constants constants = workflow.getConstants();
if (constants != null) {
factory.metaData(Metadata.CONSTANTS, constants.getConstantsDef());
}
Collection<StateHandler<?>> handlers = workflow.getStates().stream().map(state -> StateHandlerFactory.getStateHandler(state, workflow, parserContext)).filter(Optional::isPresent).map(Optional::get).filter(state -> !state.usedForCompensation()).collect(Collectors.toList());
handlers.forEach(StateHandler::handleStart);
handlers.forEach(StateHandler::handleEnd);
handlers.forEach(StateHandler::handleState);
handlers.forEach(StateHandler::handleTransitions);
handlers.forEach(StateHandler::handleErrors);
handlers.forEach(StateHandler::handleConnections);
if (parserContext.isCompensation()) {
factory.metaData(Metadata.COMPENSATION, true);
factory.addCompensationContext(workflow.getId());
}
return new GeneratedInfo<>(factory.validate().getProcess(), parserContext.generatedFiles());
}
use of io.serverlessworkflow.api.Workflow in project kogito-runtimes by kiegroup.
the class BuildExpressionsTest method testReplaceExpr.
@Test
void testReplaceExpr() {
Workflow flow = mock(Workflow.class);
FunctionDefinition functionDefinition = new FunctionDefinition();
functionDefinition.setType(Type.EXPRESSION);
functionDefinition.setOperation(".pepe");
functionDefinition.setName("pepe");
Functions functions = new Functions(Collections.singletonList(functionDefinition));
when(flow.getFunctions()).thenReturn(functions);
assertEquals("\"fn:pepe\"", ExpressionHandlerUtils.replaceExpr(flow, "\"fn:pepe\""));
assertEquals(".pepe", ExpressionHandlerUtils.replaceExpr(flow, "fn:pepe"));
assertEquals(".pepe", ExpressionHandlerUtils.replaceExpr(flow, "${fn:pepe}"));
assertThrows(IllegalArgumentException.class, () -> ExpressionHandlerUtils.replaceExpr(flow, "${fn:NoPepe}"));
}
Aggregations