Move test utils into new module 22/143322/6
authordanielhanrahan <daniel.hanrahan@est.tech>
Fri, 13 Feb 2026 18:08:30 +0000 (18:08 +0000)
committerDaniel Hanrahan <daniel.hanrahan@est.tech>
Thu, 26 Feb 2026 02:24:48 +0000 (02:24 +0000)
Move test utility classes from policy-common into a
separate module, so that dependencies such as hamcrest
and openpojo will not be included in final JAR.

Issue-ID: POLICY-5503
Change-Id: Ib7703737375ecae347dd7befd7c72d38b83c68dc
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
24 files changed:
clamp-parent/dependencies/pom.xml
models/pom.xml
participant/participant-impl/pom.xml
policy-common/pom.xml
policy-common/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json [deleted file]
policy-models/pom.xml
pom.xml
runtime-acm/pom.xml
test-utils/pom.xml [new file with mode: 0644]
test-utils/src/main/java/org/onap/policy/common/utils/jackson/JacksonTestUtils.java [moved from policy-common/src/main/java/org/onap/policy/common/utils/jackson/JacksonTestUtils.java with 97% similarity]
test-utils/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java [moved from policy-common/src/main/java/org/onap/policy/common/utils/resources/ResourceUtils.java with 93% similarity]
test-utils/src/main/java/org/onap/policy/common/utils/test/PojoTester.java [moved from policy-common/src/main/java/org/onap/policy/common/utils/test/PojoTester.java with 100% similarity]
test-utils/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java [moved from policy-common/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java with 100% similarity]
test-utils/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java [moved from policy-common/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.java with 97% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java with 89% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/PojoTesterTest.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/PojoTesterTest.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/ToStringTesterTest.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/ToStringTesterTest.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/pojo/empty/NotAPojo.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/pojo/empty/NotAPojo.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/pojo/invalid/InvalidPojo.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/pojo/invalid/InvalidPojo.java with 100% similarity]
test-utils/src/test/java/org/onap/policy/common/utils/test/pojo/valid/ValidPojo.java [moved from policy-common/src/test/java/org/onap/policy/common/utils/test/pojo/valid/ValidPojo.java with 100% similarity]
test-utils/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json [new file with mode: 0644]
test-utils/src/test/resources/testdir/testfile.xml [moved from policy-common/src/test/resources/testdir/testfile.xml with 100% similarity]

index afea522..20bc8d1 100644 (file)
                 <groupId>org.hamcrest</groupId>
                 <artifactId>hamcrest</artifactId>
                 <version>${version.hamcrest}</version>
+                <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>org.hibernate.orm</groupId>
                 <groupId>org.projectlombok</groupId>
                 <artifactId>lombok</artifactId>
                 <version>${version.lombok}</version>
+                <scope>provided</scope>
             </dependency>
             <dependency>
                 <groupId>org.slf4j</groupId>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
                     <version>${version.springboot}</version>
+                    <configuration>
+                        <excludes>
+                            <exclude>
+                                <groupId>org.projectlombok</groupId>
+                                <artifactId>lombok</artifactId>
+                            </exclude>
+                        </excludes>
+                    </configuration>
                     <executions>
                         <execution>
                             <goals>
index bc95825..42a63cf 100644 (file)
             <groupId>org.springframework</groupId>
             <artifactId>spring-tx</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.clamp</groupId>
+            <artifactId>test-utils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-api</artifactId>
index d42735c..eed41a3 100644 (file)
             <artifactId>policy-clamp-participant-intermediary</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-webflux</artifactId>
             <version>5.3.2</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.clamp</groupId>
+            <artifactId>test-utils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
index ba85c9d..8cd37bb 100644 (file)
         <dependency>
             <groupId>com.openpojo</groupId>
             <artifactId>openpojo</artifactId>
