aboutsummaryrefslogtreecommitdiffstats
path: root/reception
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2023-08-21 14:35:56 +0100
committeradheli.tavares <adheli.tavares@est.tech>2023-09-22 16:01:50 +0100
commit08ec52b6ed5ef7159087d708bddfa40d9ac03717 (patch)
treee3272e724c86cba0b57d84d43b6acc51e2f5ab32 /reception
parentff1698142a22a4811895d2ac7047fbadbb36b396 (diff)
Upgrade Java 17
Issue-ID: POLICY-4803 Change-Id: Iad0d08ee6f8ab18eb177b458d8edbba4002bcc73 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'reception')
-rw-r--r--reception/pom.xml5
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/decoding/TestExceptions.java6
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java72
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java21
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java44
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java14
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerConfigurationParametersJsonAdapter.java46
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java44
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/statistics/TestDistributionStatisticsManager.java36
9 files changed, 140 insertions, 148 deletions
diff --git a/reception/pom.xml b/reception/pom.xml
index 935e016f..994c9858 100644
--- a/reception/pom.xml
+++ b/reception/pom.xml
@@ -18,12 +18,13 @@
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">
+<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.distribution</groupId>
<artifactId>policy-distribution</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>reception</artifactId>
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/TestExceptions.java b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/TestExceptions.java
index 2b52eb27..7b70bb5d 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/TestExceptions.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/TestExceptions.java
@@ -20,13 +20,13 @@
package org.onap.policy.distribution.reception.decoding;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class TestExceptions {
+class TestExceptions {
@Test
- public void test() {
+ void test() {
new ExceptionsTester().test(PluginInitializationException.class);
new ExceptionsTester().test(PluginTerminationException.class);
new ExceptionsTester().test(PolicyDecodingException.class);
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
index 1dc4bfe0..cde5eb79 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
@@ -21,16 +21,16 @@
package org.onap.policy.distribution.reception.handling;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
@@ -47,7 +47,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
*
* @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
*/
-public class AbstractReceptionHandlerTest {
+class AbstractReceptionHandlerTest {
private static final String DISTRIBUTION_GROUP = "DummyDistributionGroup";
private static final String DECODER_TYPE = "DummyDecoder";
@@ -61,24 +61,24 @@ public class AbstractReceptionHandlerTest {
private static final String DECODER_CONFIGURATION_PARAMETERS = "DummyDecoderConfiguration";
@Test
- public void testInputReceived() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
+ void testInputReceived() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, PluginInitializationException {
- final AbstractReceptionHandler handler = new DummyReceptionHandler();
+ final var handler = new DummyReceptionHandler();
- final ToscaEntity generatedPolicy1 = new DummyPolicy1();
- final ToscaEntity generatedPolicy2 = new DummyPolicy2();
+ final var generatedPolicy1 = new DummyPolicy1();
+ final var generatedPolicy2 = new DummyPolicy2();
- final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder1 =
+ final var policyDecoder1 =
new DummyDecoder(true, Collections.singletonList(generatedPolicy1));
- final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder2 =
+ final var policyDecoder2 =
new DummyDecoder(true, Collections.singletonList(generatedPolicy2));
final Collection<PolicyDecoder<PolicyInput, ToscaEntity>> policyDecoders = new ArrayList<>();
policyDecoders.add(policyDecoder1);
policyDecoders.add(policyDecoder2);
- final DummyPolicyForwarder policyForwarder1 = new DummyPolicyForwarder();
- final DummyPolicyForwarder policyForwarder2 = new DummyPolicyForwarder();
+ final var policyForwarder1 = new DummyPolicyForwarder();
+ final var policyForwarder2 = new DummyPolicyForwarder();
final Collection<PolicyForwarder> policyForwarders = new ArrayList<>();
policyForwarders.add(policyForwarder1);
@@ -96,27 +96,28 @@ public class AbstractReceptionHandlerTest {
assertTrue(policyForwarder2.receivedPolicy(generatedPolicy2));
}
- @Test(expected = PolicyDecodingException.class)
- public void testInputReceivedNoSupportingDecoder() throws PolicyDecodingException, NoSuchFieldException,
+ @Test
+ void testInputReceivedNoSupportingDecoder() throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException {
- final AbstractReceptionHandler handler = new DummyReceptionHandler();
+ final var handler = new DummyReceptionHandler();
- final PolicyDecoder<PolicyInput, ToscaEntity> policyDecoder = new DummyDecoder(false, Collections.emptyList());
- final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder();
+ final var policyDecoder = new DummyDecoder(false, Collections.emptyList());
+ final var policyForwarder = new DummyPolicyForwarder();
setUpPlugins(handler, Collections.singleton(policyDecoder), Collections.singleton(policyForwarder));
-
- handler.inputReceived(new DummyPolicyInput());
+ var policyInput = new DummyPolicyInput();
+ assertThrows(PolicyDecodingException.class, () -> handler.inputReceived(policyInput));
}
- @Test(expected = PolicyDecodingException.class)
- public void testInputReceivedNoDecoder() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
+ @Test
+ void testInputReceivedNoDecoder() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, PluginInitializationException {
- final AbstractReceptionHandler handler = new DummyReceptionHandler();
+ final var handler = new DummyReceptionHandler();
- final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder();
+ final var policyForwarder = new DummyPolicyForwarder();
setUpPlugins(handler, Collections.emptySet(), Collections.singleton(policyForwarder));
- handler.inputReceived(new DummyPolicyInput());
+ var policyInput = new DummyPolicyInput();
+ assertThrows(PolicyDecodingException.class, () -> handler.inputReceived(policyInput));
}
static class DummyPolicyInput implements PolicyInput {
@@ -142,20 +143,20 @@ public class AbstractReceptionHandlerTest {
final Collection<PolicyDecoder<PolicyInput, ToscaEntity>> decoders,
final Collection<PolicyForwarder> forwarders) throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, PluginInitializationException {
- final PluginHandlerParameters pluginParameters = getPluginHandlerParameters();
+ final var pluginParameters = getPluginHandlerParameters();
pluginParameters.setName(DISTRIBUTION_GROUP);
ParameterService.register(pluginParameters);
- final PluginHandler pluginHandler = new PluginHandler(pluginParameters.getName());
+ final var pluginHandler = new PluginHandler(pluginParameters.getName());
- final Field decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders");
+ final var decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders");
decodersField.setAccessible(true);
decodersField.set(pluginHandler, decoders);
- final Field forwardersField = pluginHandler.getClass().getDeclaredField("policyForwarders");
+ final var forwardersField = pluginHandler.getClass().getDeclaredField("policyForwarders");
forwardersField.setAccessible(true);
forwardersField.set(pluginHandler, forwarders);
- final Field pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler");
+ final var pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler");
pluginHandlerField.setAccessible(true);
pluginHandlerField.set(receptionHandler, pluginHandler);
ParameterService.deregister(pluginParameters.getName());
@@ -163,24 +164,23 @@ public class AbstractReceptionHandlerTest {
private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>();
- final PolicyDecoderParameters pDParameters =
+ final var pDParameters =
new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME, DECODER_CONFIGURATION_PARAMETERS);
policyDecoders.put(DECODER_KEY, pDParameters);
return policyDecoders;
}
private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
- final Map<String, PolicyForwarderParameters> policyForwarders =
- new HashMap<>();
- final PolicyForwarderParameters pFParameters =
+ final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>();
+ final var pFParameters =
new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
policyForwarders.put(FORWARDER_KEY, pFParameters);
return policyForwarders;
}
private PluginHandlerParameters getPluginHandlerParameters() {
- final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders();
- final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders();
+ final var policyDecoders = getPolicyDecoders();
+ final var policyForwarders = getPolicyForwarders();
return new PluginHandlerParameters(policyDecoders, policyForwarders);
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java
index 9a0ac316..68dc6b56 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java
@@ -25,8 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ValidationResult;
+import org.junit.jupiter.api.Test;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
/**
@@ -35,29 +34,29 @@ import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParamet
* @author Adheli Tavares (adheli.tavares@est.tech)
*
*/
-public class TestPluginHandlerParameters {
+class TestPluginHandlerParameters {
@Test
- public void testValidate_PolicyDecodersEmpty() {
- PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(new HashMap<>(), getPolicyForwarders());
+ void testValidate_PolicyDecodersEmpty() {
+ var emptyDecoder = new PluginHandlerParameters(new HashMap<>(), getPolicyForwarders());
- ValidationResult result = emptyDecoder.validate();
+ var result = emptyDecoder.validate();
assertThat(result.getResult()).contains("\"policyDecoders\"", "minimum").doesNotContain("\"policyForwarders\"");
}
@Test
- public void testValidate_PolicyForwardersNullEmpty() {
- PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(getPolicyDecoders(), new HashMap<>());
+ void testValidate_PolicyForwardersNullEmpty() {
+ var emptyDecoder = new PluginHandlerParameters(getPolicyDecoders(), new HashMap<>());
- ValidationResult result = emptyDecoder.validate();
+ var result = emptyDecoder.validate();
assertThat(result.getResult()).contains("\"policyForwarders\"", "minimum").doesNotContain("\"policyDecoders\"");
}
private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>();
- final PolicyDecoderParameters pDParameters =
+ final var pDParameters =
new PolicyDecoderParameters("DummyDecoder", getClass().getName(), "dummyDecoderConfiguration");
policyDecoders.put("DummyDecoder", pDParameters);
@@ -66,7 +65,7 @@ public class TestPluginHandlerParameters {
private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>();
- final PolicyForwarderParameters pFParameters =
+ final var pFParameters =
new PolicyForwarderParameters("DummyForwarder", getClass().getName(), "dummyForwarderConfiguration");
policyForwarders.put("DummyForwarder", pFParameters);
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java
index 127f1223..d3a0e3d4 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java
@@ -21,19 +21,16 @@
package org.onap.policy.distribution.reception.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.distribution.reception.testclasses.DummyPolicyDecoderParameterGroup;
/**
@@ -45,49 +42,48 @@ import org.onap.policy.distribution.reception.testclasses.DummyPolicyDecoderPara
public class TestPolicyDecoderConfigurationParametersJsonAdapter {
@Test
- public void testDeserialize() throws JsonSyntaxException, IOException {
- final String validJsonFile = "src/test/resources/PolicyDecoderConfiguration.json";
- final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile));
+ void testDeserialize() throws JsonSyntaxException, IOException {
+ final var validJsonFile = "src/test/resources/PolicyDecoderConfiguration.json";
+ final var mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile));
- Gson gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class,
+ var gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class,
new PolicyDecoderConfigurationParametersJsonAdapter()).create();
- PolicyDecoderConfigurationParameterGroup result =
- gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class);
+ var result = gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class);
assertNotNull(result);
assertEquals(result.getClass(), DummyPolicyDecoderParameterGroup.class);
}
@Test
- public void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/EmptyClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file";
+ void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/EmptyClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file";
validateParsing(jsonFile, expectedErrorMsg);
}
@Test
- public void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/NullClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file";
+ void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/NullClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file";
validateParsing(jsonFile, expectedErrorMsg);
}
@Test
- public void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/WrongClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value "
+ void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/WrongClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value "
+ "\"org.onap.policy.distribution.reception.testclasses.NotExistentClass\", could not find class";
validateParsing(jsonFile, expectedErrorMsg);
}
private void validateParsing(final String jsonFile, String expectedErrorMsg) throws IOException {
- final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile));
+ final var mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile));
- Gson gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class,
+ var gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class,
new PolicyDecoderConfigurationParametersJsonAdapter()).create();
assertThatThrownBy(() -> gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class))
@@ -95,7 +91,7 @@ public class TestPolicyDecoderConfigurationParametersJsonAdapter {
}
private String getJsonValues(String path) throws IOException {
- return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8);
+ return Files.readString(new File(path).toPath());
}
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java
index dae91abf..d18c64d9 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java
@@ -23,7 +23,7 @@ package org.onap.policy.distribution.reception.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.distribution.reception.handling.DummyDecoder;
/**
@@ -32,15 +32,15 @@ import org.onap.policy.distribution.reception.handling.DummyDecoder;
* @author Adheli Tavares (adheli.tavares@est.tech)
*
*/
-public class TestPolicyDecoderParameters {
+class TestPolicyDecoderParameters {
static final String DECODER_CLASS_NAME = DummyDecoder.class.getName();
static final String DECODER_CONFIG = "decoderConfigName";
static final String DECODER_TYPE = "DummyDecoder";
@Test
- public void testValidate_DecoderTypeEmptyNull() {
- PolicyDecoderParameters sutParams = new PolicyDecoderParameters(null, DECODER_CLASS_NAME, DECODER_CONFIG);
+ void testValidate_DecoderTypeEmptyNull() {
+ var sutParams = new PolicyDecoderParameters(null, DECODER_CLASS_NAME, DECODER_CONFIG);
assertThat(sutParams.validate().getResult()).contains("\"decoderType\" value \"null\" INVALID, is null");
@@ -51,13 +51,13 @@ public class TestPolicyDecoderParameters {
}
@Test
- public void testValidate_ClassNameEmptyNull() {
- PolicyDecoderParameters nullClassName = new PolicyDecoderParameters(DECODER_TYPE, null, DECODER_CONFIG);
+ void testValidate_ClassNameEmptyNull() {
+ var nullClassName = new PolicyDecoderParameters(DECODER_TYPE, null, DECODER_CONFIG);
assertThat(nullClassName.validate().getResult())
.contains("\"decoderClassName\" value \"null\" INVALID, is null");
- PolicyDecoderParameters emptyClassName = new PolicyDecoderParameters(DECODER_TYPE, "", DECODER_CONFIG);
+ var emptyClassName = new PolicyDecoderParameters(DECODER_TYPE, "", DECODER_CONFIG);
assertThat(emptyClassName.validate().getResult()).contains("\"decoderClassName\" value \"\" INVALID, is blank");
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerConfigurationParametersJsonAdapter.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerConfigurationParametersJsonAdapter.java
index ae85e0dc..40e29f64 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerConfigurationParametersJsonAdapter.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerConfigurationParametersJsonAdapter.java
@@ -21,19 +21,16 @@
package org.onap.policy.distribution.reception.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.distribution.reception.testclasses.DummyReceptionHandlerParameterGroup;
/**
@@ -42,17 +39,17 @@ import org.onap.policy.distribution.reception.testclasses.DummyReceptionHandlerP
* @author Adheli Tavares (adheli.tavares@est.tech)
*
*/
-public class TestReceptionHandlerConfigurationParametersJsonAdapter {
+class TestReceptionHandlerConfigurationParametersJsonAdapter {
@Test
- public void testDeserialize() throws JsonSyntaxException, IOException {
- final String validJsonFile = "src/test/resources/ReceptionHandlerConfiguration.json";
- final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile));
+ void testDeserialize() throws JsonSyntaxException, IOException {
+ final var validJsonFile = "src/test/resources/ReceptionHandlerConfiguration.json";
+ final var mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile));
- Gson gson = new GsonBuilder().registerTypeAdapter(ReceptionHandlerConfigurationParameterGroup.class,
+ var gson = new GsonBuilder().registerTypeAdapter(ReceptionHandlerConfigurationParameterGroup.class,
new ReceptionHandlerConfigurationParametersJsonAdapter()).create();
- ReceptionHandlerConfigurationParameterGroup result =
+ var result =
gson.fromJson(mockJsonElement, ReceptionHandlerConfigurationParameterGroup.class);
assertNotNull(result);
@@ -60,34 +57,34 @@ public class TestReceptionHandlerConfigurationParametersJsonAdapter {
}
@Test
- public void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/EmptyClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file";
+ void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/EmptyClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file";
validateParsing(jsonFile, expectedErrorMsg);
}
@Test
- public void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/NullClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file";
+ void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/NullClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file";
validateParsing(jsonFile, expectedErrorMsg);
}
@Test
- public void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException {
- final String jsonFile = "src/test/resources/WrongClassName.json";
- String expectedErrorMsg = "parameter \"parameterClassName\" value "
+ void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException {
+ final var jsonFile = "src/test/resources/WrongClassName.json";
+ var expectedErrorMsg = "parameter \"parameterClassName\" value "
+ "\"org.onap.policy.distribution.reception.testclasses.NotExistentClass\", could not find class";
validateParsing(jsonFile, expectedErrorMsg);
}
private void validateParsing(final String jsonFile, String expectedErrorMsg) throws IOException {
- final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile));
+ final var mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile));
- Gson gson = new GsonBuilder().registerTypeAdapter(ReceptionHandlerConfigurationParameterGroup.class,
+ var gson = new GsonBuilder().registerTypeAdapter(ReceptionHandlerConfigurationParameterGroup.class,
new ReceptionHandlerConfigurationParametersJsonAdapter()).create();
assertThatThrownBy(() -> gson.fromJson(mockJsonElement, ReceptionHandlerConfigurationParameterGroup.class))
@@ -95,7 +92,6 @@ public class TestReceptionHandlerConfigurationParametersJsonAdapter {
}
private String getJsonValues(String path) throws IOException {
- return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8);
+ return Files.readString(new File(path).toPath());
}
-
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java
index b12af003..1cfd65d6 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java
@@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
import org.onap.policy.distribution.reception.handling.DummyDecoder;
@@ -35,47 +35,47 @@ import org.onap.policy.distribution.reception.handling.DummyDecoder;
* @author Adheli Tavares (adheli.tavares@est.tech)
*
*/
-public class TestReceptionHandlerParameters {
+class TestReceptionHandlerParameters {
@Test
- public void testValidate_ClassNotFound() {
- final String className = "org.onap.policy.distribution.reception.testclasses.NotExistent";
+ void testValidate_ClassNotFound() {
+ final var className = "org.onap.policy.distribution.reception.testclasses.NotExistent";
- ReceptionHandlerParameters sutParams = getReceptionHandlerParameters(className);
+ var sutParams = getReceptionHandlerParameters(className);
sutParams.setName(className);
assertThat(sutParams.validate().getResult()).contains("class is not in the classpath");
}
@Test
- public void testValidate_ReceptionHandlerTypeNullEmpty() {
- final String className = DummyDecoder.class.getName();
- final PluginHandlerParameters pHParameters =
+ void testValidate_ReceptionHandlerTypeNullEmpty() {
+ final var className = DummyDecoder.class.getName();
+ final var pHParameters =
new PluginHandlerParameters(getPolicyDecoders(), getPolicyForwarders());
- ReceptionHandlerParameters nullType = new ReceptionHandlerParameters(null, className, className, pHParameters);
+ var nullType = new ReceptionHandlerParameters(null, className, className, pHParameters);
assertThat(nullType.validate().getResult())
.contains("\"receptionHandlerType\" value \"null\" INVALID, is null");
- ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("", className, className, pHParameters);
+ var emptyType = new ReceptionHandlerParameters("", className, className, pHParameters);
assertThat(emptyType.validate().getResult()).contains("\"receptionHandlerType\" value \"\" INVALID, is blank")
.doesNotContain("classpath");
}
@Test
- public void testValidate_ReceptionHandlerClassNameNullEmpty() {
+ void testValidate_ReceptionHandlerClassNameNullEmpty() {
final PluginHandlerParameters pHParameters =
new PluginHandlerParameters(getPolicyDecoders(), getPolicyForwarders());
- ReceptionHandlerParameters nullType = new ReceptionHandlerParameters("DummyReceptionHandler", null,
+ var nullType = new ReceptionHandlerParameters("DummyReceptionHandler", null,
"dummyReceptionHandlerConfiguration", pHParameters);
assertThat(nullType.validate().getResult())
.contains("\"receptionHandlerClassName\" value \"null\" INVALID, is null");
- ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("DummyReceptionHandler", "",
+ var emptyType = new ReceptionHandlerParameters("DummyReceptionHandler", "",
"dummyReceptionHandlerConfiguration", pHParameters);
assertThat(emptyType.validate().getResult())
@@ -83,10 +83,10 @@ public class TestReceptionHandlerParameters {
}
@Test
- public void testValidate_PluginHandlerParametersNull() {
- final String className = "org.onap.policy.distribution.reception.testclasses.DummyReceptionHandler";
+ void testValidate_PluginHandlerParametersNull() {
+ final var className = "org.onap.policy.distribution.reception.testclasses.DummyReceptionHandler";
- ReceptionHandlerParameters sutParams = new ReceptionHandlerParameters("DummyReceptionHandler", className,
+ var sutParams = new ReceptionHandlerParameters("DummyReceptionHandler", className,
"dummyReceptionHandlerConfiguration", null);
assertThat(sutParams.validate().getResult())
@@ -94,10 +94,10 @@ public class TestReceptionHandlerParameters {
}
private ReceptionHandlerParameters getReceptionHandlerParameters(String className) {
- final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders();
- final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders();
- final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
- final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters("DummyReceptionHandler",
+ final var policyDecoders = getPolicyDecoders();
+ final var policyForwarders = getPolicyForwarders();
+ final var pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders);
+ final var rhParameters = new ReceptionHandlerParameters("DummyReceptionHandler",
className, "dummyReceptionHandlerConfiguration", pHParameters);
return rhParameters;
}
@@ -105,7 +105,7 @@ public class TestReceptionHandlerParameters {
private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>();
- final PolicyDecoderParameters pDParameters =
+ final var pDParameters =
new PolicyDecoderParameters("DummyDecoder", DummyDecoder.class.getName(), "dummyDecoderConfiguration");
policyDecoders.put("DummyDecoder", pDParameters);
@@ -115,7 +115,7 @@ public class TestReceptionHandlerParameters {
private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>();
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("DummyForwarder",
+ final var pFParameters = new PolicyForwarderParameters("DummyForwarder",
DummyDecoder.class.getName(), "dummyForwarderConfiguration");
policyForwarders.put("DummyForwarder", pFParameters);
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/statistics/TestDistributionStatisticsManager.java b/reception/src/test/java/org/onap/policy/distribution/reception/statistics/TestDistributionStatisticsManager.java
index 3c14da33..c3ea7bbc 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/statistics/TestDistributionStatisticsManager.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/statistics/TestDistributionStatisticsManager.java
@@ -20,87 +20,87 @@
package org.onap.policy.distribution.reception.statistics;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Class to perform unit test of DistributionStatisticsManager.
*
* @author Adheli Tavares (adheli.tavares@est.tech)
* */
-public class TestDistributionStatisticsManager {
+class TestDistributionStatisticsManager {
- @Before
- public void reset() {
+ @BeforeEach
+ void reset() {
DistributionStatisticsManager.resetAllStatistics();
}
@Test
- public void testUpdateTotalDistributionCount() {
+ void testUpdateTotalDistributionCount() {
DistributionStatisticsManager.updateTotalDistributionCount();
assertEquals(1L, DistributionStatisticsManager.getTotalDistributionCount());
}
@Test
- public void testUpdateDistributionSuccessCount() {
+ void testUpdateDistributionSuccessCount() {
DistributionStatisticsManager.updateDistributionSuccessCount();
assertEquals(1L, DistributionStatisticsManager.getDistributionSuccessCount());
}
@Test
- public void testUpdateDistributionFailureCount() {
+ void testUpdateDistributionFailureCount() {
DistributionStatisticsManager.updateDistributionFailureCount();
assertEquals(1L, DistributionStatisticsManager.getDistributionFailureCount());
}
@Test
- public void testUpdateTotalDownloadCount() {
+ void testUpdateTotalDownloadCount() {
DistributionStatisticsManager.updateTotalDownloadCount();
assertEquals(1L, DistributionStatisticsManager.getTotalDownloadCount());
}
@Test
- public void testUpdateDownloadSuccessCount() {
+ void testUpdateDownloadSuccessCount() {
DistributionStatisticsManager.updateDownloadSuccessCount();
assertEquals(1L, DistributionStatisticsManager.getDownloadSuccessCount());
}
@Test
- public void testUpdateDownloadFailureCount() {
+ void testUpdateDownloadFailureCount() {
DistributionStatisticsManager.updateDownloadFailureCount();
assertEquals(1L, DistributionStatisticsManager.getDownloadFailureCount());
}
@Test
- public void testGetTotalDistributionCount() {
+ void testGetTotalDistributionCount() {
assertEquals(0L, DistributionStatisticsManager.getTotalDistributionCount());
}
@Test
- public void testGetDistributionSuccessCount() {
+ void testGetDistributionSuccessCount() {
assertEquals(0L, DistributionStatisticsManager.getDistributionSuccessCount());
}
@Test
- public void testGetDistributionFailureCount() {
+ void testGetDistributionFailureCount() {
assertEquals(0L, DistributionStatisticsManager.getDistributionFailureCount());
}
@Test
- public void testGetTotalDownloadCount() {
+ void testGetTotalDownloadCount() {
assertEquals(0L, DistributionStatisticsManager.getTotalDownloadCount());
}
@Test
- public void testGetDownloadSuccessCount() {
+ void testGetDownloadSuccessCount() {
assertEquals(0L, DistributionStatisticsManager.getDownloadSuccessCount());
}
@Test
- public void testGetDownloadFailureCount() {
+ void testGetDownloadFailureCount() {
assertEquals(0L, DistributionStatisticsManager.getDownloadFailureCount());
}
}