From 91497cce2b7b79ee1c0a4fbcd6bf38bc22a0a280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pere=20Fern=C3=A1ndez?= Date: Thu, 14 Sep 2023 14:58:49 +0200 Subject: [PATCH] kie-issues#532: create REST endpoint to start process instances using signals (#3221) * kie-issues#532: create REST endpoint to start process instances using signals * review comments * review comments#2 --- .../codegen/process/ProcessCodegen.java | 2 +- .../process/ProcessResourceGenerator.java | 122 +++++++++++++--- .../RestResourceSignalQuarkusTemplate.java | 24 +++- .../RestResourceSignalSpringTemplate.java | 22 ++- .../process/ProcessResourceGeneratorTest.java | 75 +++++++++- .../StartSignalEventNoPayload.bpmn2 | 113 +++++++++++++++ .../StartSignalEventStringPayload.bpmn2 | 131 ++++++++++++++++++ .../StartSignalEventStringPayload.bpmn2 | 131 ++++++++++++++++++ .../quarkus/SignalProcessIT.java | 21 +++ .../StartSignalEventStringPayload.bpmn2 | 131 ++++++++++++++++++ .../springboot/SignalProcessTest.java | 20 +++ .../integrationtests/springboot/TaskTest.java | 2 +- 12 files changed, 770 insertions(+), 24 deletions(-) create mode 100644 kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2 create mode 100644 kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventStringPayload.bpmn2 create mode 100644 quarkus/integration-tests/integration-tests-quarkus-processes/src/main/resources/StartSignalEventStringPayload.bpmn2 create mode 100644 springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/main/resources/StartSignalEventStringPayload.bpmn2 diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java index dad3e0537c7..faf545ed022 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java @@ -362,7 +362,7 @@ protected Collection internalGenerate() { processResourceGenerator .withUserTasks(processIdToUserTaskModel.get(workFlowProcess.getId())) .withSignals(metaData.getSignals()) - .withTriggers(metaData.isStartable(), metaData.isDynamic()); + .withTriggers(metaData.isStartable(), metaData.isDynamic(), metaData.getTriggers()); rgs.add(processResourceGenerator); diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java index 5fbe8553bf4..eece2d904ad 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessResourceGenerator.java @@ -18,6 +18,8 @@ */ package org.kie.kogito.codegen.process; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,8 +29,13 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import org.drools.util.StringUtils; import org.jbpm.compiler.canonical.ProcessToExecModelGenerator; +import org.jbpm.compiler.canonical.TriggerMetaData; import org.jbpm.compiler.canonical.UserTaskModelMetaData; +import org.jbpm.ruleflow.core.Metadata; +import org.jbpm.ruleflow.core.RuleFlowProcess; +import org.jbpm.workflow.core.node.StartNode; import org.kie.kogito.codegen.api.context.KogitoBuildContext; import org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext; import org.kie.kogito.codegen.api.template.TemplatedGenerator; @@ -44,6 +51,7 @@ import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; +import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.NullLiteralExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; @@ -69,6 +77,8 @@ public class ProcessResourceGenerator { private static final String REST_USER_TASK_TEMPLATE_NAME = "RestResourceUserTask"; private static final String REST_SIGNAL_TEMPLATE_NAME = "RestResourceSignal"; + private static final String SIGNAL_METHOD_PREFFIX = "signal_"; + private final String relativePath; private final KogitoBuildContext context; @@ -82,6 +92,8 @@ public class ProcessResourceGenerator { private boolean startable; private boolean dynamic; + private List triggers; + private List userTasks; private Map signals; private CompilationUnit taskModelFactoryUnit; @@ -114,9 +126,10 @@ public ProcessResourceGenerator withSignals(Map signals) { return this; } - public ProcessResourceGenerator withTriggers(boolean startable, boolean dynamic) { + public ProcessResourceGenerator withTriggers(boolean startable, boolean dynamic, List triggers) { this.startable = startable; this.dynamic = dynamic; + this.triggers = triggers; return this; } @@ -166,28 +179,75 @@ public String generate() { .findFirst(ClassOrInterfaceDeclaration.class) .orElseThrow(() -> new NoSuchElementException("SignalResourceTemplate class not found!")); + MethodDeclaration signalProcessDeclaration = signalTemplate + .findFirst(MethodDeclaration.class, md -> md.getNameAsString().equals("signalProcess")) + .orElseThrow(() -> new NoSuchElementException("signalProcess method not found in SignalResourceTemplate")); + + MethodDeclaration signalInstanceDeclaration = signalTemplate + .findFirst(MethodDeclaration.class, md -> md.getNameAsString().equals("signalInstance")) + .orElseThrow(() -> new NoSuchElementException("signalInstance method not found in SignalResourceTemplate")); + + Collection startSignalTriggers = getStartSignalTriggers(); + signalsMap.entrySet() .stream() .filter(e -> Objects.nonNull(e.getKey())) .forEach(entry -> { - String methodName = "signal_" + index.getAndIncrement(); String signalName = entry.getKey(); String signalType = entry.getValue(); - signalTemplate.findAll(MethodDeclaration.class) - .forEach(md -> { - MethodDeclaration cloned = md.clone(); - BlockStmt body = cloned.getBody().get(); - if (signalType == null) { - body.findAll(NameExpr.class, nameExpr -> "data".equals(nameExpr.getNameAsString())).forEach(name -> name.replace(new NullLiteralExpr())); - } - template.addMethod(methodName, Keyword.PUBLIC) - .setType(cloned.getType()) - // Remove data parameter ( payload ) if signalType is null - .setParameters(signalType == null ? NodeList.nodeList(cloned.getParameter(0)) : cloned.getParameters()) - .setBody(body) - .setAnnotations(cloned.getAnnotations()); - }); + // Looking if the Process starts with the current signal + Optional startTrigger = startSignalTriggers.stream() + .filter(trigger -> trigger.getName().equals(signalName)) + .findAny(); + + startTrigger.ifPresent(trigger -> { + // Create endpoint to signal the process container to start new instances + MethodDeclaration signalProcessDeclarationClone = signalProcessDeclaration.clone(); + + BlockStmt signalProcessBody = signalProcessDeclarationClone.getBody() + .orElseThrow(() -> new RuntimeException("signalProcessDeclaration doesn't have body")); + + MethodCallExpr setterMethod = signalProcessBody.findAll(MethodCallExpr.class, m -> m.getName().getIdentifier().contains("$SetModelMethodName$")) + .stream() + .findFirst() + .orElseThrow(() -> new RuntimeException("signalProcessDeclaration doesn't have model setter")); + + if (signalType == null) { + // if there's no type we should remove the payload references form the method declaration and body + signalProcessDeclarationClone.getParameters() + .stream() + .filter(parameter -> parameter.getNameAsString().equals("data")) + .findFirst() + .ifPresent(Parameter::removeForced); + setterMethod.removeForced(); + } else { + String name = Optional.ofNullable((String) trigger.getNode().getMetaData().get(Metadata.MAPPING_VARIABLE)).orElseGet(trigger::getModelRef); + setterMethod.setName(setterMethod.getNameAsString().replace("$SetModelMethodName$", StringUtils.ucFirst(name))); + } + + template.addMethod(SIGNAL_METHOD_PREFFIX + signalName, Keyword.PUBLIC) + .setType(signalProcessDeclarationClone.getType()) + .setParameters(signalProcessDeclarationClone.getParameters()) + .setBody(signalProcessBody) + .setAnnotations(signalProcessDeclarationClone.getAnnotations()); + }); + + // Create endpoint to signal process instances + MethodDeclaration signalInstanceDeclarationClone = signalInstanceDeclaration.clone(); + BlockStmt signalInstanceBody = signalInstanceDeclarationClone.getBody() + .orElseThrow(() -> new RuntimeException("signalInstanceDeclaration doesn't have body")); + + if (signalType == null) { + signalInstanceBody.findAll(NameExpr.class, nameExpr -> "data".equals(nameExpr.getNameAsString())).forEach(name -> name.replace(new NullLiteralExpr())); + } + + template.addMethod(SIGNAL_METHOD_PREFFIX + index.getAndIncrement(), Keyword.PUBLIC) + .setType(signalInstanceDeclarationClone.getType()) + // Remove data parameter ( payload ) if signalType is null + .setParameters(signalType == null ? NodeList.nodeList(signalInstanceDeclarationClone.getParameter(0)) : signalInstanceDeclaration.getParameters()) + .setBody(signalInstanceBody) + .setAnnotations(signalInstanceDeclarationClone.getAnnotations()); if (signalType != null) { template.findAll(ClassOrInterfaceType.class).forEach(name -> { @@ -248,7 +308,7 @@ public String generate() { if (!userTask.isAdHoc()) { template.findAll(MethodDeclaration.class) .stream() - .filter(md -> md.getNameAsString().equals("signal_" + methodSuffix)) + .filter(md -> md.getNameAsString().equals(SIGNAL_METHOD_PREFFIX + methodSuffix)) .collect(Collectors.toList()).forEach(template::remove); } switchExpr.getEntries().add(0, userTask.getModelSwitchEntry()); @@ -372,6 +432,34 @@ private String sanitizeName(String name) { return name.replaceAll("\\s", "_"); } + private Collection getStartSignalTriggers() { + return Optional.ofNullable(this.triggers).orElse(Collections.emptyList()) + .stream() + .filter(this::isStartSignalTriggerFilter) + .collect(Collectors.toList()); + } + + private boolean isStartSignalTriggerFilter(TriggerMetaData trigger) { + + // Checking trigger type is Signal + if (!trigger.getType().equals(TriggerMetaData.TriggerType.Signal)) { + return false; + } + + // Checking if the trigger belongs to a StartNode + if (!(trigger.getNode() instanceof StartNode)) { + return false; + } + + // Checking if the StartNode belongs to the parent process (not in a subprocess) + if (!(((StartNode) trigger.getNode()).getParentContainer() instanceof RuleFlowProcess)) { + return false; + } + + // Checking if the node is a "Start Error" node. + return !trigger.getNode().getMetaData().containsKey("FaultCode"); + } + public String generatedFilePath() { return relativePath; } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalQuarkusTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalQuarkusTemplate.java index 997cc6a796d..3591e013d78 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalQuarkusTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalQuarkusTemplate.java @@ -19,16 +19,38 @@ package com.myspace.demo; import org.kie.kogito.process.Process; +import org.kie.kogito.process.ProcessInstance; public class $Type$Resource { Process<$Type$> process; + @POST + @Path("/$signalPath$") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response signalProcess(@Context HttpHeaders httpHeaders, + @Context UriInfo uriInfo, + @QueryParam("businessKey") @DefaultValue("") String businessKey, + $signalType$ data) { + $Type$ model = new $Type$(); + model.set$SetModelMethodName$(data); + this.processService.createProcessInstance(process, + businessKey, + model, + httpHeaders.getRequestHeaders(), + httpHeaders.getHeaderString("X-KOGITO-StartFromNode"), + "$signalName$", + httpHeaders.getHeaderString("X-KOGITO-ReferenceId"), + null); + return Response.accepted().build(); + } + @POST @Path("/{id}/$signalPath$") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public $Type$Output signal(@PathParam("id") final String id, final $signalType$ data) { + public $Type$Output signalInstance(@PathParam("id") final String id, final $signalType$ data) { return processService.signalProcessInstance(process, id, data, "$signalName$") .orElseThrow(() -> new NotFoundException()); } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalSpringTemplate.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalSpringTemplate.java index d8f70f61d81..3b99f1bcaf1 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalSpringTemplate.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/resources/class-templates/RestResourceSignalSpringTemplate.java @@ -31,9 +31,29 @@ public class $Type$Resource { Process<$Type$> process; + @PostMapping(value = "/$signalName$", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<$Type$Output> signalProcess(@RequestHeader HttpHeaders httpHeaders, + @RequestParam(value = "businessKey", required = false) String businessKey, + @RequestBody(required = false) $signalType$ data, + UriComponentsBuilder uriComponentsBuilder) { + + $Type$ model = new $Type$(); + model.set$SetModelMethodName$(data); + + this.processService.createProcessInstance(process, + businessKey, + model, + httpHeaders, + httpHeaders.getOrEmpty("X-KOGITO-StartFromNode").stream().findFirst().orElse(null), + "$signalName$", + httpHeaders.getOrEmpty("X-KOGITO-ReferenceId").stream().findFirst().orElse(null), + null); + + return ResponseEntity.accepted().build(); + } @PostMapping(value = "/{id}/$signalPath$", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public $Type$Output signal(@PathVariable("id") final String id, final @RequestBody(required = false) $signalType$ data) { + public $Type$Output signalInstance(@PathVariable("id") final String id, final @RequestBody(required = false) $signalType$ data) { return processService.signalProcessInstance(process, id, data, "$signalName$") .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessResourceGeneratorTest.java b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessResourceGeneratorTest.java index 2cc02b4d662..57b4fa9a49a 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessResourceGeneratorTest.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/process/ProcessResourceGeneratorTest.java @@ -25,6 +25,7 @@ import java.util.function.Predicate; import org.drools.io.FileSystemResource; +import org.jbpm.compiler.canonical.ProcessMetaData; import org.jbpm.compiler.canonical.ProcessToExecModelGenerator; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -46,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; class ProcessResourceGeneratorTest { - + private static final String SIGNAL_METHOD = "signal_"; private static final List JAVA_AND_QUARKUS_REST_ANNOTATIONS = List.of("DELETE", "GET", "POST"); private static final List SPRING_BOOT_REST_ANNOTATIONS = List.of("DeleteMapping", "GetMapping", "PostMapping"); @@ -82,7 +83,72 @@ void testGenerateBoundarySignalEventOnTask(KogitoBuildContext.Builder contextBui String outputType = new ModelClassGenerator(contextBuilder.build(), process).simpleName() + "Output"; classDeclaration.getMethods().stream() - .filter(method -> isRestMethod(method) && method.getNameAsString().startsWith("signal_")) + .filter(method -> isRestMethod(method) && method.getNameAsString().startsWith(SIGNAL_METHOD)) + .forEach(method -> assertMethodOutputModelType(method, outputType)); + } + + @ParameterizedTest + @MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders") + void testGenerateStartSignalEventStringPayload(KogitoBuildContext.Builder contextBuilder) { + String fileName = "src/test/resources/startsignal/StartSignalEventStringPayload.bpmn2"; + String signalName = "start"; + + ClassOrInterfaceDeclaration classDeclaration = getResourceClassDeclaration(contextBuilder, fileName); + + KogitoWorkflowProcess process = parseProcess(fileName); + + MethodDeclaration startSignalMethod = classDeclaration.getMethods().stream() + .filter(method -> isRestMethod(method) && method.getNameAsString().equals(SIGNAL_METHOD + signalName)) + .findFirst() + .orElseThrow(); + + assertThat(startSignalMethod.isPublic()).isTrue(); + assertThat(startSignalMethod.getParameters()).hasSize(4); + assertThat(startSignalMethod.getParameters().stream() + .filter(parameter -> parameter.getNameAsString().equals("data")) + .findFirst() + .get()).matches(parameter -> parameter.getTypeAsString().equals("java.lang.String")); + + assertThat(startSignalMethod.getBody().get().getChildNodes() + .stream() + .anyMatch(child -> child.toString().equals("model.setMessage(data);"))).isTrue(); + + String outputType = new ModelClassGenerator(contextBuilder.build(), process).simpleName() + "Output"; + + classDeclaration.getMethods().stream() + .filter(method -> isRestMethod(method) && method.getNameAsString().startsWith(SIGNAL_METHOD + "0")) + .forEach(method -> assertMethodOutputModelType(method, outputType)); + } + + @ParameterizedTest + @MethodSource("org.kie.kogito.codegen.api.utils.KogitoContextTestUtils#contextBuilders") + void testGenerateStartSignalEventNoPayload(KogitoBuildContext.Builder contextBuilder) { + String fileName = "src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2"; + String signalName = "start"; + + ClassOrInterfaceDeclaration classDeclaration = getResourceClassDeclaration(contextBuilder, fileName); + + KogitoWorkflowProcess process = parseProcess(fileName); + + MethodDeclaration startSignalMethod = classDeclaration.getMethods().stream() + .filter(method -> isRestMethod(method) && method.getNameAsString().equals(SIGNAL_METHOD + signalName)) + .findFirst() + .orElseThrow(); + + assertThat(startSignalMethod.isPublic()).isTrue(); + assertThat(startSignalMethod.getParameters()).hasSize(3); + assertThat(startSignalMethod.getParameters() + .stream() + .anyMatch(parameter -> parameter.getNameAsString().equals("data"))).isFalse(); + + assertThat(startSignalMethod.getBody().get().getChildNodes() + .stream() + .anyMatch(child -> child.toString().equals("model.setMessage(data);"))).isFalse(); + + String outputType = new ModelClassGenerator(contextBuilder.build(), process).simpleName() + "Output"; + + classDeclaration.getMethods().stream() + .filter(method -> isRestMethod(method) && method.getNameAsString().startsWith(SIGNAL_METHOD + "0")) .forEach(method -> assertMethodOutputModelType(method, outputType)); } @@ -117,8 +183,11 @@ private CompilationUnit getCompilationUnit(KogitoBuildContext.Builder contextBui execModelGen.className(), context.getPackageName() + ".Application"); + ProcessMetaData metaData = execModelGen.generate(); + processResourceGenerator - .withSignals(execModelGen.generate().getSignals()); + .withSignals(metaData.getSignals()) + .withTriggers(metaData.isStartable(), metaData.isDynamic(), metaData.getTriggers()); return StaticJavaParser.parse(processResourceGenerator.generate()); } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2 new file mode 100644 index 00000000000..1176e5b1fa0 --- /dev/null +++ b/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventNoPayload.bpmn2 @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + _228419DF-A546-48C7-985C-D9AE03D2B600 + + + + + + + + _875A5DBC-FE41-4BA9-AC57-DBCFA2B58784 + _228419DF-A546-48C7-985C-D9AE03D2B600 + + + + + _8CB19847-F5C6-4F3D-9062-0017DC9E64B5_TaskNameInputX + _8CB19847-F5C6-4F3D-9062-0017DC9E64B5_SkippableInputX + + + + _8CB19847-F5C6-4F3D-9062-0017DC9E64B5_TaskNameInputX + + + + + + + _8CB19847-F5C6-4F3D-9062-0017DC9E64B5_SkippableInputX + + + + + + + + _875A5DBC-FE41-4BA9-AC57-DBCFA2B58784 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _OH154C-2EDyJc62fsA_78w + _OH154C-2EDyJc62fsA_78w + + \ No newline at end of file diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventStringPayload.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventStringPayload.bpmn2 new file mode 100644 index 00000000000..87f37a88fbe --- /dev/null +++ b/kogito-codegen-modules/kogito-codegen-processes/src/test/resources/startsignal/StartSignalEventStringPayload.bpmn2 @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + + + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + + + + + john + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + message + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _MQCqwC-2EDygKtrlCr7CNQ + _MQCqwC-2EDygKtrlCr7CNQ + + \ No newline at end of file diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes/src/main/resources/StartSignalEventStringPayload.bpmn2 b/quarkus/integration-tests/integration-tests-quarkus-processes/src/main/resources/StartSignalEventStringPayload.bpmn2 new file mode 100644 index 00000000000..ac88171edc2 --- /dev/null +++ b/quarkus/integration-tests/integration-tests-quarkus-processes/src/main/resources/StartSignalEventStringPayload.bpmn2 @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + + + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + + + + + john + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + message + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _MQCqwC-2EDygKtrlCr7CNQ + _MQCqwC-2EDygKtrlCr7CNQ + + \ No newline at end of file diff --git a/quarkus/integration-tests/integration-tests-quarkus-processes/src/test/java/org/kie/kogito/integrationtests/quarkus/SignalProcessIT.java b/quarkus/integration-tests/integration-tests-quarkus-processes/src/test/java/org/kie/kogito/integrationtests/quarkus/SignalProcessIT.java index d1701adde3f..fc7991792af 100644 --- a/quarkus/integration-tests/integration-tests-quarkus-processes/src/test/java/org/kie/kogito/integrationtests/quarkus/SignalProcessIT.java +++ b/quarkus/integration-tests/integration-tests-quarkus-processes/src/test/java/org/kie/kogito/integrationtests/quarkus/SignalProcessIT.java @@ -25,6 +25,7 @@ import io.restassured.http.ContentType; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.emptyOrNullString; @@ -37,6 +38,26 @@ class SignalProcessIT { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } + @Test + void testSignalStartProcess() { + given() + .contentType(ContentType.JSON) + .when() + .body("hello world") + .post("/signalStart/start") + .then() + .statusCode(202); + + given() + .contentType(ContentType.JSON) + .when() + .get("/signalStart/") + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].message", equalTo("hello world")); + } + @Test void testProcessSignals() { String pid = given() diff --git a/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/main/resources/StartSignalEventStringPayload.bpmn2 b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/main/resources/StartSignalEventStringPayload.bpmn2 new file mode 100644 index 00000000000..ac88171edc2 --- /dev/null +++ b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/main/resources/StartSignalEventStringPayload.bpmn2 @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + _9E11326E-ADD1-4BF1-9135-E1E2EC2A2A94 + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_TaskNameInputX + + + + + + + _E7AA60DD-0A4B-4FEA-AD51-8A79E25F39C3_SkippableInputX + + + + + + + + john + + + + + _6D07FE5C-B505-45E7-BFAC-C9248377F7A6 + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + message + + + _DD58CEF9-616B-4526-831E-B86EF556E59A_messageOutputX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _MQCqwC-2EDygKtrlCr7CNQ + _MQCqwC-2EDygKtrlCr7CNQ + + \ No newline at end of file diff --git a/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/SignalProcessTest.java b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/SignalProcessTest.java index 3e248c62120..8cdb8bb6cb5 100644 --- a/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/SignalProcessTest.java +++ b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/SignalProcessTest.java @@ -25,6 +25,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.emptyOrNullString; @@ -34,6 +35,25 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = KogitoSpringbootApplication.class) class SignalProcessTest extends BaseRestTest { + @Test + void testSignalStartProcess() { + given() + .contentType(ContentType.JSON) + .when() + .body("hello world") + .post("/signalStart/start") + .then() + .statusCode(202); + + given() + .contentType(ContentType.JSON) + .when() + .get("/signalStart/") + .then() + .statusCode(200) + .body("$.size()", is(1)) + .body("[0].message", equalTo("hello world")); + } @Test void testProcessSignals() { String pid = given() diff --git a/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/TaskTest.java b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/TaskTest.java index 439de8d94c9..174bc82f719 100644 --- a/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/TaskTest.java +++ b/springboot/integration-tests/src/it/integration-tests-springboot-processes-it/src/test/java/org/kie/kogito/integrationtests/springboot/TaskTest.java @@ -101,7 +101,7 @@ void testJsonSchema() { @Test void testJsonSchemaFiles() { - long expectedJsonSchemas = 21; + long expectedJsonSchemas = 23; Path jsonDir = Paths.get("target", "classes").resolve(JsonSchemaUtil.getJsonDir()); try (Stream paths = Files.walk(jsonDir)) { long generatedJsonSchemas = paths