-            <scope>compile</scope>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest</artifactId>
-            <scope>compile</scope>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-api</artifactId>
-            <scope>compile</scope>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.clamp</groupId>
+            <artifactId>test-utils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.assertj</groupId>
diff --git a/policy-common/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json b/policy-common/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json
deleted file mode 100644 (file)
index 56897ba..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "id": "${obj.id}",
-    "text": "${obj.text}"
-}
index 54e4e53..f0b6c0d 100644 (file)
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.clamp</groupId>
+            <artifactId>test-utils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-api</artifactId>
diff --git a/pom.xml b/pom.xml
index 29e0bd5..821158d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -50,6 +50,7 @@
 
     <modules>
         <module>clamp-parent</module>
+        <module>test-utils</module>
         <module>policy-common</module>
         <module>policy-models</module>
         <module>common</module>
index 52d46b9..6faf16b 100644 (file)
             <artifactId>testcontainers-postgresql</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.clamp</groupId>
+            <artifactId>test-utils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/test-utils/pom.xml b/test-utils/pom.xml
new file mode 100644 (file)
index 0000000..01c4bf5
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ============LICENSE_START=======================================================
+  Copyright (C) 2026 OpenInfra Foundation Europe. All rights reserved.
+  ================================================================================
+  Licensed 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.
+
+  SPDX-License-Identifier: Apache-2.0
+  ============LICENSE_END=========================================================
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onap.policy.clamp</groupId>
+        <artifactId>dependencies</artifactId>
+        <version>9.0.2-SNAPSHOT</version>
+        <relativePath>../clamp-parent/dependencies/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>test-utils</artifactId>
+    <name>${project.artifactId}</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.openpojo</groupId>
+            <artifactId>openpojo</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.re2j</groupId>
+            <artifactId>re2j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
@@ -28,7 +28,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.NullNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.re2j.Pattern;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -44,11 +43,6 @@ import lombok.Getter;
 @Getter
 public class JacksonTestUtils {
 
-    /**
-     * Matches script items, of the form ${xxx}, within text.
-     */
-    private static final Pattern SCRIPT_PAT = Pattern.compile("\\$\\{([^}]+)\\}");
-
     /**
      * Engine used to interpolate strings before they're compared.
      */
@@ -193,25 +193,6 @@ public final class ResourceUtils {
         }
     }
 
-    /**
-     * Gets the file path for a resource on the local file system or on the class path.
-     *
-     * @param resource the resource to the get the file path for
-     * @return the resource file path
-     */
-    public static String getFilePath4Resource(final String resource) {
-        if (resource == null) {
-            return null;
-        }
-
-        var modelFileUrl = getUrl4Resource(resource);
-        if (modelFileUrl != null) {
-            return modelFileUrl.getPath();
-        } else {
-            return resource;
-        }
-    }
-
     /**
      * Read the list of entries in a resource directory.
      *
@@ -246,7 +227,7 @@ public final class ResourceUtils {
      * @param resourceDirectoryName the name of the resource directory
      * @return a set of the directory contents
      */
