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 55df2f4c8 [incubator-kie-issues#1806] Extend dmn-resource examples to
also feature custom DMNProfile usage (#2069)
55df2f4c8 is described below
commit 55df2f4c8ebca6df2a9b1a9494f9ea5161f15795
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Wed Feb 12 10:45:28 2025 +0100
[incubator-kie-issues#1806] Extend dmn-resource examples to also feature
custom DMNProfile usage (#2069)
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
.../dmn-resource-jar-quarkus-example/README.md | 1 +
.../src/main/resources/application.properties | 1 +
.../dmn/consumer/example/TrafficViolationTest.java | 18 +++++++++
.../dmn-quarkus-resource-jar/pom.xml | 16 ++++++++
.../example/customprofiles/CustomDMNProfile.java | 44 ++++++++++++++++++++++
.../dmn-resource-jar-springboot-example/README.md | 1 +
.../src/main/resources/application.properties | 3 +-
.../consumer/example/TrafficViolationTest.java | 19 ++++++++++
.../dmn-springboot-resource-jar/pom.xml | 16 ++++++++
.../example/customprofiles/CustomDMNProfile.java | 44 ++++++++++++++++++++++
10 files changed, 162 insertions(+), 1 deletion(-)
diff --git a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/README.md
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/README.md
index 50d9dd5d9..dba21ef19 100644
--- a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/README.md
+++ b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/README.md
@@ -3,6 +3,7 @@
## Description
A simple DMN service to evaluate a model (traffic violation) that is imported
from a different jar.
+It also features the usage of custom DMN profiles, imported from a dependency
and declared inside the application.properties file.
Demonstrates DMN on Kogito capabilities, including REST interface code
generation.
diff --git
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/main/resources/application.properties
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/main/resources/application.properties
index 727b6c82f..4bdadff55 100644
---
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/main/resources/application.properties
+++
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/main/resources/application.properties
@@ -20,3 +20,4 @@
# Packaging
quarkus.swagger-ui.always-include=true
+org.kie.dmn.profiles.CustomDMNProfile=org.kie.kogito.dmn.consumer.example.customprofiles.CustomDMNProfile
diff --git
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/test/java/org/kie/kogito/dmn/consumer/example/TrafficViolationTest.java
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/test/java/org/kie/kogito/dmn/consumer/example/TrafficViolationTest.java
index 612166f5e..34be5f4a8 100644
---
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/test/java/org/kie/kogito/dmn/consumer/example/TrafficViolationTest.java
+++
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-consumer-example/src/test/java/org/kie/kogito/dmn/consumer/example/TrafficViolationTest.java
@@ -19,16 +19,24 @@
package org.kie.kogito.dmn.consumer.example;
import org.junit.jupiter.api.Test;
+import org.kie.kogito.decision.DecisionModel;
+import org.kie.kogito.decision.DecisionModels;
+import org.kie.kogito.dmn.DmnDecisionModel;
+import org.kie.kogito.dmn.consumer.example.customprofiles.CustomDMNProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
@QuarkusTest
public class TrafficViolationTest {
+ @jakarta.inject.Inject
+ DecisionModels decisionModels;
+
@Test
public void testEvaluateTrafficViolation() {
given()
@@ -49,4 +57,14 @@ public class TrafficViolationTest {
.statusCode(200)
.body("'Should the driver be suspended?'", is("No"));
}
+
+ @Test
+ void testCustomDMNProfile() {
+ assertThat(decisionModels).isNotNull();
+ DecisionModel decisionModel =
decisionModels.getDecisionModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF",
"Traffic Violation");
+
assertThat(decisionModel).isNotNull().isInstanceOf(DmnDecisionModel.class);
+ DmnDecisionModel dmnDecisionModel = (DmnDecisionModel) decisionModel;
+ assertThat(dmnDecisionModel).isNotNull();
+ assertThat(dmnDecisionModel.getProfiles()).anyMatch(profile -> profile
instanceof CustomDMNProfile);
+ }
}
diff --git
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/pom.xml
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/pom.xml
index d7790464c..4058961ef 100644
---
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/pom.xml
+++
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/pom.xml
@@ -16,6 +16,22 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
<build>
<plugins>
<plugin>
diff --git
a/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
new file mode 100644
index 000000000..a566a46f4
--- /dev/null
+++
b/kogito-quarkus-examples/dmn-resource-jar-quarkus-example/dmn-quarkus-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
@@ -0,0 +1,44 @@
+/*
+ * 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.consumer.example.customprofiles;
+
+import java.util.List;
+
+import org.kie.dmn.api.marshalling.DMNExtensionRegister;
+import org.kie.dmn.core.compiler.DMNProfile;
+import org.kie.dmn.core.compiler.DRGElementCompiler;
+import org.kie.dmn.feel.runtime.FEELFunction;
+
+public class CustomDMNProfile implements DMNProfile {
+
+ @Override
+ public List<DMNExtensionRegister> getExtensionRegisters() {
+ return List.of();
+ }
+
+ @Override
+ public List<DRGElementCompiler> getDRGElementCompilers() {
+ return List.of();
+ }
+
+ @Override
+ public List<FEELFunction> getFEELFunctions() {
+ return List.of();
+ }
+}
\ No newline at end of file
diff --git
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/README.md
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/README.md
index e6c24ad70..52f14eeae 100644
--- a/kogito-springboot-examples/dmn-resource-jar-springboot-example/README.md
+++ b/kogito-springboot-examples/dmn-resource-jar-springboot-example/README.md
@@ -3,6 +3,7 @@
## Description
A simple DMN service to evaluate a model (traffic violation) that is imported
from a different jar.
+It also features the usage of custom DMN profiles, imported from a dependency
and declared inside the application.properties file.
Demonstrates DMN on Kogito capabilities, including REST interface code
generation.
diff --git
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/main/resources/application.properties
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/main/resources/application.properties
index fcbf5c650..9bbe9643f 100644
---
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/main/resources/application.properties
+++
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/main/resources/application.properties
@@ -19,4 +19,5 @@
# Packaging
-server.address=0.0.0.0
\ No newline at end of file
+server.address=0.0.0.0
+org.kie.dmn.profiles.CustomDMNProfile=org.kie.kogito.dmn.consumer.example.customprofiles.CustomDMNProfile
\ No newline at end of file
diff --git
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/test/java/org/kie/kogito/dmn/springboot/consumer/example/TrafficViolationTest.java
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/test/java/org/kie/kogito/dmn/springboot/consumer/example/TrafficViolationTest.java
index 920025c1b..077e4f84d 100644
---
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/test/java/org/kie/kogito/dmn/springboot/consumer/example/TrafficViolationTest.java
+++
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-consumer-example/src/test/java/org/kie/kogito/dmn/springboot/consumer/example/TrafficViolationTest.java
@@ -20,6 +20,11 @@ package org.kie.kogito.dmn.springboot.consumer.example;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.kie.kogito.decision.DecisionModel;
+import org.kie.kogito.decision.DecisionModels;
+import org.kie.kogito.dmn.DmnDecisionModel;
+import org.kie.kogito.dmn.consumer.example.customprofiles.CustomDMNProfile;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
@@ -28,6 +33,7 @@ import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = KogitoSpringbootApplication.class)
@@ -37,6 +43,9 @@ public class TrafficViolationTest {
@LocalServerPort
private int port;
+ @Autowired
+ DecisionModels decisionModels;
+
@BeforeEach
public void setUp() {
RestAssured.port = port;
@@ -62,4 +71,14 @@ public class TrafficViolationTest {
.statusCode(200)
.body("'Should the driver be suspended?'", is("No"));
}
+
+ @Test
+ void testCustomDMNProfile() {
+ assertThat(decisionModels).isNotNull();
+ DecisionModel decisionModel =
decisionModels.getDecisionModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF",
"Traffic Violation");
+
assertThat(decisionModel).isNotNull().isInstanceOf(DmnDecisionModel.class);
+ DmnDecisionModel dmnDecisionModel = (DmnDecisionModel) decisionModel;
+ assertThat(dmnDecisionModel).isNotNull();
+ assertThat(dmnDecisionModel.getProfiles()).anyMatch(profile -> profile
instanceof CustomDMNProfile);
+ }
}
diff --git
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/pom.xml
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/pom.xml
index f6b89b322..89ec5c863 100644
---
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/pom.xml
+++
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/pom.xml
@@ -16,6 +16,22 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
<build>
<plugins>
<plugin>
diff --git
a/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
new file mode 100644
index 000000000..a566a46f4
--- /dev/null
+++
b/kogito-springboot-examples/dmn-resource-jar-springboot-example/dmn-springboot-resource-jar/src/main/java/org/kie/kogito/dmn/consumer/example/customprofiles/CustomDMNProfile.java
@@ -0,0 +1,44 @@
+/*
+ * 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.consumer.example.customprofiles;
+
+import java.util.List;
+
+import org.kie.dmn.api.marshalling.DMNExtensionRegister;
+import org.kie.dmn.core.compiler.DMNProfile;
+import org.kie.dmn.core.compiler.DRGElementCompiler;
+import org.kie.dmn.feel.runtime.FEELFunction;
+
+public class CustomDMNProfile implements DMNProfile {
+
+ @Override
+ public List<DMNExtensionRegister> getExtensionRegisters() {
+ return List.of();
+ }
+
+ @Override
+ public List<DRGElementCompiler> getDRGElementCompilers() {
+ return List.of();
+ }
+
+ @Override
+ public List<FEELFunction> getFEELFunctions() {
+ return List.of();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]