This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 04aaacf39 [incubator-kie-issues#1825] Implement
AllowedValuesChecksInsideCollection model usage inside dmn examples. (#2070)
04aaacf39 is described below
commit 04aaacf39c9d6de6e2732ec89accdb73752a0360
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Thu Feb 13 10:08:03 2025 +0100
[incubator-kie-issues#1825] Implement AllowedValuesChecksInsideCollection
model usage inside dmn examples. (#2070)
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
.../dmn-quarkus-example/README.md | 105 ++++++++++++++++++++-
.../AllowedValuesChecksInsideCollection.dmn | 77 +++++++++++++++
.../src/main/resources/application.properties | 2 +
.../dmn/quarkus/example/AllowedValuesTest.java | 71 ++++++++++++++
.../dmn-springboot-example/README.md | 105 ++++++++++++++++++++-
.../AllowedValuesChecksInsideCollection.dmn | 77 +++++++++++++++
.../src/main/resources/application.properties | 4 +-
.../dmn/springboot/example/AllowedValuesTest.java | 84 +++++++++++++++++
8 files changed, 522 insertions(+), 3 deletions(-)
diff --git a/kogito-quarkus-examples/dmn-quarkus-example/README.md
b/kogito-quarkus-examples/dmn-quarkus-example/README.md
index 18e4a5f7b..233ee5f03 100644
--- a/kogito-quarkus-examples/dmn-quarkus-example/README.md
+++ b/kogito-quarkus-examples/dmn-quarkus-example/README.md
@@ -2,7 +2,9 @@
## Description
-A simple DMN service to evaluate a traffic violation.
+A simple DMN service to evaluate a traffic violation and a model with input
constraints.
+
+The org.kie.dmn.runtime.typecheck=true property is used to enable type and
value check.
Demonstrates DMN on Kogito capabilities, including REST interface code
generation.
@@ -128,3 +130,104 @@ Example response:
"Should the driver be suspended?":"No"
}
```
+
+### POST /AllowedValuesChecksInsideCollection
+
+Valid interests for the model are: Golf, Computer, Hockey, Jogging
+
+Given valid input:
+
+```json
+{
+ "p1": {
+ "Name": "Joe",
+ "Interests": [
+ "Golf"
+ ]
+ }
+}
+```
+
+Curl command (using the JSON object above):
+
+```sh
+curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json'
-d 'p1": {"Name":"Joe","Interests":["Golf"]}'
http://localhost:8080/AllowedValuesChecksInsideCollection
+```
+
+As response, interests information is returned.
+
+Example response:
+```json
+{
+ "p1": {
+ "Interests": [
+ "Golf"
+ ],
+ "Name": "Joe"
+ },
+ "MyDecision": "The Person Joe likes 1 thing(s)."
+}
+```
+
+With invalid value
+
+```json
+{
+ "p1": {
+ "Name": "Joe",
+ "Interests": [
+ "Dancing"
+ ]
+ }
+}
+```
+
+Curl command (using the JSON object above):
+
+```sh
+curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json'
-d 'p1": {"Name":"Joe","Interests":["Dancing"]}'
http://localhost:8080/AllowedValuesChecksInsideCollection
+```
+
+As response, error information is returned.
+
+Example response:
+```json
+{
+ "namespace":
"http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442",
+ "modelName": "AllowedValuesChecksInsideCollection",
+ "dmnContext": {
+ "p1": {
+ "Interests": [
+ "Dancing"
+ ],
+ "Name": "Joe"
+ }
+ },
+ "messages": [
+ {
+ "severity": "ERROR",
+ "message": "Error while evaluating node 'MyDecision' for dependency 'p1':
the dependency value '{Interests=[Dancing], Name=Joe}' is not allowed by the
declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })",
+ "messageType": "ERROR_EVAL_NODE",
+ "sourceId": "_27453770-68e3-48da-8605-d33a653c09ef",
+ "level": "ERROR"
+ }
+ ],
+ "decisionResults": [
+ {
+ "decisionId": "_ed3b9794-9306-4b6a-b4f9-5486be3c5515",
+ "decisionName": "MyDecision",
+ "result": null,
+ "messages": [
+ {
+ "severity": "ERROR",
+ "message": "Error while evaluating node 'MyDecision' for dependency 'p1':
the dependency value '{Interests=[Dancing], Name=Joe}' is not allowed by the
declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })",
+ "messageType": "ERROR_EVAL_NODE",
+ "sourceId": "_27453770-68e3-48da-8605-d33a653c09ef",
+ "level": "ERROR"
+ }
+ ],
+ "evaluationStatus": "SKIPPED"
+ }
+ ]
+}
+```
diff --git
a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
new file mode 100644
index 000000000..ade557ea7
--- /dev/null
+++
b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<dmn:definitions
xmlns="http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442"
+ xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
+ xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
+ xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/"
+ xmlns:feel="https://www.omg.org/spec/DMN/20230324/FEEL/"
+ xmlns:dmn="https://www.omg.org/spec/DMN/20230324/MODEL/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ exporter="DMN Modeler"
+ exporterVersion="5.1.10.201705011622"
+ id="_238bd96d-47cd-4746-831b-504f3e77b442"
+ name="AllowedValuesChecksInsideCollection"
+
namespace="http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442">
+ <dmn:itemDefinition isCollection="false" label="Person" name="Person">
+ <dmn:itemComponent id="_7939ee65-737d-4ea9-b912-448dd5fb2cf1"
+ isCollection="false"
+ name="Name">
+ <dmn:typeRef>string</dmn:typeRef>
+ </dmn:itemComponent>
+ <dmn:itemComponent id="_19ef99ee-1d53-4185-aa9d-8fe58a7834ce"
+ isCollection="true"
+ name="Interests">
+ <dmn:typeRef>tInterests</dmn:typeRef>
+ </dmn:itemComponent>
+ </dmn:itemDefinition>
+ <dmn:itemDefinition label="tInterest" name="tInterest">
+ <dmn:typeRef>string</dmn:typeRef>
+ </dmn:itemDefinition>
+ <dmn:itemDefinition isCollection="true" label="tInterests"
name="tInterests">
+ <dmn:typeRef>tInterest</dmn:typeRef>
+ <dmn:allowedValues
xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ triso:constraintsType="enumeration">
+ <dmn:text>"Golf","Computer","Hockey","Jogging"</dmn:text>
+ </dmn:allowedValues>
+ </dmn:itemDefinition>
+ <dmn:decision xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ id="_ed3b9794-9306-4b6a-b4f9-5486be3c5515"
+ name="MyDecision"
+ triso:displayName="MyDecision">
+ <dmn:variable id="_2e39fe17-4902-40ba-a36c-7fe0d3d992b9"
+ name="MyDecision"
+ typeRef="string"/>
+ <dmn:informationRequirement>
+ <dmn:requiredInput href="#_27453770-68e3-48da-8605-d33a653c09ef"/>
+ </dmn:informationRequirement>
+ <dmn:literalExpression id="_71df1866-2b74-4d40-b4fd-0ebe860b27f1">
+ <dmn:text>"The Person " + p1.Name + " likes " + string(count(
p1.Interests )) + " thing(s)."</dmn:text>
+ </dmn:literalExpression>
+ </dmn:decision>
+ <dmn:inputData xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ id="_27453770-68e3-48da-8605-d33a653c09ef"
+ name="p1"
+ triso:displayName="p1">
+ <dmn:variable id="_1c6c0e02-8b82-4d1f-88a6-a2e35b4eedc7"
+ name="p1"
+ typeRef="Person"/>
+ </dmn:inputData>
+</dmn:definitions>
\ No newline at end of file
diff --git
a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/application.properties
b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/application.properties
index 727b6c82f..de9038038 100644
---
a/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/application.properties
+++
b/kogito-quarkus-examples/dmn-quarkus-example/src/main/resources/application.properties
@@ -20,3 +20,5 @@
# Packaging
quarkus.swagger-ui.always-include=true
+
+org.kie.dmn.runtime.typecheck=true
diff --git
a/kogito-quarkus-examples/dmn-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/AllowedValuesTest.java
b/kogito-quarkus-examples/dmn-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/AllowedValuesTest.java
new file mode 100644
index 000000000..80dd1992a
--- /dev/null
+++
b/kogito-quarkus-examples/dmn-quarkus-example/src/test/java/org/kie/kogito/dmn/quarkus/example/AllowedValuesTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.CoreMatchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+@QuarkusTest
+public class AllowedValuesTest {
+
+ @Test
+ public void testAllowedValuesWithValidValue() {
+ given()
+ .body("{\n" +
+ " \"p1\": {\n" +
+ " \"Name\": \"Joe\",\n" +
+ " \"Interests\": [\n" +
+ " \"Golf\"\n" +
+ " ]\n" +
+ " }\n" +
+ "}")
+ .contentType(ContentType.JSON)
+ .when()
+ .post("/AllowedValuesChecksInsideCollection")
+ .then()
+ .statusCode(200)
+ .body("'MyDecision'", is("The Person Joe likes 1 thing(s)."));
+ }
+
+ @Test
+ public void testAllowedValuesWithInvalidValue() {
+ given()
+ .body("{\n" +
+ " \"p1\": {\n" +
+ " \"Name\": \"Joe\",\n" +
+ " \"Interests\": [\n" +
+ " \"Dancing\"\n" +
+ " ]\n" +
+ " }\n" +
+ "}")
+ .contentType(ContentType.JSON)
+ .when()
+ .post("/AllowedValuesChecksInsideCollection")
+ .then()
+ .statusCode(500)
+ .body("messages[0].message", containsString(
+ "Error while evaluating node 'MyDecision' for
dependency 'p1': the dependency value '{Interests=[Dancing], Name=Joe}' is not
allowed by the declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })"));
+ }
+}
diff --git a/kogito-springboot-examples/dmn-springboot-example/README.md
b/kogito-springboot-examples/dmn-springboot-example/README.md
index faac896f3..3e9006071 100644
--- a/kogito-springboot-examples/dmn-springboot-example/README.md
+++ b/kogito-springboot-examples/dmn-springboot-example/README.md
@@ -2,7 +2,9 @@
## Description
-A simple DMN service to evaluate a traffic violation.
+A simple DMN service to evaluate a traffic violation and a model with input
constraints.
+
+The org.kie.dmn.runtime.typecheck=true property is used to enable type and
value check.
## Installing and Running
@@ -84,6 +86,107 @@ Example response:
}
```
+### POST /AllowedValuesChecksInsideCollection
+
+Valid interests for the model are: Golf, Computer, Hockey, Jogging
+
+Given valid input:
+
+```json
+{
+ "p1": {
+ "Name": "Joe",
+ "Interests": [
+ "Golf"
+ ]
+ }
+}
+```
+
+Curl command (using the JSON object above):
+
+```sh
+curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json'
-d 'p1": {"Name":"Joe","Interests":["Golf"]}'
http://localhost:8080/AllowedValuesChecksInsideCollection
+```
+
+As response, interests information is returned.
+
+Example response:
+```json
+{
+ "p1": {
+ "Interests": [
+ "Golf"
+ ],
+ "Name": "Joe"
+ },
+ "MyDecision": "The Person Joe likes 1 thing(s)."
+}
+```
+
+With invalid value
+
+```json
+{
+ "p1": {
+ "Name": "Joe",
+ "Interests": [
+ "Dancing"
+ ]
+ }
+}
+```
+
+Curl command (using the JSON object above):
+
+```sh
+curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json'
-d 'p1": {"Name":"Joe","Interests":["Dancing"]}'
http://localhost:8080/AllowedValuesChecksInsideCollection
+```
+
+As response, error information is returned.
+
+Example response:
+```json
+{
+ "namespace":
"http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442",
+ "modelName": "AllowedValuesChecksInsideCollection",
+ "dmnContext": {
+ "p1": {
+ "Interests": [
+ "Dancing"
+ ],
+ "Name": "Joe"
+ }
+ },
+ "messages": [
+ {
+ "severity": "ERROR",
+ "message": "Error while evaluating node 'MyDecision' for dependency 'p1':
the dependency value '{Interests=[Dancing], Name=Joe}' is not allowed by the
declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })",
+ "messageType": "ERROR_EVAL_NODE",
+ "sourceId": "_27453770-68e3-48da-8605-d33a653c09ef",
+ "level": "ERROR"
+ }
+ ],
+ "decisionResults": [
+ {
+ "decisionId": "_ed3b9794-9306-4b6a-b4f9-5486be3c5515",
+ "decisionName": "MyDecision",
+ "result": null,
+ "messages": [
+ {
+ "severity": "ERROR",
+ "message": "Error while evaluating node 'MyDecision' for dependency 'p1':
the dependency value '{Interests=[Dancing], Name=Joe}' is not allowed by the
declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })",
+ "messageType": "ERROR_EVAL_NODE",
+ "sourceId": "_27453770-68e3-48da-8605-d33a653c09ef",
+ "level": "ERROR"
+ }
+ ],
+ "evaluationStatus": "SKIPPED"
+ }
+ ]
+}
+```
+
## Developer notes
In order to have the DMN generated resources properly scanned by Spring Boot,
please ensure the DMN model namespaces
diff --git
a/kogito-springboot-examples/dmn-springboot-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
b/kogito-springboot-examples/dmn-springboot-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
new file mode 100644
index 000000000..ade557ea7
--- /dev/null
+++
b/kogito-springboot-examples/dmn-springboot-example/src/main/resources/AllowedValuesChecksInsideCollection.dmn
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<dmn:definitions
xmlns="http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442"
+ xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
+ xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/"
+ xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/"
+ xmlns:feel="https://www.omg.org/spec/DMN/20230324/FEEL/"
+ xmlns:dmn="https://www.omg.org/spec/DMN/20230324/MODEL/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ exporter="DMN Modeler"
+ exporterVersion="5.1.10.201705011622"
+ id="_238bd96d-47cd-4746-831b-504f3e77b442"
+ name="AllowedValuesChecksInsideCollection"
+
namespace="http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442">
+ <dmn:itemDefinition isCollection="false" label="Person" name="Person">
+ <dmn:itemComponent id="_7939ee65-737d-4ea9-b912-448dd5fb2cf1"
+ isCollection="false"
+ name="Name">
+ <dmn:typeRef>string</dmn:typeRef>
+ </dmn:itemComponent>
+ <dmn:itemComponent id="_19ef99ee-1d53-4185-aa9d-8fe58a7834ce"
+ isCollection="true"
+ name="Interests">
+ <dmn:typeRef>tInterests</dmn:typeRef>
+ </dmn:itemComponent>
+ </dmn:itemDefinition>
+ <dmn:itemDefinition label="tInterest" name="tInterest">
+ <dmn:typeRef>string</dmn:typeRef>
+ </dmn:itemDefinition>
+ <dmn:itemDefinition isCollection="true" label="tInterests"
name="tInterests">
+ <dmn:typeRef>tInterest</dmn:typeRef>
+ <dmn:allowedValues
xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ triso:constraintsType="enumeration">
+ <dmn:text>"Golf","Computer","Hockey","Jogging"</dmn:text>
+ </dmn:allowedValues>
+ </dmn:itemDefinition>
+ <dmn:decision xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ id="_ed3b9794-9306-4b6a-b4f9-5486be3c5515"
+ name="MyDecision"
+ triso:displayName="MyDecision">
+ <dmn:variable id="_2e39fe17-4902-40ba-a36c-7fe0d3d992b9"
+ name="MyDecision"
+ typeRef="string"/>
+ <dmn:informationRequirement>
+ <dmn:requiredInput href="#_27453770-68e3-48da-8605-d33a653c09ef"/>
+ </dmn:informationRequirement>
+ <dmn:literalExpression id="_71df1866-2b74-4d40-b4fd-0ebe860b27f1">
+ <dmn:text>"The Person " + p1.Name + " likes " + string(count(
p1.Interests )) + " thing(s)."</dmn:text>
+ </dmn:literalExpression>
+ </dmn:decision>
+ <dmn:inputData xmlns:triso="http://www.trisotech.com/2015/triso/modeling"
+ id="_27453770-68e3-48da-8605-d33a653c09ef"
+ name="p1"
+ triso:displayName="p1">
+ <dmn:variable id="_1c6c0e02-8b82-4d1f-88a6-a2e35b4eedc7"
+ name="p1"
+ typeRef="Person"/>
+ </dmn:inputData>
+</dmn:definitions>
\ No newline at end of file
diff --git
a/kogito-springboot-examples/dmn-springboot-example/src/main/resources/application.properties
b/kogito-springboot-examples/dmn-springboot-example/src/main/resources/application.properties
index fcbf5c650..a3205e4e7 100644
---
a/kogito-springboot-examples/dmn-springboot-example/src/main/resources/application.properties
+++
b/kogito-springboot-examples/dmn-springboot-example/src/main/resources/application.properties
@@ -19,4 +19,6 @@
# Packaging
-server.address=0.0.0.0
\ No newline at end of file
+server.address=0.0.0.0
+
+org.kie.dmn.runtime.typecheck=true
\ No newline at end of file
diff --git
a/kogito-springboot-examples/dmn-springboot-example/src/test/java/org/kie/kogito/dmn/springboot/example/AllowedValuesTest.java
b/kogito-springboot-examples/dmn-springboot-example/src/test/java/org/kie/kogito/dmn/springboot/example/AllowedValuesTest.java
new file mode 100644
index 000000000..26f5d4189
--- /dev/null
+++
b/kogito-springboot-examples/dmn-springboot-example/src/test/java/org/kie/kogito/dmn/springboot/example/AllowedValuesTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.springboot.example;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.annotation.DirtiesContext;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = KogitoSpringbootApplication.class)
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
+public class AllowedValuesTest {
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ public void setUp() {
+ RestAssured.port = port;
+ }
+
+ @Test
+ public void testAllowedValuesWithValidValue() {
+ given()
+ .body("{\n" +
+ " \"p1\": {\n" +
+ " \"Name\": \"Joe\",\n" +
+ " \"Interests\": [\n" +
+ " \"Golf\"\n" +
+ " ]\n" +
+ " }\n" +
+ "}")
+ .contentType(ContentType.JSON)
+ .when()
+ .post("/AllowedValuesChecksInsideCollection")
+ .then()
+ .statusCode(200)
+ .body("'MyDecision'", is("The Person Joe likes 1 thing(s)."));
+ }
+
+ @Test
+ public void testAllowedValuesWithInvalidValue() {
+ given()
+ .body("{\n" +
+ " \"p1\": {\n" +
+ " \"Name\": \"Joe\",\n" +
+ " \"Interests\": [\n" +
+ " \"Dancing\"\n" +
+ " ]\n" +
+ " }\n" +
+ "}")
+ .contentType(ContentType.JSON)
+ .when()
+ .post("/AllowedValuesChecksInsideCollection")
+ .then()
+ .statusCode(500)
+ .body("messages[0].message", containsString(
+ "Error while evaluating node 'MyDecision' for
dependency 'p1': the dependency value '{Interests=[Dancing], Name=Joe}' is not
allowed by the declared type (DMNType{
http://www.trisotech.com/definitions/_238bd96d-47cd-4746-831b-504f3e77b442 :
Person })"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]