-    public static Set<String> getDirectoryContentsLocal(final URL localResourceDirectoryUrl,
+    private static Set<String> getDirectoryContentsLocal(final URL localResourceDirectoryUrl,
             final String resourceDirectoryName) {
         var localDirectory = new File(localResourceDirectoryUrl.getFile());
 
@@ -275,7 +256,7 @@ public final class ResourceUtils {
      * @param resourceDirectoryName the name of the resource directory
      * @return a set of the directory contents
      */
-    public static Set<String> getDirectoryContentsJar(final URL jarResourceDirectoryUrl,
+    private static Set<String> getDirectoryContentsJar(final URL jarResourceDirectoryUrl,
             final String resourceDirectoryName) {
         String dirNameWithSlash = resourceDirectoryName + "/";
         int minLength = dirNameWithSlash.length() + 1;
@@ -53,6 +53,9 @@ class JacksonTestUtilsTest {
         var data = new Data();
         data.setId(500);
         data.setText(HELLO);
+        // file is found
+        assertThatCode(() -> utils.compareJson(data, JacksonTestUtilsTest.class))
+                .doesNotThrowAnyException();
         // file not found
         var file = new File(JacksonTestUtilsTest.class.getSimpleName() + "-NotFound.json");
         assertThatThrownBy(() -> utils.compareJson(data, file))
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- *  Modifications Copyright (C) 2020-2021, 2023-2024,2026 OpenInfra Foundation Europe. All rights reserved.
+ *  Modifications Copyright (C) 2020-2026 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Set;
 import org.junit.jupiter.api.AfterEach;
@@ -245,7 +244,7 @@ class ResourceUtilsTest {
 
         theString = ResourceUtils.getResourceAsString("");
 
-        assertEquals("keystore-test\nlogback-test.xml\nMETA-INF\norg\ntestdir\nversion.txt\nwebapps\n", theString);
+        assertEquals("org\ntestdir\n", theString);
 
     }
 
@@ -286,15 +285,7 @@ class ResourceUtilsTest {
     }
 
     @Test
-    void testGetFilePath4Resource() {
-        assertNull(ResourceUtils.getFilePath4Resource(null));
-        assertEquals("/something/else", ResourceUtils.getFilePath4Resource("/something/else"));
-        assertTrue(ResourceUtils.getFilePath4Resource("xml/example.xml").endsWith("xml/example.xml"));
-        assertTrue(ResourceUtils.getFilePath4Resource("com/google").contains("com/google"));
-    }
-
-    @Test
-    void testGetDirectoryContents() throws MalformedURLException {
+    void testGetDirectoryContents() {
         assertTrue(ResourceUtils.getDirectoryContents(null).isEmpty());
         assertTrue(ResourceUtils.getDirectoryContents("idontexist").isEmpty());
         assertTrue(ResourceUtils.getDirectoryContents("logback-test.xml").isEmpty());
@@ -305,24 +296,22 @@ class ResourceUtilsTest {
 
         Set<String> resultD1 = ResourceUtils.getDirectoryContents("org/onap/policy/common/utils");
         assertFalse(resultD1.isEmpty());
-        assertEquals("org/onap/policy/common/utils/coder/", normalizePath(resultD1.iterator().next()));
+        assertEquals("org/onap/policy/common/utils/jackson/", normalizePath(resultD1.iterator().next()));
 
-        Set<String> resultD2 = ResourceUtils.getDirectoryContents("org/onap/policy/common/utils/coder");
-        assertTrue(resultD2.size() >= 15);
-        assertEquals("org/onap/policy/common/utils/coder/CoderExceptionTest.class",
+        Set<String> resultD2 = ResourceUtils.getDirectoryContents("org/onap/policy/common/utils/jackson");
+        assertEquals(4, resultD2.size());
+        assertEquals("org/onap/policy/common/utils/jackson/JacksonTestUtilsTest$1.class",
                 normalizePath(resultD2.iterator().next()));
 
         Set<String> resultJ0 = ResourceUtils.getDirectoryContents("com");
-        assertTrue(resultJ0.contains("com/fasterxml/"));
-        assertEquals("com/fasterxml/", normalizePath(resultJ0.iterator().next()));
+        assertTrue(resultJ0.contains("com/openpojo/"));
+        assertEquals("com/openpojo/", normalizePath(resultJ0.iterator().next()));
 
         Set<String> resultJ1 = ResourceUtils.getDirectoryContents("com/fasterxml/jackson/core");
         assertTrue(resultJ1.size() > 1);
         assertTrue(resultJ1.contains("com/fasterxml/jackson/core/Base64Variants.class"));
 
-        URL dummyUrl = new URL("http://even/worse");
-        assertTrue(ResourceUtils.getDirectoryContentsJar(dummyUrl, "nonexistantdirectory").isEmpty());
-
+        assertTrue(ResourceUtils.getDirectoryContents("nonexistantdirectory").isEmpty());
     }
 
     /**
diff --git a/test-utils/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json b/test-utils/src/test/resources/org/onap/policy/common/utils/jackson/JacksonTestUtilsTest.json
new file mode 100644 (file)
index 0000000..43e7537
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "id": 500,
+    "text": "hello"
+}