aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/test
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-09-23 15:13:36 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-11-01 10:36:08 +0000
commitac4b5296ab01fc25d89cc4fc89b6407fb7254f1b (patch)
tree4fd2fe6f3b611dbdba48d6f4947bfb716eb08dc5 /utils/src/test
parentf8ff4184fe5cc5d5a84c266d50e63c289729ef2f (diff)
Moving message bus configurations to its own moduleHEADmaster
Issue-ID: POLICY-5131 Change-Id: Ibbcdc487300767e7b10d69e9b388c50f09e1adbc Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'utils/src/test')
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/properties/PropertyUtilsTest.java110
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/report/TestHealthCheckReport.java78
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java2
3 files changed, 189 insertions, 1 deletions
diff --git a/utils/src/test/java/org/onap/policy/common/utils/properties/PropertyUtilsTest.java b/utils/src/test/java/org/onap/policy/common/utils/properties/PropertyUtilsTest.java
new file mode 100644
index 00000000..a8b37f57
--- /dev/null
+++ b/utils/src/test/java/org/onap/policy/common/utils/properties/PropertyUtilsTest.java
@@ -0,0 +1,110 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.utils.properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Properties;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class PropertyUtilsTest {
+ private static final String DFLT_STRING = "my-default";
+ private static final int DLFT_INT = 1000;
+
+ private PropertyUtils utils;
+ private String invalidName;
+ private String invalidValue;
+ private Exception invalidEx;
+
+ /**
+ * Initializes {@link #utils}.
+ */
+ @BeforeEach
+ public void setUp() {
+ Properties properties = new Properties();
+ properties.put("myPrefix.my-string", "some text");
+ properties.put("myPrefix.empty-string", "");
+
+ properties.put("myPrefix.my-bool", "true");
+ properties.put("myPrefix.my-bool2", "false");
+ properties.put("myPrefix.empty-bool", "");
+ properties.put("myPrefix.invalid-bool", "not a bool");
+
+ properties.put("myPrefix.my-int", "100");
+ properties.put("myPrefix.my-int2", "200");
+ properties.put("myPrefix.empty-int", "");
+ properties.put("myPrefix.invalid-int", "not an int");
+
+ utils = new PropertyUtils(properties, "myPrefix", (name, value, ex) -> {
+ invalidName = name;
+ invalidValue = value;
+ invalidEx = ex;
+ });
+ }
+
+ @Test
+ void testGetString() {
+ assertEquals("some text", utils.getString(".my-string", DFLT_STRING));
+ assertEquals(DFLT_STRING, utils.getString(".empty-string", DFLT_STRING));
+ assertEquals(DFLT_STRING, utils.getString(".missing-string", DFLT_STRING));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+ }
+
+ @Test
+ void testGetBoolean() {
+ assertTrue(utils.getBoolean(".my-bool", false));
+ assertFalse(utils.getBoolean(".my-bool2", true));
+ assertTrue(utils.getBoolean(".empty-bool", true));
+ assertFalse(utils.getBoolean(".invalid-bool", true));
+ assertTrue(utils.getBoolean(".missing-bool", true));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+ }
+
+ @Test
+ void testGetInteger() {
+ assertEquals(100, utils.getInteger(".my-int", DLFT_INT));
+ assertEquals(200, utils.getInteger(".my-int2", DLFT_INT));
+ assertEquals(DLFT_INT, utils.getInteger(".empty-int", DLFT_INT));
+ assertEquals(DLFT_INT, utils.getInteger(".missing-int", DLFT_INT));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+
+ assertEquals(DLFT_INT, utils.getInteger(".invalid-int", DLFT_INT));
+
+ assertEquals("myPrefix.invalid-int", invalidName);
+ assertEquals("not an int", invalidValue);
+ assertTrue(invalidEx instanceof NumberFormatException);
+ }
+
+}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/report/TestHealthCheckReport.java b/utils/src/test/java/org/onap/policy/common/utils/report/TestHealthCheckReport.java
new file mode 100644
index 00000000..3a207022
--- /dev/null
+++ b/utils/src/test/java/org/onap/policy/common/utils/report/TestHealthCheckReport.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.policy.common.utils.report;
+
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.anything;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.filters.FilterClassName;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.affirm.Affirm;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.Tester;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+import com.openpojo.validation.utils.ValidationHelper;
+import org.hamcrest.Matcher;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Class to perform unit test of HealthCheckReport.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+class TestHealthCheckReport {
+
+ @Test
+ void testHealthCheckReport() {
+ final Validator validator =
+ ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new GetterTester()).with(new SetterTester()).with(new ToStringTester()).build();
+ validator.validate(HealthCheckReport.class.getPackage().getName(),
+ new FilterClassName(HealthCheckReport.class.getName()));
+ }
+
+ static class ToStringTester implements Tester {
+
+ private final Matcher<?> matcher;
+
+ public ToStringTester() {
+ matcher = anything();
+ }
+
+ @Override
+ public void run(final PojoClass pojoClass) {
+ final Class<?> clazz = pojoClass.getClazz();
+ if (anyOf(matcher).matches(clazz)) {
+ final Object classInstance = ValidationHelper.getBasicInstance(pojoClass);
+
+ Affirm.affirmFalse("Found default toString output",
+ classInstance.toString().matches(Object.class.getName() + "@" + "\\w+"));
+ }
+
+ }
+ }
+}
diff --git a/utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java b/utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java
index d1e891ca..9db367cf 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/resources/ResourceUtilsTest.java
@@ -313,7 +313,7 @@ class ResourceUtilsTest {
normalizePath(resultD2.iterator().next()));
Set<String> resultJ0 = ResourceUtils.getDirectoryContents("com");
- assertTrue(resultJ0.contains("com/google/gson/"));
+ assertTrue(resultJ0.contains("com/google/"));
assertEquals("com/google/", normalizePath(resultJ0.iterator().next()));
Set<String> resultJ1 = ResourceUtils.getDirectoryContents("com/google/gson");