summaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/test
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-04-02 09:09:51 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-04-02 09:09:51 +0000
commit50b84774797677791fb2111cf97b9f2ff65cb3e2 (patch)
tree2162cff82f7cdfa1305786a6ed5e9916cdbf7006 /services/services-onappf/src/test
parentab4cba7d37f41eddbf3ab040f04afe18c6630777 (diff)
Changes to send pdp status messages
1) Adding handlers to create and send pdp status messages from apex-pdp. 2) Changes to read initial pdp status parameters from configuration file. 3) Adding test cases. Change-Id: Id2d1caa8abc124865a9ef8fbfe4d9f751e4491b5 Issue-ID: POLICY-1452 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'services/services-onappf/src/test')
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java19
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java37
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java17
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java52
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java18
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java1
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java60
-rw-r--r--services/services-onappf/src/test/resources/ApexStarterConfigParameters.json9
8 files changed, 181 insertions, 32 deletions
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java
index 3b7df8321..6da3a5eb6 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterActivator.java
@@ -23,7 +23,8 @@ package org.onap.policy.apex.starter;
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.assertSame;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
@@ -36,8 +37,8 @@ import org.onap.policy.apex.starter.exception.ApexStarterException;
import org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.starter.parameters.ApexStarterParameterHandler;
import org.onap.policy.apex.starter.parameters.CommonTestData;
-
-
+import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.pdp.concepts.PdpStatus;
/**
* Class to perform unit test of {@link ApexStarterActivator}}.
@@ -55,6 +56,7 @@ public class TestApexStarterActivator {
*/
@Before
public void setUp() throws Exception {
+ Registry.newRegistry();
final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
"-p", "src/test/resources/topic.properties" };
final ApexStarterCommandLineArguments arguments =
@@ -90,6 +92,9 @@ public class TestApexStarterActivator {
assertTrue(activator.getParameterGroup().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, activator.getParameterGroup().getName());
+ // ensure items were added to the registry
+ assertNotNull(Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class));
+
// repeat - should throw an exception
assertThatIllegalStateException().isThrownBy(() -> activator.initialize());
assertTrue(activator.isAlive());
@@ -97,16 +102,14 @@ public class TestApexStarterActivator {
}
@Test
- public void testGetCurrent_testSetCurrent() {
- assertSame(activator, ApexStarterActivator.getCurrent());
- }
-
- @Test
public void testTerminate() throws Exception {
activator.initialize();
activator.terminate();
assertFalse(activator.isAlive());
+ // ensure items have been removed from the registry
+ assertNull(Registry.getOrDefault(ApexStarterConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class, null));
+
// repeat - should throw an exception
assertThatIllegalStateException().isThrownBy(() -> activator.terminate());
assertFalse(activator.isAlive());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java
new file mode 100644
index 000000000..08e56cdf8
--- /dev/null
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterConstants.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.starter;
+
+import org.junit.Test;
+import org.powermock.reflect.Whitebox;
+
+/**
+ * Class to perform unit test of {@link ApexStarterConstants}}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class TestApexStarterConstants {
+ @Test
+ public void test() throws Exception {
+ // verify that constructor does not throw an exception
+ Whitebox.invokeConstructor(ApexStarterConstants.class);
+ }
+}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java
index 5d52d85c5..3005e320a 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/TestApexStarterMain.java
@@ -21,12 +21,15 @@
package org.onap.policy.apex.starter;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.starter.exception.ApexStarterException;
import org.onap.policy.apex.starter.parameters.CommonTestData;
+import org.onap.policy.common.utils.services.Registry;
/**
* Class to perform unit test of {@link ApexStarterMain}}.
@@ -37,6 +40,14 @@ public class TestApexStarterMain {
private ApexStarterMain apexStarter;
/**
+ * Set up.
+ */
+ @Before
+ public void setUp() {
+ Registry.newRegistry();
+ }
+
+ /**
* Shuts "main" down.
*
* @throws Exception if an error occurs
@@ -44,7 +55,8 @@ public class TestApexStarterMain {
@After
public void tearDown() throws Exception {
// shut down activator
- final ApexStarterActivator activator = ApexStarterActivator.getCurrent();
+ final ApexStarterActivator activator = Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR,
+ ApexStarterActivator.class, null);
if (activator != null && activator.isAlive()) {
activator.terminate();
}
@@ -58,6 +70,9 @@ public class TestApexStarterMain {
assertTrue(apexStarter.getParameters().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
+ // ensure items were added to the registry
+ assertNotNull(Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class));
+
apexStarter.shutdown();
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java
index 08a33b94c..03f6ec2c5 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/CommonTestData.java
@@ -20,6 +20,8 @@
package org.onap.policy.apex.starter.parameters;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -36,9 +38,29 @@ import org.onap.policy.common.utils.coder.StandardCoder;
public class CommonTestData {
public static final String APEX_STARTER_GROUP_NAME = "ApexStarterParameterGroup";
- public static final int APEX_STARTER_TIME_INTERVAL = 5;
+ public static final int TIME_INTERVAL = 2;
+ public static final String PDP_NAME = "apex-pdp";
+ public static final String VERSION = "0.0.1";
+ public static final String PDP_TYPE = "apex";
+ public static final String DESCRIPTION = "Pdp status for HealthCheck";
+ public static final String POLICY_NAME = "onap.controllloop.operational.apex.BBS";
+ public static final String POLICY_VERSION = "0.0.1";
+ public static final List<PolicyTypeIdentParameters> SUPPORTED_POLICY_TYPES =
+ Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
+
+ public static final Coder coder = new StandardCoder();
- private static final Coder coder = new StandardCoder();
+ /**
+ * Returns supported policy types for test cases.
+ *
+ * @return supported policy types
+ */
+ public static PolicyTypeIdentParameters getSupportedPolicyTypes(final String name, final String version) {
+ final PolicyTypeIdentParameters policyTypeIdentParameters = new PolicyTypeIdentParameters();
+ policyTypeIdentParameters.setName(name);
+ policyTypeIdentParameters.setVersion(version);
+ return policyTypeIdentParameters;
+ }
/**
* Converts the contents of a map to a parameter class.
@@ -67,26 +89,28 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
map.put("name", name);
- map.put("timeInterval", getTimeInterval(false));
+ map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
return map;
}
-
-
/**
- * Determines whether to return null or a valid time interval
+ * Returns a property map for a PdpStatusParameters map for test cases.
*
- * @param isNullField flag to determine what to return
- * @return time interval based on the flag
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
*/
- public Object getTimeInterval(final boolean isNullField) {
- if (isNullField) {
- return null;
- } else {
- return APEX_STARTER_TIME_INTERVAL;
+ public Map<String, Object> getPdpStatusParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("timeInterval", TIME_INTERVAL);
+ map.put("pdpName", PDP_NAME);
+ map.put("version", VERSION);
+ map.put("pdpType", PDP_TYPE);
+ map.put("description", DESCRIPTION);
+ map.put("supportedPolicyTypes", SUPPORTED_POLICY_TYPES);
}
+ return map;
}
-
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java
index d22455214..2ba575ea6 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterGroup.java
@@ -48,10 +48,16 @@ public class TestApexStarterParameterGroup {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
ApexStarterParameterGroup.class);
+ final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
- assertEquals(CommonTestData.APEX_STARTER_TIME_INTERVAL, apexStarterParameters.getTimeInterval());
+ assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeInterval());
+ assertEquals(CommonTestData.PDP_NAME, pdpStatusParameters.getPdpName());
+ assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
+ assertEquals(CommonTestData.VERSION, pdpStatusParameters.getVersion());
+ assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
+ assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
}
@Test
@@ -61,7 +67,6 @@ public class TestApexStarterParameterGroup {
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, apexStarterParameters.getName());
- assertEquals(CommonTestData.APEX_STARTER_TIME_INTERVAL, apexStarterParameters.getTimeInterval());
assertTrue(validationResult.getResult().contains("is null"));
}
@@ -72,7 +77,6 @@ public class TestApexStarterParameterGroup {
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", apexStarterParameters.getName());
- assertEquals(CommonTestData.APEX_STARTER_TIME_INTERVAL, apexStarterParameters.getTimeInterval());
assertTrue(validationResult.getResult().contains(
"field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
}
@@ -89,16 +93,16 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_EmptyTimeInterval() {
+ public void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
final Map<String, Object> map =
commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
- map.put("timeInterval", commonTestData.getTimeInterval(true));
+ map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
commonTestData.toObject(map, ApexStarterParameterGroup.class);
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("field \"timeInterval\" type \"int\" value \"0\" INVALID, must be >= 1")
- && validationResult.getResult().contains("parameter group has status INVALID"));
+ .contains("\"org.onap.policy.apex.starter.parameters.ApexStarterParameterGroup\" INVALID, "
+ + "parameter group has status INVALID"));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java
index 3889b2aa5..baa91d23a 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestApexStarterParameterHandler.java
@@ -109,7 +109,6 @@ public class TestApexStarterParameterHandler {
final ApexStarterParameterGroup parGroup = new ApexStarterParameterHandler().getParameters(arguments);
assertTrue(arguments.checkSetConfigurationFilePath());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, parGroup.getName());
- assertEquals(CommonTestData.APEX_STARTER_TIME_INTERVAL, parGroup.getTimeInterval());
}
@Test
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java
new file mode 100644
index 000000000..c5e061e1b
--- /dev/null
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/starter/parameters/TestPdpStatusParameters.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.starter.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of {@link PdpStatusParameters}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class TestPdpStatusParameters {
+ private static CommonTestData testData = new CommonTestData();
+
+ @Test
+ public void test() throws Exception {
+ final PdpStatusParameters pdpStatusParameters =
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ final GroupValidationResult validationResult = pdpStatusParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeInterval());
+ assertEquals(CommonTestData.PDP_NAME, pdpStatusParameters.getPdpName());
+ assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
+ assertEquals(CommonTestData.VERSION, pdpStatusParameters.getVersion());
+ assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
+ assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
+ }
+
+ @Test
+ public void testValidate() throws Exception {
+ final PdpStatusParameters pdpStatusParameters =
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ final GroupValidationResult result = pdpStatusParameters.validate();
+ assertNull(result.getResult());
+ assertTrue(result.isValid());
+ }
+}
diff --git a/services/services-onappf/src/test/resources/ApexStarterConfigParameters.json b/services/services-onappf/src/test/resources/ApexStarterConfigParameters.json
index 2720cdefd..dad7408dc 100644
--- a/services/services-onappf/src/test/resources/ApexStarterConfigParameters.json
+++ b/services/services-onappf/src/test/resources/ApexStarterConfigParameters.json
@@ -1,4 +1,11 @@
{
"name":"ApexStarterParameterGroup",
- "timeInterval": 5
+ "pdpStatusParameters":{
+ "timeInterval": 2,
+ "pdpName":"apex-pdp",
+ "version":"0.0.1",
+ "pdpType":"apex",
+ "description":"Pdp status for HealthCheck",
+ "supportedPolicyTypes":[{"name":"policy1","version":"1.0"},{"name":"policy2","version":"1.0"}]
+ }
}