<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>
<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>
<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>
<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>
+++ /dev/null
-{
- "id": "${obj.id}",
- "text": "${obj.text}"
-}
<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>
<modules>
<module>clamp-parent</module>
+ <module>test-utils</module>
<module>policy-common</module>
<module>policy-models</module>
<module>common</module>
<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>
--- /dev/null
+<?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>
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;
@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.
*/
}
}
- /**
- * 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.
*
* @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());
* @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;
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))
* ============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.
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;
theString = ResourceUtils.getResourceAsString("");
- assertEquals("keystore-test\nlogback-test.xml\nMETA-INF\norg\ntestdir\nversion.txt\nwebapps\n", theString);
+ assertEquals("org\ntestdir\n", theString);
}
}
@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());
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());
}
/**
--- /dev/null
+{
+ "id": 500,
+ "text": "hello"
+}