summaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-08-10 14:47:31 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-10 14:47:31 +0000
commite9261d520a496881c315fe28aa9095f59d579e0a (patch)
treeec801e5b9e80d8ee74a434e029f8a7d41a3edba9 /services/services-engine
parent69db35c582df773c5559ee569f9ba22c6bcb69d8 (diff)
parentf4895ff98b3ed83b44733adc20ad8cf0092a3d83 (diff)
Merge "Handling apex-pdp multi policy deployment failure:"
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java18
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java19
2 files changed, 24 insertions, 13 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
index 1e2447b2e..a928f208c 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexActivator.java
@@ -24,6 +24,7 @@ package org.onap.policy.apex.service.engine.main;
import java.io.IOException;
import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -133,16 +134,19 @@ public class ApexActivator {
new LinkedHashSet<>(apexParametersMap.entrySet());
apexParamsEntrySet.stream().forEach(apexParamsEntry -> {
ApexParameters apexParams = apexParamsEntry.getValue();
- boolean duplicateInputParameterExist =
- apexParams.getEventInputParameters().keySet().stream().anyMatch(inputParametersMap::containsKey);
- boolean duplicateOutputParameterExist =
- apexParams.getEventOutputParameters().keySet().stream().anyMatch(outputParametersMap::containsKey);
- if (duplicateInputParameterExist || duplicateOutputParameterExist) {
- LOGGER.error("I/O Parameters for {}:{} has duplicates. So this policy is not executed.",
- apexParamsEntry.getKey().getName(), apexParamsEntry.getKey().getVersion());
+ List<String> duplicateInputParameters = new ArrayList<>(apexParams.getEventInputParameters().keySet());
+ duplicateInputParameters.retainAll(inputParametersMap.keySet());
+ List<String> duplicateOutputParameters = new ArrayList<>(apexParams.getEventOutputParameters().keySet());
+ duplicateOutputParameters.retainAll(outputParametersMap.keySet());
+
+ if (!(duplicateInputParameters.isEmpty() && duplicateOutputParameters.isEmpty())) {
+ LOGGER.error("I/O Parameters {}/{} for {}:{} are duplicates. So this policy is not executed.",
+ duplicateInputParameters, duplicateOutputParameters, apexParamsEntry.getKey().getName(),
+ apexParamsEntry.getKey().getVersion());
apexParametersMap.remove(apexParamsEntry.getKey());
return;
}
+
inputParametersMap.putAll(apexParams.getEventInputParameters());
outputParametersMap.putAll(apexParams.getEventOutputParameters());
// Check if a policy model file has been specified
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index 731baf5ef..f38dcaa40 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 Bell Canada. 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.
@@ -21,9 +22,10 @@
package org.onap.policy.apex.service.engine.main;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
@@ -61,6 +63,8 @@ public class ApexMainTest {
ApexMain.main(null);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("Apex configuration file was not specified as an argument"));
+ assertThat(outContent.toString())
+ .contains("Apex configuration file was not specified as an argument");
}
@Test
@@ -73,6 +77,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("invalid command line arguments specified : Unrecognized option: -whee"));
+ assertNotNull(apexMain);
apexMain.shutdown();
}
@@ -86,6 +91,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
+ assertNotNull(apexMain);
apexMain.shutdown();
}
@@ -99,6 +105,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
.contains("parameter group has status INVALID"));
+ assertNotNull(apexMain);
apexMain.shutdown();
}
@@ -148,7 +155,7 @@ public class ApexMainTest {
assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName());
apexMain.shutdown();
final String outString = outContent.toString();
- assertTrue(outString.contains("Added the action listener to the engine"));
+ assertThat(outString).contains("Added the action listener to the engine");
}
@Test
@@ -165,7 +172,8 @@ public class ApexMainTest {
assertEquals("MyApexEngine", apexParam.getEngineServiceParameters().getName());
apexMain.shutdown();
final String outString = outContent.toString();
- assertTrue(outString.contains("I/O Parameters for id2:v2 has duplicates. So this policy is not executed"));
+ assertThat(outString).contains("I/O Parameters [TheFileConsumer1]/[FirstProducer] for id2:v2 are duplicates. "
+ + "So this policy is not executed");
assertEquals(1, apexMain.getApexParametersMap().size()); // only id1:v1 is kept in the map, id2:v2 failed
}
@@ -179,8 +187,7 @@ public class ApexMainTest {
final ApexMain apexMain = new ApexMain(argsMap);
final String outString = outContent.toString();
apexMain.shutdown();
- assertTrue(
- outString.contains("Arguments validation failed") && outString.contains("start of Apex service failed"));
- assertTrue(apexMain.getApexParametersMap().isEmpty()); // No policy is running in the engine
+ assertThat(outString).contains("Arguments validation failed", "start of Apex service failed");
+ assertThat(apexMain.getApexParametersMap()).isEmpty(); // No policy is running in the engine
}
}