aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/main/java/org/onap
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-06-14 11:14:09 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-06-17 15:25:22 +0100
commite4383ac15c6e4da1a83115a31730f729ff25f5cd (patch)
tree2aa25c288185ab247108c1953b387752bbe23e47 /services/services-onappf/src/main/java/org/onap
parent70e614910a05b3588902a779e996a9c695c4b3d9 (diff)
Convert junit4 to junit5
- services module Issue-ID: POLICY-5041 Change-Id: I50f1ce21dbef1398cd91dd55196baa61bd06a63c Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'services/services-onappf/src/main/java/org/onap')
-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
4 files changed, 41 insertions, 40 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;