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-drools.git
The following commit(s) were added to refs/heads/main by this push:
new cc062e7d69 [incubator-kie-issues#1065] Remove dmn test resource
unpacking (#5828)
cc062e7d69 is described below
commit cc062e7d69463e1a6adce25a7d04ca63eca873d6
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Mon Apr 8 10:51:06 2024 +0200
[incubator-kie-issues#1065] Remove dmn test resource unpacking (#5828)
* [incubator-kie-issues#1065] Remove dmn test resource unpacking
* [incubator-kie-issues#1065] Fix
ValidatorTest.validateAllValidSharedModels (attempt)
* [incubator-kie-issues#1065] Fix
ValidatorTest.validateAllValidSharedModels (attempt)
---------
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
kie-dmn/kie-dmn-validation/pom.xml | 32 -----------
.../java/org/kie/dmn/validation/ValidatorTest.java | 65 +++++++++-------------
2 files changed, 27 insertions(+), 70 deletions(-)
diff --git a/kie-dmn/kie-dmn-validation/pom.xml
b/kie-dmn/kie-dmn-validation/pom.xml
index 3dfc05eb19..863a165af9 100644
--- a/kie-dmn/kie-dmn-validation/pom.xml
+++ b/kie-dmn/kie-dmn-validation/pom.xml
@@ -181,40 +181,8 @@
<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>valid_models/**/*.dmn</includes>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
diff --git
a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
index 9096a81755..d3668ecca9 100644
---
a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
+++
b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
@@ -24,18 +24,13 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.file.DirectoryIteratorException;
-import java.nio.file.DirectoryStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Objects;
-import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
-import org.drools.io.FileSystemResource;
+import org.drools.io.ClassPathResource;
import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.builder.Message.Level;
@@ -533,40 +528,34 @@ public class ValidatorTest extends AbstractValidatorTest {
}
@Test
- public void validateAllValidSharedModels() throws URISyntaxException,
IOException {
- String modelFilesPath = "valid_models";
- URL modelFilesUrl =
-
Collections.list(Thread.currentThread().getContextClassLoader().getResources(modelFilesPath))
+ public void validateAllValidSharedModels() throws IOException {
+ String modelFilesPath = "valid_models/";
+ URL modelFilesJarURL =
Collections.list(Thread.currentThread().getContextClassLoader().getResources(
+ "valid_models/"))
.stream()
- .filter(url -> url.getProtocol().equals("file"))
+ .filter(url -> url.getProtocol().equals("jar"))
.findFirst()
- .orElseThrow(() -> new RuntimeException("Failed to retrieve "
+ modelFilesPath));
- Path modelsPath = Path.of(modelFilesUrl.toURI());
- testDirectory(modelsPath);
- }
-
- private void testDirectory(Path modelsPath) {
- try (DirectoryStream<Path> pathIterator =
Files.newDirectoryStream(modelsPath)) {
- Map<Boolean, List<Path>> allFiles =
StreamSupport.stream(pathIterator.spliterator(), false)
- .collect(Collectors.groupingBy(path ->
path.toFile().isDirectory()));
- if (allFiles.containsKey(true)) {
- allFiles.get(true).forEach(this::testDirectory);
- }
- if (allFiles.containsKey(false)) {
- testFiles(allFiles.get(false));
- }
- } catch (IOException | DirectoryIteratorException e) {
- String messageToShow = e.getMessage() != null &&
!e.getMessage().isEmpty() ? e.getMessage() : String.format("Unable to navigate
directory %s", modelsPath);
- LOGGER.error(messageToShow);
- LOGGER.debug(messageToShow, e);
- fail(messageToShow);
- }
+ .orElseThrow(() -> new RuntimeException("Failed to retrieve
jar containing " + modelFilesPath));
+ String modelFilesJarFile = modelFilesJarURL.getFile();
+ String jarPath =
modelFilesJarFile.substring(modelFilesJarFile.lastIndexOf(":") + 1,
+
modelFilesJarFile.lastIndexOf("!"));
+ final JarFile jarFile = new JarFile(new File(jarPath));
+ testDirectoryInJar(jarFile, modelFilesPath);
+ }
+
+ private void testDirectoryInJar(JarFile jarFile, String directory) {
+ List<String> allFiles = Collections.list(jarFile.entries())
+ .stream()
+ .filter(entry -> entry.getName().startsWith(directory) &&
!entry.isDirectory())
+ .map(ZipEntry::getName)
+ .toList();
+ testFiles(allFiles);
}
- private void testFiles(List<Path> modelPaths) {
- Resource[] resources = modelPaths.stream()
- .map(path -> new FileSystemResource(path.toFile()))
- .toArray(value -> new Resource[modelPaths.size()]);
+ private void testFiles(List<String> modelFiles) {
+ Resource[] resources = modelFiles.stream()
+ .map(ClassPathResource::new)
+ .toArray(value -> new Resource[modelFiles.size()]);
List<DMNMessage> dmnMessages = validatorBuilder.theseModels(resources);
assertNotNull(dmnMessages);
dmnMessages.forEach(dmnMessage -> LOGGER.error(dmnMessage.toString()));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]