Skip to content

Commit

Permalink
[incubator-kie-issues#1044] DMN: Copy shared models (#3458)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriele-Cardosi <[email protected]>
  • Loading branch information
gitgabrio and Gabriele-Cardosi authored Apr 2, 2024
1 parent f4821b9 commit 02c6b00
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 308 deletions.
55 changes: 55 additions & 0 deletions kogito-codegen-modules/kogito-codegen-decisions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<properties>
<java.module.name>org.kie.kogito.codegen.decision</java.module.name>
<dependency-plugin.version>3.6.1</dependency-plugin.version>
</properties>

<dependencyManagement>
Expand All @@ -44,6 +45,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-test-resources</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -73,6 +80,12 @@


<!-- test -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-test-resources</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-codegen-api</artifactId>
Expand Down Expand Up @@ -110,4 +123,46 @@
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.build.directory}/generated-test-resources</directory>
</testResource>
</testResources>
<plugins>
<!-- Unpack DMN resources from org.kie:kie-dmn-test-resources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${dependency-plugin.version}</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.kie</groupId>
<artifactId>kie-dmn-test-resources</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/generated-test-resources</outputDirectory>
<includes>**/*.dmn</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class CodegenUtilsTest {

@Test
void getDefinitionsFileFromModelWithSpace() {
File dmnFile = FileUtils.getFile("Traffic Violation.dmn");
String modelFile = "Traffic Violation Simple.dmn";
File dmnFile = FileUtils.getFile(modelFile);
assertNotNull(dmnFile);
assertTrue(dmnFile.exists());
Resource dmnResource = new FileSystemResource(dmnFile, StandardCharsets.UTF_8.name());
Expand All @@ -53,15 +54,15 @@ void getDefinitionsFileFromModelWithSpace() {
.fromResources(Collections.singleton(dmnResource))
.getOrElseThrow(e -> new RuntimeException("Error compiling DMN model(s)", e));
assertThat(dmnRuntime.getModels()).hasSize(1);
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation Model Name");
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation");
assertNotNull(dmnModel);
String expected = "Traffic_Violation.json";
String expected = "Traffic_Violation_Simple.json";
assertEquals(expected, CodegenUtils.getDefinitionsFileFromModel(dmnModel));
}

@Test
void geNameForDefinitionsFileWithSourcePath() {
File dmnFile = FileUtils.getFile("Traffic Violation.dmn");
File dmnFile = FileUtils.getFile("Traffic Violation Simple.dmn");
assertNotNull(dmnFile);
assertTrue(dmnFile.exists());
Resource dmnResource = new FileSystemResource(dmnFile, StandardCharsets.UTF_8.name());
Expand All @@ -71,23 +72,23 @@ void geNameForDefinitionsFileWithSourcePath() {
.fromResources(Collections.singleton(dmnResource))
.getOrElseThrow(e -> new RuntimeException("Error compiling DMN model(s)", e));
assertThat(dmnRuntime.getModels()).hasSize(1);
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation Model Name");
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation");
assertNotNull(dmnModel);
String expected = "Traffic Violation.dmn";
String expected = "Traffic Violation Simple.dmn";
assertEquals(expected, CodegenUtils.geNameForDefinitionsFile(dmnModel));
}

@Test
void geNameForDefinitionsFileWithoutSourcePath() throws FileNotFoundException {
File dmnFile = FileUtils.getFile("Traffic Violation.dmn");
File dmnFile = FileUtils.getFile("Traffic Violation Simple.dmn");
assertNotNull(dmnFile);
assertTrue(dmnFile.exists());
DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new FileReader(dmnFile));
assertNotNull(dmnRuntime);
assertThat(dmnRuntime.getModels()).hasSize(1);
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation Model Name");
final DMNModel dmnModel = dmnRuntime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation");
assertNotNull(dmnModel);
String expected = "Traffic Violation Model Name.dmn";
String expected = "Traffic Violation.dmn";
assertEquals(expected, CodegenUtils.geNameForDefinitionsFile(dmnModel));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void resilientToDuplicateDMNIDs(KogitoBuildContext.Builder contextBuilder
public void emptyName(KogitoBuildContext.Builder contextBuilder) {
DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-empty-name", contextBuilder);
RuntimeException re = Assertions.assertThrows(RuntimeException.class, codeGenerator::generate);
String expected = "DMN: Invalid name '': Name cannot be null or empty (DMN id: _f27bb64b-6fc7-4e1f-9848-11ba35e0df44, The listed name is not a valid FEEL identifier)";
String expected = "DMN: Invalid name '': Name cannot be null or empty (DMN id: _9efe7fc6-f41b-422c-accd-95dcaaa67a39, The listed name is not a valid FEEL identifier)";
assertTrue(re.getMessage().contains(expected));
}

Expand Down
Loading

0 comments on commit 02c6b00

Please sign in to comment.