aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-onappf
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-onappf')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java35
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java6
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java22
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java18
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java37
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java12
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java9
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java39
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java41
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java59
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java8
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java3
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java59
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java46
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java32
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java6
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java10
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java10
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java58
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java37
20 files changed, 265 insertions, 282 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index 2030b3b65..49bde831f 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -74,7 +74,7 @@ public class ApexEngineHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ApexEngineHandler.class);
- private Map<ToscaConceptIdentifier, ApexMain> apexMainMap = new LinkedHashMap<>();
+ private final Map<ToscaConceptIdentifier, ApexMain> apexMainMap = new LinkedHashMap<>();
/**
* Constructs the object. Extracts the config and model files from each policy and instantiates the apex engine.
@@ -95,12 +95,13 @@ public class ApexEngineHandler {
* @param polsToUndeploy list of policies to undeploy which will be modified to remove policies not running
* @throws ApexStarterException if the apex engine instantiation failed using the policies passed
*/
- public void updateApexEngine(List<ToscaPolicy> polsToDeploy, List<ToscaConceptIdentifier> polsToUndeploy)
+ public void updateApexEngine(final List<ToscaPolicy> polsToDeploy,
+ final List<ToscaConceptIdentifier> polsToUndeploy)
throws ApexStarterException {
Set<ToscaConceptIdentifier> runningPolicies = new HashSet<>(getRunningPolicies());
- List<ToscaPolicy> policiesToDeploy = polsToDeploy;
+ List<ToscaPolicy> policiesToDeploy = new ArrayList<>(polsToDeploy);
policiesToDeploy.removeIf(p -> runningPolicies.contains(p.getIdentifier()));
- List<ToscaConceptIdentifier> policiesToUnDeploy = polsToUndeploy;
+ List<ToscaConceptIdentifier> policiesToUnDeploy = new ArrayList<>(polsToUndeploy);
policiesToUnDeploy.removeIf(p -> !runningPolicies.contains(p));
Map<ToscaConceptIdentifier, ApexMain> undeployedPoliciesMainMap = new LinkedHashMap<>();
policiesToUnDeploy.forEach(policyId -> {
@@ -179,19 +180,19 @@ public class ApexEngineHandler {
List<String> schemaParamKeysToRetain, ApexMain main) {
ApexParameters existingParameters = ParameterService.get(ApexParameterConstants.MAIN_GROUP_NAME);
List<String> eventInputParamKeysToRemove = main.getApexParameters().getEventInputParameters().keySet().stream()
- .filter(key -> !inputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !inputParamKeysToRetain.contains(key)).toList();
List<String> eventOutputParamKeysToRemove = main.getApexParameters().getEventOutputParameters().keySet()
- .stream().filter(key -> !outputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .stream().filter(key -> !outputParamKeysToRetain.contains(key)).toList();
eventInputParamKeysToRemove.forEach(existingParameters.getEventInputParameters()::remove);
eventOutputParamKeysToRemove.forEach(existingParameters.getEventOutputParameters()::remove);
var engineParameters = main.getApexParameters().getEngineServiceParameters().getEngineParameters();
final List<TaskParameters> taskParametersToRemove = engineParameters.getTaskParameters().stream()
- .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).collect(Collectors.toList());
+ .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).toList();
final List<String> executorParamKeysToRemove = engineParameters.getExecutorParameterMap().keySet().stream()
- .filter(key -> !executorParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !executorParamKeysToRetain.contains(key)).toList();
final List<String> schemaParamKeysToRemove =
engineParameters.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap().keySet()
- .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).toList();
var aggregatedEngineParameters = existingParameters.getEngineServiceParameters().getEngineParameters();
aggregatedEngineParameters.getTaskParameters().removeAll(taskParametersToRemove);
executorParamKeysToRemove.forEach(aggregatedEngineParameters.getExecutorParameterMap()::remove);
@@ -205,17 +206,17 @@ public class ApexEngineHandler {
Map<AxArtifactKey, AxPolicy> policyMapToRetain, ApexMain main) {
final AxPolicyModel policyModel = main.getActivator().getPolicyModel();
final List<AxArtifactKey> keyInfoKeystoRemove = policyModel.getKeyInformation().getKeyInfoMap().keySet()
- .stream().filter(key -> !keyInfoMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .stream().filter(key -> !keyInfoMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> schemaKeystoRemove = policyModel.getSchemas().getSchemasMap().keySet().stream()
- .filter(key -> !schemaMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !schemaMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> eventKeystoRemove = policyModel.getEvents().getEventMap().keySet().stream()
- .filter(key -> !eventMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !eventMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> albumKeystoRemove = policyModel.getAlbums().getAlbumsMap().keySet().stream()
- .filter(key -> !albumMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !albumMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> taskKeystoRemove = policyModel.getTasks().getTaskMap().keySet().stream()
- .filter(key -> !taskMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !taskMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> policyKeystoRemove = policyModel.getPolicies().getPolicyMap().keySet().stream()
- .filter(key -> !policyMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !policyMapToRetain.containsKey(key)).toList();
final Map<AxArtifactKey, AxKeyInfo> keyInfoMap = ModelService.getModel(AxKeyInformation.class).getKeyInfoMap();
final Map<AxArtifactKey, AxContextSchema> schemasMap =
@@ -274,7 +275,7 @@ public class ApexEngineHandler {
ModelService.clear();
ParameterService.clear();
throw new ApexStarterException("Apex Engine failed to start.");
- } else if (failedPoliciesMainMap.size() > 0) {
+ } else if (!failedPoliciesMainMap.isEmpty()) {
updateModelAndParameterServices(failedPoliciesMainMap);
if (failedPoliciesMainMap.size() == policies.size()) {
throw new ApexStarterException("Updating the APEX engine with new policies failed.");
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
index 328bb3003..d3f428174 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2023 Bell Canada. All rights reserved.
* ================================================================================
@@ -122,8 +122,8 @@ public class PdpMessageHandler {
*
* @return PdpResponseDetails
*/
- public PdpResponseDetails createPdpResonseDetails(final String requestId, final PdpResponseStatus status,
- final String responseMessage) {
+ public PdpResponseDetails createPdpResponseDetails(final String requestId, final PdpResponseStatus status,
+ final String responseMessage) {
final var pdpResponseDetails = new PdpResponseDetails();
pdpResponseDetails.setResponseTo(requestId);
pdpResponseDetails.setResponseStatus(status);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
index af3e93b6a..4d3de3293 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -93,13 +93,13 @@ public class PdpStateChangeMessageHandler {
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already in active state");
} else {
final List<ToscaPolicy> policies = Registry.get(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST);
if (policies.isEmpty()) {
pdpStatusContext.setState(PdpState.ACTIVE);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "State changed to active. No policies found.");
} else {
pdpResponseDetails = startApexEngine(pdpStateChangeMsg, pdpStatusContext, pdpMessageHandler, policies);
@@ -130,7 +130,7 @@ public class PdpStateChangeMessageHandler {
if (new HashSet<>(runningPolicies)
.equals(new HashSet<>(pdpMessageHandler.getToscaPolicyIdentifiers(policies)))) {
pdpResponseDetails =
- pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex engine started. State changed to active.");
} else {
var message = new StringBuilder(
@@ -139,18 +139,18 @@ public class PdpStateChangeMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
message.append(". Other policies failed execution. Please see the logs for more details.");
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(
pdpStateChangeMsg.getRequestId(), PdpResponseStatus.SUCCESS, message.toString());
}
pdpStatusContext.setState(PdpState.ACTIVE);
updateDeploymentCounts(runningPolicies, policies);
} else {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start. State cannot be changed to active.");
}
} catch (final ApexStarterException e) {
LOGGER.error("Pdp State Change failed.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
return pdpResponseDetails;
@@ -168,7 +168,7 @@ public class PdpStateChangeMessageHandler {
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (pdpStatusContext.getState().equals(PdpState.PASSIVE)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already in passive state");
} else {
ApexEngineHandler apexEngineHandler = null;
@@ -181,12 +181,12 @@ public class PdpStateChangeMessageHandler {
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
apexEngineHandler.shutdown();
}
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex pdp state changed from Active to Passive.");
pdpStatusContext.setState(PdpState.PASSIVE);
} catch (final Exception e) {
LOGGER.error("Stopping apex engine failed. State cannot be changed to Passive.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL,
"Stopping apex engine failed. State cannot be changed to Passive." + e.getMessage());
}
@@ -206,7 +206,7 @@ public class PdpStateChangeMessageHandler {
return;
}
var policiesToDeploy = policies.stream()
- .map(ToscaWithTypeAndObjectProperties::getIdentifier).collect(Collectors.toList());
+ .map(ToscaWithTypeAndObjectProperties::getIdentifier).toList();
var policiesSuccessfullyDeployed = new ArrayList<>(policiesToDeploy);
policiesSuccessfullyDeployed.retainAll(runningPolicies);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index b8e361e1e..f6567f06e 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -66,7 +66,7 @@ public class PdpUpdateMessageHandler {
if (pdpUpdateMsg.appliesTo(pdpStatusContext.getName(), pdpStatusContext.getPdpGroup(),
pdpStatusContext.getPdpSubgroup())) {
if (checkIfAlreadyHandled(pdpUpdateMsg, pdpStatusContext)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already updated");
} else {
pdpResponseDetails = handlePdpUpdate(pdpUpdateMsg, pdpMessageHandler, pdpStatusContext);
@@ -128,7 +128,7 @@ public class PdpUpdateMessageHandler {
}
}
if (null == pdpResponseDetails) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful.");
}
return pdpResponseDetails;
@@ -170,11 +170,11 @@ public class PdpUpdateMessageHandler {
try {
apexEngineHandler.shutdown();
runningPolicies = apexEngineHandler.getRunningPolicies();
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful. No policies are running.");
} catch (final ApexStarterException e) {
LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
}
updateDeploymentCounts(runningPolicies, pdpUpdateMsg);
@@ -200,12 +200,12 @@ public class PdpUpdateMessageHandler {
populateResponseForEngineInitiation(pdpUpdateMsg, pdpMessageHandler, apexEngineHandler);
runningPolicies = apexEngineHandler.getRunningPolicies();
} else {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start.");
}
} catch (final ApexStarterException e) {
LOGGER.error("Apex engine service running failed. ", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
updateDeploymentCounts(runningPolicies, pdpUpdateMsg);
@@ -234,7 +234,7 @@ public class PdpUpdateMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
}
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, message.toString());
} else {
var message =
@@ -243,7 +243,7 @@ public class PdpUpdateMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
message.append(". Other policies failed execution. Please see the logs for more details.");
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, message.toString());
}
return pdpResponseDetails;
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
index 77ffa5317..793549b14 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
@@ -1,8 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. 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.
@@ -23,15 +22,15 @@
package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
@@ -44,7 +43,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterActivator {
+class TestApexStarterActivator {
private ApexStarterActivator activator;
@@ -53,12 +52,12 @@ public class TestApexStarterActivator {
*
* @throws Exception if an error occurs
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
final ApexStarterCommandLineArguments arguments =
- new ApexStarterCommandLineArguments(apexStarterConfigParameters);
+ new ApexStarterCommandLineArguments(apexStarterConfigParameters);
final ApexStarterParameterGroup parGroup = new ApexStarterParameterHandler().getParameters(arguments);
activator = new ApexStarterActivator(parGroup);
}
@@ -68,15 +67,15 @@ public class TestApexStarterActivator {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
if (activator != null && activator.isAlive()) {
activator.terminate();
}
}
@Test
- public void testApexStarterActivator() throws ApexStarterException {
+ void testApexStarterActivator() throws ApexStarterException {
assertFalse(activator.isAlive());
activator.initialize();
assertTrue(activator.isAlive());
@@ -93,7 +92,7 @@ public class TestApexStarterActivator {
}
@Test
- public void testTerminate() throws Exception {
+ void testTerminate() throws Exception {
activator.initialize();
activator.terminate();
assertFalse(activator.isAlive());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java
index e564d38e4..c5ebd50ea 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 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.
@@ -21,11 +21,11 @@
package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestApexStarterCommandLineArguments {
+class TestApexStarterCommandLineArguments {
/**
* Test method for {@link org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments
@@ -33,7 +33,7 @@ public class TestApexStarterCommandLineArguments {
* Assert custom option was added to options object from super.
*/
@Test
- public void testCommandLineHasPropertyFileOption() {
+ void testCommandLineHasPropertyFileOption() {
String[] args = {"-p", "someFile.json"};
ApexStarterCommandLineArguments sut = new ApexStarterCommandLineArguments(args);
assertEquals("someFile.json", sut.getPropertyFilePath());
@@ -44,7 +44,7 @@ public class TestApexStarterCommandLineArguments {
* Assert method consults version.txt from Apex module.
*/
@Test
- public void testVersion() {
+ void testVersion() {
String[] args = {"-v"};
ApexStarterCommandLineArguments sut = new ApexStarterCommandLineArguments(args);
assertThat(sut.version()).startsWith("ONAP Policy Framework Apex Starter Service");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
index f1a2a089c..4c13b5709 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,16 +24,17 @@ package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatCode;
import java.lang.reflect.Constructor;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to perform unit test of {@link ApexStarterConstants}}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterConstants {
+class TestApexStarterConstants {
+
@Test
- public void test() throws Exception {
+ void test() {
// verify that constructor does not throw an exception
assertThatCode(() -> {
Constructor<ApexStarterConstants> c = ApexStarterConstants.class.getDeclaredConstructor();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
index f24329c29..e34a1cd04 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Nordix Foundation
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
@@ -24,13 +24,13 @@ package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException;
@@ -39,18 +39,17 @@ import org.onap.policy.common.utils.resources.MessageConstants;
import org.onap.policy.common.utils.services.Registry;
/**
- * Class to perform unit test of {@link ApexStarterMain}}.
+ * Class to perform unit test of {@link ApexStarterMain}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterMain {
- private ApexStarterMain apexStarter;
+class TestApexStarterMain {
/**
* Set up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
Registry.newRegistry();
}
@@ -59,8 +58,8 @@ public class TestApexStarterMain {
*
* @throws Exception if an error occurs
*/
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
// shut down activator
final ApexStarterActivator activator =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class, null);
@@ -70,9 +69,9 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter() throws ApexStarterException {
+ void testApexStarter() throws ApexStarterException {
final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
- apexStarter = new ApexStarterMain(apexStarterConfigParameters);
+ ApexStarterMain apexStarter = new ApexStarterMain(apexStarterConfigParameters);
assertTrue(apexStarter.getParameters().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
@@ -84,7 +83,7 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_NoArguments() {
+ void testApexStarter_NoArguments() {
final String[] apexStarterConfigParameters = {};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
.isInstanceOf(ApexStarterRunTimeException.class)
@@ -92,7 +91,7 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_InvalidArguments() {
+ void testApexStarter_InvalidArguments() {
final String[] apexStarterConfigParameters = {"src/test/resources/ApexStarterConfigParameters.json"};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
.isInstanceOf(ApexStarterRunTimeException.class)
@@ -100,13 +99,13 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_Help() {
+ void testApexStarter_Help() {
final String[] apexStarterConfigParameters = {"-h"};
assertThatCode(() -> ApexStarterMain.main(apexStarterConfigParameters)).doesNotThrowAnyException();
}
@Test
- public void testApexStarter_InvalidParameters() {
+ void testApexStarter_InvalidParameters() {
final String[] apexStarterConfigParameters =
{"-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json"};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index dda98db94..7bff64652 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,20 +23,19 @@
package org.onap.policy.apex.services.onappf.comm;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
@@ -60,25 +59,23 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpStateChangeListener {
+class TestPdpStateChangeListener {
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
private ApexEngineHandler apexEngineHandler;
- private PrintStream stdout = System.out;
+ private final PrintStream stdout = System.out;
/**
* Method for setup before each test.
*
* @throws ApexStarterException if some error occurs while starting up the apex starter
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
* @throws CommandLineException if any parsing of args has errors
*/
- @Before
- public void setUp() throws ApexStarterException, FileNotFoundException, IOException, CommandLineException {
+ @BeforeEach
+ void setUp() throws ApexStarterException, CommandLineException {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
@@ -108,8 +105,8 @@ public class TestPdpStateChangeListener {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
System.setOut(stdout);
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
@@ -123,7 +120,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener_passivetopassive() {
+ void testPdpStateChangeMessageListener_passiveToPassive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
@@ -136,7 +133,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener_activetoactive() {
+ void testPdpStateChangeMessageListener_activeToActive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
@@ -150,7 +147,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener() throws InterruptedException, CoderException {
+ void testPdpStateChangeMessageListener() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
@@ -180,11 +177,11 @@ public class TestPdpStateChangeListener {
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
assertNotNull(apexEngineHandler);
- assertTrue(apexEngineHandler.getEngineStats().size() > 0);
+ assertFalse(apexEngineHandler.getEngineStats().isEmpty());
}
@Test
- public void testPdpStateChangeMessageListener_activetopassive() throws InterruptedException, CoderException {
+ void testPdpStateChangeMessageListener_activeToPassive() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
final ToscaPolicy toscaPolicy =
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index 3716e043f..56889cf72 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,21 +23,19 @@
package org.onap.policy.apex.services.onappf.comm;
import static org.assertj.core.api.Assertions.assertThat;
-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.assertTrue;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
@@ -62,25 +60,23 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpUpdateListener {
+class TestPdpUpdateListener {
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
private ApexEngineHandler apexEngineHandler;
- private PrintStream stdout = System.out;
+ private final PrintStream stdout = System.out;
/**
* Method for setup before each test.
*
* @throws ApexStarterException if some error occurs while starting up the apex starter
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
* @throws CommandLineException if any parsing of args has errors
*/
- @Before
- public void setUp() throws ApexStarterException, FileNotFoundException, IOException, CommandLineException {
+ @BeforeEach
+ void setUp() throws ApexStarterException, CommandLineException {
Registry.newRegistry();
final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
@@ -103,7 +99,7 @@ public class TestPdpUpdateListener {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.register(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER,
- new ApexPolicyStatisticsManager());
+ new ApexPolicyStatisticsManager());
}
/**
@@ -111,8 +107,8 @@ public class TestPdpUpdateListener {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
System.setOut(stdout);
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
@@ -126,29 +122,29 @@ public class TestPdpUpdateListener {
}
@Test
- public void testPdpUpdateMssageListener() throws CoderException {
+ void testPdpUpdateMessageListener() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
final ToscaPolicy toscaPolicy =
TestListenerUtils.createToscaPolicy("apex policy name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
}
@Test
- public void testPdpUpdateMssageListener_success() throws InterruptedException, CoderException {
+ void testPdpUpdateMessageListener_success() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- new ArrayList<>()));
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -157,22 +153,22 @@ public class TestPdpUpdateListener {
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
final String outString = outContent.toString();
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
assertThat(outString).contains("Apex engine started. Deployed policies are: apex_policy_name:1.0");
}
@Test
- public void testPdpUpdateMssageListener_undeploy() throws InterruptedException, CoderException {
+ void testPdpUpdateMessageListener_undeploy() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- new ArrayList<>()));
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -181,21 +177,20 @@ public class TestPdpUpdateListener {
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new ArrayList<>());
+ new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- toscaPolicies.stream().map(ToscaPolicy::getIdentifier)
+ toscaPolicies.stream().map(ToscaPolicy::getIdentifier)
.collect(Collectors.toList())));
final String outString = outContent.toString();
assertThat(outString).contains("Pdp update successful. No policies are running.");
}
@Test
- public void testPdpUpdateMssageListener_multi_policy_duplicate()
- throws InterruptedException, ApexStarterException, CoderException {
+ void testPdpUpdateMessageListener_multi_policy_duplicate() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
@@ -207,7 +202,7 @@ public class TestPdpUpdateListener {
toscaPolicies.add(toscaPolicy);
toscaPolicies.add(toscaPolicy2);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
@@ -215,6 +210,6 @@ public class TestPdpUpdateListener {
final String outString = outContent.toString();
assertTrue(outString.contains(
"Apex engine started. But, only the following polices are running - apex_policy_name:1.0 . "
- + "Other policies failed execution. Please see the logs for more details."));
+ + "Other policies failed execution. Please see the logs for more details."));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
index 7ccb850b1..da1568d33 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 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.
@@ -20,7 +20,7 @@
package org.onap.policy.apex.services.onappf.exception;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
/**
@@ -28,10 +28,10 @@ import org.onap.policy.common.utils.test.ExceptionsTester;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestExceptions {
+class TestExceptions {
@Test
- public void test() {
+ void test() {
new ExceptionsTester().test(ApexStarterException.class);
new ExceptionsTester().test(ApexStarterRunTimeException.class);
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
index f227acc6c..099663af9 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
@@ -86,7 +86,7 @@ public class CommonTestData {
* Converts the contents of a map to a parameter class.
*
* @param source property map
- * @param clazz class of object to be created from the map
+ * @param clazz class of object to be created from the map
* @return a new object represented by the map
*/
public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
@@ -102,7 +102,6 @@ public class CommonTestData {
* Returns a property map for a ApexStarterParameterGroup map for test cases.
*
* @param name name of the parameters
- *
* @return a property map suitable for constructing an object
*/
public Map<String, Object> getApexStarterParameterGroupMap(final String name) {
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
index c44964921..bd063d06a 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,12 +22,13 @@
package org.onap.policy.apex.services.onappf.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+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.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ValidationResult;
@@ -37,23 +38,23 @@ import org.onap.policy.common.parameters.ValidationResult;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterParameterGroup {
+class TestApexStarterParameterGroup {
CommonTestData commonTestData = new CommonTestData();
@Test
- public void testApexStarterParameterGroup_Named() {
+ void testApexStarterParameterGroup_Named() {
final ApexStarterParameterGroup apexStarterParameters = new ApexStarterParameterGroup("my-name");
assertEquals("my-name", apexStarterParameters.getName());
}
@Test
- public void testApexStarterParameterGroup() {
+ void testApexStarterParameterGroup() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
- ApexStarterParameterGroup.class);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
+ ApexStarterParameterGroup.class);
final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
- final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
+ final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
@@ -72,19 +73,19 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_NullName() {
+ void testApexStarterParameterGroup_NullName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
- .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
+ .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
- assertEquals(null, apexStarterParameters.getName());
+ assertNull(apexStarterParameters.getName());
assertTrue(validationResult.getResult().contains("is null"));
}
@Test
- public void testApexStarterParameterGroup_EmptyName() {
+ void testApexStarterParameterGroup_EmptyName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
- .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
+ .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, is blank");
assertFalse(validationResult.isValid());
@@ -92,10 +93,10 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_SetName() {
+ void testApexStarterParameterGroup_SetName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
- ApexStarterParameterGroup.class);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
+ ApexStarterParameterGroup.class);
apexStarterParameters.setName("ApexStarterNewGroup");
final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
@@ -103,26 +104,26 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
+ void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult())
- .contains("\"ApexStarterParameterGroup\" INVALID, item has status INVALID");
+ .contains("\"ApexStarterParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
}
@Test
- public void testApexStarterParameterGroupp_EmptyRestServerParameters() {
+ void testApexStarterParameterGroupp_EmptyRestServerParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("restServerParameters", commonTestData.getRestServerParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"RestServerParameters\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
@@ -130,13 +131,13 @@ public class TestApexStarterParameterGroup {
@Test
- public void testApexStarterParameterGroupp_EmptyTopicParameters() {
+ void testApexStarterParameterGroup_EmptyTopicParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"TopicParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index 90c2ef743..0f97203b4 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,11 +22,11 @@
package org.onap.policy.apex.services.onappf.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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.assertTrue;
import java.io.FileNotFoundException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.utils.cmd.CommandLineException;
@@ -37,11 +37,11 @@ import org.onap.policy.common.utils.coder.CoderException;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterParameterHandler {
+class TestApexStarterParameterHandler {
@Test
- public void testParameterHandlerNoParameterFile() throws ApexStarterException, CommandLineException {
- final String[] emptyArgumentString = { "-c", "src/test/resources/NoParametersFile.json" };
+ void testParameterHandlerNoParameterFile() throws CommandLineException {
+ final String[] emptyArgumentString = {"-c", "src/test/resources/NoParametersFile.json"};
final ApexStarterCommandLineArguments emptyArguments = new ApexStarterCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
@@ -52,8 +52,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerEmptyParameters() throws ApexStarterException, CommandLineException {
- final String[] noArgumentString = { "-c", "src/test/resources/NoParameters.json" };
+ void testParameterHandlerEmptyParameters() throws CommandLineException {
+ final String[] noArgumentString = {"-c", "src/test/resources/NoParameters.json"};
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -63,8 +63,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerInvalidParameters() throws ApexStarterException, CommandLineException {
- final String[] invalidArgumentString = { "-c", "src/test/resources/InvalidParameters.json" };
+ void testParameterHandlerInvalidParameters() throws CommandLineException {
+ final String[] invalidArgumentString = {"-c", "src/test/resources/InvalidParameters.json"};
final ApexStarterCommandLineArguments invalidArguments = new ApexStarterCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
@@ -75,8 +75,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerNoParameters() throws ApexStarterException, CommandLineException {
- final String[] noArgumentString = { "-c", "src/test/resources/EmptyConfigParameters.json" };
+ void testParameterHandlerNoParameters() throws CommandLineException {
+ final String[] noArgumentString = {"-c", "src/test/resources/EmptyConfigParameters.json"};
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -86,8 +86,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterParameterGroup() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
+ void testApexStarterParameterGroup() throws ApexStarterException, CommandLineException {
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParameters.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
@@ -98,9 +98,9 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterParameterGroup_InvalidName() throws ApexStarterException, CommandLineException {
+ void testApexStarterParameterGroup_InvalidName() throws CommandLineException {
final String[] apexStarterConfigParameters =
- { "-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json" };
+ {"-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
@@ -110,24 +110,24 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterVersion() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-v" };
+ void testApexStarterVersion() throws CommandLineException {
+ final String[] apexStarterConfigParameters = {"-v"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
final String version = arguments.parse(apexStarterConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Apex Starter Service"));
}
@Test
- public void testApexStarterHelp() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-h" };
+ void testApexStarterHelp() throws CommandLineException {
+ final String[] apexStarterConfigParameters = {"-h"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
final String help = arguments.parse(apexStarterConfigParameters);
assertTrue(help.startsWith("usage:"));
}
@Test
- public void testApexStarterInvalidOption() throws ApexStarterException {
- final String[] apexStarterConfigParameters = { "-d" };
+ void testApexStarterInvalidOption() {
+ final String[] apexStarterConfigParameters = {"-d"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
assertThatThrownBy(() -> arguments.parse(apexStarterConfigParameters))
.hasMessageStartingWith("invalid command line arguments specified");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
index 765bb70a9..7b65ac71e 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,13 +22,13 @@
package org.onap.policy.apex.services.onappf.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+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.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
/**
@@ -36,13 +36,13 @@ import org.onap.policy.common.parameters.ValidationResult;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpStatusParameters {
- private static CommonTestData testData = new CommonTestData();
+class TestPdpStatusParameters {
+ private static final CommonTestData testData = new CommonTestData();
@Test
- public void test() throws Exception {
+ void test() {
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
@@ -53,31 +53,31 @@ public class TestPdpStatusParameters {
}
@Test
- public void testValidate() throws Exception {
+ void testValidate() {
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final ValidationResult result = pdpStatusParameters.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
}
@Test
- public void testPdpStatusParameters_nullPdpGroup() throws Exception {
+ void testPdpStatusParameters_nullPdpGroup() {
Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
pdpStatusParametersMap.remove("pdpGroup");
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
+ testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"null\" INVALID");
}
@Test
- public void testPdpStatusParameters_emptyPdpGroup() throws Exception {
+ void testPdpStatusParameters_emptyPdpGroup() {
Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
pdpStatusParametersMap.put("pdpGroup", "");
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
+ testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"\" INVALID");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java
index 2342542e4..b89333668 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,9 +24,7 @@ package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Map;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
/**
* Dummy state finalizer executor for testing.
@@ -35,7 +33,7 @@ public class DummyStateFinalizerExecutor extends StateFinalizerExecutor {
@Override
public String execute(final long executionId, final Properties executorProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ final Map<String, Object> newIncomingFields) {
return "stateOutput0";
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java
index eac2ec3ba..85999d74c 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -25,10 +25,8 @@ package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Map;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.TaskExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
@@ -38,13 +36,13 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTask;
public class DummyTaskExecutor extends TaskExecutor {
@Override
- public void prepare() throws StateMachineException {
+ public void prepare() {
// Not used
}
@Override
public Map<String, Map<String, Object>> execute(final long executionId, final Properties executorProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ final Map<String, Object> newIncomingFields) {
AxArtifactKey event0Key = new AxArtifactKey("Event0:0.0.1");
return Map.of(event0Key.getName(), new EnEvent(event0Key));
@@ -57,7 +55,7 @@ public class DummyTaskExecutor extends TaskExecutor {
}
@Override
- public void cleanUp() throws StateMachineException {
+ public void cleanUp() {
// Not used
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java
index 5a6a98f4e..d51f2c4b0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,10 +23,8 @@
package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
/**
@@ -35,19 +33,19 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
public class DummyTaskSelectExecutor extends TaskSelectExecutor {
@Override
- public void prepare() throws StateMachineException {
+ public void prepare() {
// Not used
}
@Override
public AxArtifactKey execute(final long executionId, final Properties executorProperties,
- final EnEvent newIncomingEvent) throws StateMachineException, ContextException {
+ final EnEvent newIncomingEvent) {
return new AxArtifactKey("task:0.0.1");
}
@Override
- public void cleanUp() throws StateMachineException {
+ public void cleanUp() {
// Not used
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
index 24835d70c..3279c27ab 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,8 +21,9 @@
package org.onap.policy.apex.services.onappf.rest;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
@@ -39,10 +40,10 @@ import java.util.function.Function;
import javax.net.ssl.SSLContext;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.onap.policy.apex.services.onappf.ApexStarterMain;
@@ -59,7 +60,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.test.util.ReflectionTestUtils;
/**
- * Class to perform unit test of {@link ApexStarterRestServer}.
+ * Class to perform unit test to check REST endpoints.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
@@ -67,9 +68,8 @@ public class CommonApexStarterRestServer {
private static final Logger LOGGER = LoggerFactory.getLogger(CommonApexStarterRestServer.class);
- private static Coder coder = new StandardCoder();
+ private static final Coder coder = new StandardCoder();
- public static final String NOT_ALIVE = "not alive";
public static final String ALIVE = "alive";
public static final String SELF = "self";
public static final String ENDPOINT_PREFIX = "policy/apex-pdp/v1/";
@@ -86,7 +86,7 @@ public class CommonApexStarterRestServer {
*
* @throws Exception if an error occurs
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
port = NetworkUtil.allocPort();
@@ -100,7 +100,7 @@ public class CommonApexStarterRestServer {
/**
* Stops Main.
*/
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() {
try {
stopMain();
@@ -115,7 +115,7 @@ public class CommonApexStarterRestServer {
*
* @throws Exception if an error occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
// restart, if not currently running
if (main == null) {
@@ -123,13 +123,13 @@ public class CommonApexStarterRestServer {
}
activatorWasAlive =
- Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
}
/**
* Restores the activator's "alive" state.
*/
- @After
+ @AfterEach
public void tearDown() {
markActivator(activatorWasAlive);
}
@@ -154,10 +154,10 @@ public class CommonApexStarterRestServer {
*/
private static void makeConfigFile() throws Exception {
final Map<String, Object> config =
- new CommonTestData().getApexStarterParameterGroupMap("ApexStarterParameterGroup");
+ new CommonTestData().getApexStarterParameterGroupMap("ApexStarterParameterGroup");
- @SuppressWarnings("unchecked")
- final Map<String, Object> restParams = (Map<String, Object>) config.get("restServerParameters");
+ @SuppressWarnings("unchecked") final Map<String, Object> restParams =
+ (Map<String, Object>) config.get("restServerParameters");
restParams.put("port", port);
final File file = new File("src/test/resources/TestConfigParams.json");
@@ -184,7 +184,7 @@ public class CommonApexStarterRestServer {
systemProps.put("javax.net.ssl.keyStorePassword", SelfSignedKeyStore.KEYSTORE_PASSWORD);
System.setProperties(systemProps);
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/TestConfigParams.json" };
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/TestConfigParams.json"};
main = new ApexStarterMain(apexStarterConfigParameters);
@@ -196,7 +196,7 @@ public class CommonApexStarterRestServer {
/**
* Stops the "Main".
*
- * @throws Exception if an error occurs
+ * @throws ApexStarterException if an error occurs
*/
private static void stopMain() throws ApexStarterException {
if (main != null) {
@@ -209,8 +209,10 @@ public class CommonApexStarterRestServer {
private void markActivator(final boolean wasAlive) {
final Object manager = ReflectionTestUtils.getField(
- Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class), "manager");
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class), "manager");
+ assertNotNull(manager);
AtomicBoolean running = (AtomicBoolean) ReflectionTestUtils.getField(manager, "running");
+ assertNotNull(running);
running.set(wasAlive);
}
@@ -218,13 +220,13 @@ public class CommonApexStarterRestServer {
* Verifies that unauthorized requests fail.
*
* @param endpoint the target end point
- * @param sender function that sends the requests to the target
+ * @param sender function that sends the requests to the target
* @throws Exception if an error occurs
*/
- protected void checkUnauthRequest(final String endpoint, final Function<Invocation.Builder, Response> sender)
- throws Exception {
+ protected void checkUnauthorizedRequest(final String endpoint, final Function<Invocation.Builder, Response> sender)
+ throws Exception {
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(),
- sender.apply(sendNoAuthRequest(endpoint)).getStatus());
+ sender.apply(sendNoAuthRequest(endpoint)).getStatus());
}
/**
@@ -253,16 +255,16 @@ public class CommonApexStarterRestServer {
* Sends a request to a fully qualified endpoint.
*
* @param fullyQualifiedEndpoint the fully qualified target endpoint
- * @param includeAuth if authorization header should be included
+ * @param includeAuth if authorization header should be included
* @return a request builder
* @throws Exception if an error occurs
*/
protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, final boolean includeAuth)
- throws Exception {
+ throws Exception {
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom());
final ClientBuilder clientBuilder =
- ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
+ ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
final Client client = clientBuilder.build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
index a49fb5070..a63824a0e 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,44 +22,39 @@
package org.onap.policy.apex.services.onappf.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.client.Invocation;
-import org.junit.Ignore;
-import org.junit.Test;
+import jakarta.ws.rs.client.SyncInvoker;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
/**
- * Class to perform unit test of {@link ApexStarterRestServer}.
+ * Class to perform unit test of {@link HealthCheckRestControllerV1}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
+class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
- @Ignore
@Test
- public void testSwagger() throws Exception {
- super.testSwagger(HEALTHCHECK_ENDPOINT);
- }
-
- @Test
- public void testHealthCheckSuccess() throws Exception {
+ void testHealthCheckSuccess() throws Exception {
final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(SELF, true, 200, ALIVE, report);
+ validateHealthCheckReport(report);
// verify it fails when no authorization info is included
- checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
+ checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
}
- private void validateHealthCheckReport(final String url, final boolean healthy, final int code,
- final String message, final HealthCheckReport report) {
+ private void validateHealthCheckReport(final HealthCheckReport report) {
assertThat(report.getName()).isNotBlank();
- assertEquals(url, report.getUrl());
- assertEquals(healthy, report.isHealthy());
- assertEquals(code, report.getCode());
- assertEquals(message, report.getMessage());
+ assertEquals(CommonApexStarterRestServer.SELF, report.getUrl());
+ assertTrue(report.isHealthy());
+ assertEquals(200, report.getCode());
+ assertEquals(CommonApexStarterRestServer.ALIVE, report.getMessage());
}
}