From b68fafe88b471b5077f095a4d46824b8aeb4de65 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Mon, 4 Mar 2024 17:31:06 +0100 Subject: [PATCH 1/5] [incubator-kie-kogito-runtimes#2608] Testing multiple DMNs, importing dmn --- .../src/main/resources/Imported_Model.dmn | 35 +++++ .../src/main/resources/Traffic Violation.dmn | 44 ++++--- .../src/main/resources/habitability.dmn | 124 ++++++++++++++++++ 3 files changed, 185 insertions(+), 18 deletions(-) create mode 100644 kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn create mode 100644 kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn new file mode 100644 index 0000000000..a4440e3b3d --- /dev/null +++ b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn @@ -0,0 +1,35 @@ + + + + + + + string + + + number + + + string + + + string + + + number + + + diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn index 109d4689e1..d31454f274 100644 --- a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn +++ b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn @@ -1,23 +1,31 @@ - - - string - - - number - - - string - - - string - - - number - - + + + + + + + + + + + + + + + + + + string @@ -126,7 +134,7 @@ - + Should the driver be suspended due to points on his license? diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn new file mode 100644 index 0000000000..5ba2839631 --- /dev/null +++ b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + oxygene + + + + + temperature + + + + + + + [10..100] + + + < 40 + + + "somehow doable" + + + + + + + + <10 + + + < 40 + + + "hardly doable" + + + + + + + + - + + + >= 40 + + + "too hot" + + + + + + + + + + + + + 50 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 8cba0fbbff2ff082633268fc0c035351e8ad47fd Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 5 Mar 2024 11:02:39 +0100 Subject: [PATCH 2/5] [incubator-kie-kogito-runtimes#2608] Restored dmn-quarkus-example. Created dmn-multiple-models-quarkus-example --- .../README.md | 130 +++ .../pom.xml | 118 +++ .../src/main/resources/Imported_Model.dmn | 0 .../src/main/resources/Traffic Violation.dmn | 238 ++++++ .../src/main/resources/application.properties | 22 + .../src/main/resources/habitability.dmn | 0 .../example/NativeTrafficViolationIT.java | 27 + .../quarkus/example/TrafficViolationTest.java | 52 ++ .../KogitoScenarioJunitActivatorTest.java | 29 + .../resources/TrafficViolationTest.scesim | 766 ++++++++++++++++++ .../src/test/resources/application.properties | 21 + .../src/main/resources/Traffic Violation.dmn | 42 +- kogito-quarkus-examples/pom.xml | 1 + 13 files changed, 1421 insertions(+), 25 deletions(-) create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/pom.xml rename kogito-quarkus-examples/{dmn-quarkus-example => dmn-multiple-models-quarkus-example}/src/main/resources/Imported_Model.dmn (100%) create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/application.properties rename kogito-quarkus-examples/{dmn-quarkus-example => dmn-multiple-models-quarkus-example}/src/main/resources/habitability.dmn (100%) create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeTrafficViolationIT.java create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/TrafficViolationTest.java create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/TrafficViolationTest.scesim create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/application.properties diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md new file mode 100644 index 0000000000..0266461258 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md @@ -0,0 +1,130 @@ +# DMN + Quarkus example + +## Description + +A simple DMN service to evaluate a traffic violation. + +Demonstrates DMN on Kogito capabilities, including REST interface code generation. + +## Installing and Running + +### Prerequisites + +You will need: + - Java 11+ installed + - Environment variable JAVA_HOME set accordingly + - Maven 3.8.6+ installed + +When using native image compilation, you will also need: + - [GraalVM 19.3.1](https://github.com/oracle/graal/releases/tag/vm-19.3.1) installed + - Environment variable GRAALVM_HOME set accordingly + - Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too. You also need 'native-image' installed in GraalVM (using 'gu install native-image'). Please refer to [GraalVM installation documentation](https://www.graalvm.org/docs/reference-manual/aot-compilation/#prerequisites) for more details. + +### Compile and Run in Local Dev Mode + +``` +mvn clean compile quarkus:dev +``` + +### Package and Run in JVM mode + +``` +mvn clean package +java -jar target/quarkus-app/quarkus-run.jar +``` + +or on Windows + +``` +mvn clean package +java -jar target\quarkus-app\quarkus-run.jar +``` + +### Package and Run using Local Native Image +Note that this requires GRAALVM_HOME to point to a valid GraalVM installation + +``` +mvn clean package -Pnative +``` + +To run the generated native executable, generated in `target/`, execute + +``` +./target/dmn-quarkus-example-runner +``` + +Note: This does not yet work on Windows, GraalVM and Quarkus should be rolling out support for Windows soon. + +## OpenAPI (Swagger) documentation +[Specification at swagger.io](https://swagger.io/docs/specification/about/) + +You can take a look at the [OpenAPI definition](http://localhost:8080/openapi?format=json) - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available [Swagger UI](https://editor.swagger.io). + +In addition, various clients to interact with this service can be easily generated using this OpenAPI definition. + +When running in either Quarkus Development or Native mode, we also leverage the [Quarkus OpenAPI extension](https://quarkus.io/guides/openapi-swaggerui#use-swagger-ui-for-development) that exposes [Swagger UI](http://localhost:8080/swagger-ui/) that you can use to look at available REST endpoints and send test requests. + +## Test DMN Model using Maven + +Validate the functionality of DMN models before deploying them into a production environment by defining test scenarios in Test Scenario Editor. + +To define test scenarios you need to create a .scesim file inside your project and link it to the DMN model you want to be tested. Run all Test Scenarios, executing: + +```sh +mvn clean test +``` +See results in surefire test report `target/surefire-reports` + +## Example Usage + +Once the service is up and running, you can use the following example to interact with the service. + +### POST /Traffic Violation + +Returns penalty information from the given inputs -- driver and violation: + +Given inputs: + +```json +{ + "Driver":{"Points":2}, + "Violation":{ + "Type":"speed", + "Actual Speed":120, + "Speed Limit":100 + } +} +``` + +Curl command (using the JSON object above): + +```sh +curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"Driver":{"Points":2},"Violation":{"Type":"speed","Actual Speed":120,"Speed Limit":100}}' http://localhost:8080/Traffic%20Violation +``` +or on Windows: + +```sh +curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"Driver\":{\"Points\":2},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":120,\"Speed Limit\":100}}" http://localhost:8080/Traffic%20Violation +``` + +As response, penalty information is returned. + +Example response: + +```json +{ + "Violation":{ + "Type":"speed", + "Speed Limit":100, + "Actual Speed":120 + }, + "Driver":{ + "Points":2 + }, + "Fine":{ + "Points":3, + "Amount":500 + }, + "Should the driver be suspended?":"No" +} +``` diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/pom.xml b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/pom.xml new file mode 100644 index 0000000000..b9df8cd83a --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/pom.xml @@ -0,0 +1,118 @@ + + + + 4.0.0 + + org.kie.kogito.examples + kogito-quarkus-examples + 999-SNAPSHOT + + dmn-multiple-models-quarkus-example + Kogito Example :: DMN :: Multiple Models + + 3.2.10.Final + quarkus-bom + io.quarkus + 3.2.10.Final + org.kie.kogito + kogito-bom + 999-SNAPSHOT + 999-SNAPSHOT + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + ${kogito.bom.group-id} + ${kogito.bom.artifact-id} + ${kogito.bom.version} + pom + import + + + + + + org.drools + drools-quarkus-decisions + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + org.kie.kogito + kogito-scenario-simulation + test + + + io.quarkus + quarkus-smallrye-health + + + + ${project.artifactId} + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + + diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Imported_Model.dmn similarity index 100% rename from kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Imported_Model.dmn rename to kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Imported_Model.dmn diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn new file mode 100644 index 0000000000..d31454f274 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + string + + + date + + + string + + "speed", "parking", "driving under the influence" + + + + number + + + number + + + + + number + + + number + + + + + + + + + + + + + + Violation.Type + + + + + Violation.Actual Speed - Violation.Speed Limit + + + + + + + "speed" + + + [10..30) + + + 500 + + + 3 + + + + + "speed" + + + >= 30 + + + 1000 + + + 7 + + + + + "parking" + + + - + + + 100 + + + 1 + + + + + "driving under the influence" + + + - + + + 1000 + + + 5 + + + + + + + + + Should the driver be suspended due to points on his license? + "Yes", "No" + + + + + + + + + + + + Driver.Points + Fine.Points + + + + + if Total Points >= 20 then "Yes" else "No" + + + + + + + + + + 50.0 + 254.0 + 329.0 + 119.0 + 100.0 + 186.0 + + + 50.0 + 100.0 + 398.0 + + + 398.0 + + + 398.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/application.properties b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/application.properties new file mode 100644 index 0000000000..727b6c82f1 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/application.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +# + +# Packaging + +quarkus.swagger-ui.always-include=true diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/habitability.dmn similarity index 100% rename from kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/habitability.dmn rename to kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/habitability.dmn diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeTrafficViolationIT.java b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeTrafficViolationIT.java new file mode 100644 index 0000000000..b43c7dca80 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeTrafficViolationIT.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package org.kie.kogito.dmn.quarkus.example; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class NativeTrafficViolationIT extends TrafficViolationTest { + + // Execute the same tests but in native mode. +} \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/TrafficViolationTest.java b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/TrafficViolationTest.java new file mode 100644 index 0000000000..3c42782c77 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/TrafficViolationTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package org.kie.kogito.dmn.quarkus.example; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +@QuarkusTest +public class TrafficViolationTest { + + @Test + public void testEvaluateTrafficViolation() { + given() + .body("{\n" + + " \"Driver\": {\n" + + " \"Points\": 2\n" + + " },\n" + + " \"Violation\": {\n" + + " \"Type\": \"speed\",\n" + + " \"Actual Speed\": 120,\n" + + " \"Speed Limit\": 100\n" + + " }\n" + + "}") + .contentType(ContentType.JSON) + .when() + .post("/Traffic Violation") + .then() + .statusCode(200) + .body("'Should the driver be suspended?'", is("No")); + } +} diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java new file mode 100644 index 0000000000..4b19a12015 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/testscenario/KogitoScenarioJunitActivatorTest.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package testscenario; + +/** + * KogitoJunitActivator is a custom JUnit runner that enables the execution of Test Scenario files (*.scesim). + * This activator class, when executed, will load all scesim files available in the project and run them. + * Each row of the scenario will generate a test JUnit result. + */ +@org.junit.runner.RunWith(org.kogito.scenariosimulation.runner.KogitoJunitActivator.class) +public class KogitoScenarioJunitActivatorTest { + +} \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/TrafficViolationTest.scesim b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/TrafficViolationTest.scesim new file mode 100644 index 0000000000..ff5d6a2b3e --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/TrafficViolationTest.scesim @@ -0,0 +1,766 @@ + + + + + + + + + Index + OTHER + + + # + java.lang.Integer + + java.lang.Integer + # + 70 + NOT_EXPRESSION + + + + + Description + OTHER + + + Scenario description + java.lang.String + + java.lang.String + Scenario description + 300 + NOT_EXPRESSION + + + + + Driver + + + Points + + + + 1|5 + GIVEN + + + Driver + Driver + + number + Driver + Points + + 114 + NOT_EXPRESSION + + + + + Violation + + + Type + + + + 1|8 + GIVEN + + + Violation + Violation + + Type + Violation + Type + + 114 + NOT_EXPRESSION + + + + + Violation + + + Speed Limit + + + + 1|9 + GIVEN + + + Violation + Violation + + number + Violation + Speed Limit + + 114 + NOT_EXPRESSION + + + + + Violation + + + Actual Speed + + + + 1|10 + GIVEN + + + Violation + Violation + + number + Violation + Actual Speed + + 114 + NOT_EXPRESSION + + + + + Fine + + + Amount + + + + 1|11 + EXPECT + + + Fine + Fine + + number + Fine + Amount + + 114 + NOT_EXPRESSION + + + + + Fine + + + Points + + + + 1|12 + EXPECT + + + Fine + Fine + + number + Fine + Points + + 114 + NOT_EXPRESSION + + + + + Should the driver be suspended? + + + + 1|13 + EXPECT + + + Should the driver be suspended? + Should the driver be suspended? + + string + Should the driver be suspended? + value + + 114 + NOT_EXPRESSION + + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Above speed limit: 10km/h and 30 km/h + + + + Driver + Driver + + + 1|5 + GIVEN + + 10 + + + + Violation + Violation + + + 1|8 + GIVEN + + "speed" + + + + Violation + Violation + + + 1|9 + GIVEN + + 100 + + + + Violation + Violation + + + 1|10 + GIVEN + + 120 + + + + Fine + Fine + + + 1|11 + EXPECT + + 500 + + + + Fine + Fine + + + 1|12 + EXPECT + + 3 + + + + Should the driver be suspended? + Should the driver be suspended? + + + 1|13 + EXPECT + + "No" + + + + # + java.lang.Integer + + + Index + OTHER + + 1 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Above speed limit: more than 30 km/h + + + + Driver + Driver + + + 1|5 + GIVEN + + 10 + + + + Violation + Violation + + + 1|8 + GIVEN + + "speed" + + + + Violation + Violation + + + 1|9 + GIVEN + + 100 + + + + Violation + Violation + + + 1|10 + GIVEN + + 150 + + + + Fine + Fine + + + 1|11 + EXPECT + + 1000 + + + + Fine + Fine + + + 1|12 + EXPECT + + 7 + + + + Should the driver be suspended? + Should the driver be suspended? + + + 1|13 + EXPECT + + "No" + + + + # + java.lang.Integer + + + Index + OTHER + + 2 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Parking violation + + + + Driver + Driver + + + 1|5 + GIVEN + + 10 + + + + Violation + Violation + + + 1|8 + GIVEN + + "parking" + + + + Violation + Violation + + + 1|9 + GIVEN + + + + + Violation + Violation + + + 1|10 + GIVEN + + + + + Fine + Fine + + + 1|11 + EXPECT + + 100 + + + + Fine + Fine + + + 1|12 + EXPECT + + 1 + + + + Should the driver be suspended? + Should the driver be suspended? + + + 1|13 + EXPECT + + "No" + + + + # + java.lang.Integer + + + Index + OTHER + + 3 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + DUI violation + + + + Driver + Driver + + + 1|5 + GIVEN + + 10 + + + + Violation + Violation + + + 1|8 + GIVEN + + "driving under the influence" + + + + Violation + Violation + + + 1|9 + GIVEN + + + + + Violation + Violation + + + 1|10 + GIVEN + + + + + Fine + Fine + + + 1|11 + EXPECT + + 1000 + + + + Fine + Fine + + + 1|12 + EXPECT + + 5 + + + + Should the driver be suspended? + Should the driver be suspended? + + + 1|13 + EXPECT + + "No" + + + + # + java.lang.Integer + + + Index + OTHER + + 4 + + + + + + + + Scenario description + java.lang.String + + + Description + OTHER + + Driver suspended + + + + Driver + Driver + + + 1|5 + GIVEN + + 15 + + + + Violation + Violation + + + 1|8 + GIVEN + + "speed" + + + + Violation + Violation + + + 1|9 + GIVEN + + 100 + + + + Violation + Violation + + + 1|10 + GIVEN + + 140 + + + + Fine + Fine + + + 1|11 + EXPECT + + 1000 + + + + Fine + Fine + + + 1|12 + EXPECT + + 7 + + + + Should the driver be suspended? + Should the driver be suspended? + + + 1|13 + EXPECT + + "Yes" + + + + # + java.lang.Integer + + + Index + OTHER + + 5 + + + + + + + + + + + + 1|1 + GIVEN + + + Empty + java.lang.Void + + java.lang.Void + INSTANCE 1 + PROPERTY 1 + 114 + NOT_EXPRESSION + + + + + + + + + Empty + java.lang.Void + + + 1|1 + GIVEN + + + + + + + + src/main/resources/Traffic Violation.dmn + DMN + https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF + Traffic Violation + false + false + + + + + \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/application.properties b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/application.properties new file mode 100644 index 0000000000..a047ea13ba --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/resources/application.properties @@ -0,0 +1,21 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. +# + +# Quarkus +quarkus.http.test-port=0 \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn index d31454f274..66e9d0ada4 100644 --- a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn +++ b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn @@ -1,31 +1,23 @@ - - - - - - - - - - - - - - - - - - + + + string + + + number + + + string + + + string + + + number + + string diff --git a/kogito-quarkus-examples/pom.xml b/kogito-quarkus-examples/pom.xml index 67e4b8a8dc..6e68947c48 100644 --- a/kogito-quarkus-examples/pom.xml +++ b/kogito-quarkus-examples/pom.xml @@ -58,6 +58,7 @@ dmn-listener-dtable dmn-pmml-quarkus-example dmn-quarkus-example + dmn-multiple-models-quarkus-example dmn-tracing-quarkus flexible-process-quarkus kogito-travel-agency From ca9336099f660eaed466958a1ea27c1a3eb727d9 Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 5 Mar 2024 11:30:20 +0100 Subject: [PATCH 3/5] [incubator-kie-kogito-runtimes#2608] Restored dmn-quarkus-example. Created dmn-multiple-models-quarkus-example --- .../README.md | 47 +++++++++++++++++-- .../dmn/quarkus/example/HabitabilityTest.java | 46 ++++++++++++++++++ .../quarkus/example/NativeHabitabilityIT.java | 27 +++++++++++ .../src/main/resources/Traffic Violation.dmn | 2 +- 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/HabitabilityTest.java create mode 100644 kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeHabitabilityIT.java diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md index 0266461258..ddafc05173 100644 --- a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md @@ -1,8 +1,8 @@ -# DMN + Quarkus example +# DMN + Quarkus example with multiple models ## Description -A simple DMN service to evaluate a traffic violation. +A simple DMN service to evaluate different models (traffic violation, habitability) with also importing feature (traffic violation). Demonstrates DMN on Kogito capabilities, including REST interface code generation. @@ -50,7 +50,7 @@ mvn clean package -Pnative To run the generated native executable, generated in `target/`, execute ``` -./target/dmn-quarkus-example-runner +./target/dmn-multiple-models-quarkus-example-runner ``` Note: This does not yet work on Windows, GraalVM and Quarkus should be rolling out support for Windows soon. @@ -128,3 +128,44 @@ Example response: "Should the driver be suspended?":"No" } ``` + +The difference from the [dmn-quarkus-example](../dmn-quarkus-example) is that, in the current one, the `Traffic Model` features the import declaration, with definitions coming from the ` Imported Model`. + +### POST /habitability + +Returns habitability information from the given inputs -- oxygen and temperature: + +Given inputs: + +```json +{ + "oxygene": 70, + "temperature": 30 +} +``` + +Curl command (using the JSON object above): + +```sh +curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"oxygene": 70, "temperature": 30}' http://localhost:8080/habitability +``` +or on Windows: + +```sh +curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"oxygene\": 70, \"temperature\": 30}" http://localhost:8080/habitability +``` + +As response, habitability information is returned. + +Example response: + +```json +{ + "oxygene": 70, + "temperature": 30, + "habitability": "somehow doable" +} +``` + + + diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/HabitabilityTest.java b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/HabitabilityTest.java new file mode 100644 index 0000000000..17e2714dc3 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/HabitabilityTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package org.kie.kogito.dmn.quarkus.example; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +@QuarkusTest +public class HabitabilityTest { + + @Test + public void testEvaluateHabitability() { + given() + .body("{\n" + + " \"oxygene\": 70,\n" + + " \"temperature\": 30\n" + + "}") + .contentType(ContentType.JSON) + .when() + .post("/habitability") + .then() + .statusCode(200) + .body("'habitability'", is("somehow doable")); + } +} diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeHabitabilityIT.java b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeHabitabilityIT.java new file mode 100644 index 0000000000..6bc4f990d8 --- /dev/null +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/NativeHabitabilityIT.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package org.kie.kogito.dmn.quarkus.example; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class NativeHabitabilityIT extends HabitabilityTest { + + // Execute the same tests but in native mode. +} \ No newline at end of file diff --git a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn index 66e9d0ada4..109d4689e1 100644 --- a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn +++ b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/Traffic Violation.dmn @@ -126,7 +126,7 @@ - + Should the driver be suspended due to points on his license? From 16b67dc506d659eb8fcca3b852d3bb843295a4ce Mon Sep 17 00:00:00 2001 From: Gabriele-Cardosi Date: Tue, 5 Mar 2024 11:32:40 +0100 Subject: [PATCH 4/5] [incubator-kie-kogito-runtimes#2608] Removed commented block --- .../src/main/resources/Traffic Violation.dmn | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn index d31454f274..aa798507d8 100644 --- a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/src/main/resources/Traffic Violation.dmn @@ -1,23 +1,6 @@ - - - - - - - - - - - - - - - - - Date: Thu, 7 Mar 2024 08:54:24 +0100 Subject: [PATCH 5/5] [incubator-kie-kogito-runtimes#2608] Fixed as per PR suggestion --- .../dmn-multiple-models-quarkus-example/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md index ddafc05173..1e861d88ce 100644 --- a/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md +++ b/kogito-quarkus-examples/dmn-multiple-models-quarkus-example/README.md @@ -11,9 +11,9 @@ Demonstrates DMN on Kogito capabilities, including REST interface code generatio ### Prerequisites You will need: - - Java 11+ installed + - Java 17+ installed - Environment variable JAVA_HOME set accordingly - - Maven 3.8.6+ installed + - Maven 3.9.6+ installed When using native image compilation, you will also need: - [GraalVM 19.3.1](https://github.com/oracle/graal/releases/tag/vm-19.3.1) installed