summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-07-13 10:30:02 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2021-07-20 14:13:14 +0100
commit2ddb38bd7f0c5e6b74f5ac74685120f32ce9e9de (patch)
tree18733e450cedd87d522e5db3554ce163a427ea13 /runtime-controlloop/src/test/java
parentc16142da394ba515aa639aa87d88137a73c0c8ac (diff)
Refactor Control Loop Parameters in Spring
Issue-ID: POLICY-3461 Change-Id: I54351d02da9bfa2b775f40fad0a12a4f32994cd9 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-controlloop/src/test/java')
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java31
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java5
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java2
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java17
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java4
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java14
6 files changed, 22 insertions, 51 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
index 440380781..448df4199 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
@@ -31,9 +31,6 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.provider.PolicyModelsProvider;
@@ -46,31 +43,11 @@ class CommissioningProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
private static final String TEMPLATE_IS_NULL = ".*serviceTemplate is marked non-null but is null";
- private static final Coder CODER = new StandardCoder();
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
- private static int dbNum = 0;
- private static final Object lockit = new Object();
private PolicyModelsProvider modelsProvider = null;
private ControlLoopProvider clProvider = null;
- private static String getParameterGroupAsString() {
- dbNum++;
- return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
- .replace("jdbc:h2:mem:testdb", "jdbc:h2:mem:commissioningdb" + dbNum);
- }
-
- /**
- * return a Cl Runtime Parameters.
- *
- * @throws CoderException .
- */
- public ClRuntimeParameterGroup getClRuntimeParameterGroup() throws CoderException {
- synchronized (lockit) {
- return CODER.decode(getParameterGroupAsString(), ClRuntimeParameterGroup.class);
- }
- }
-
@AfterEach
void close() throws Exception {
if (modelsProvider != null) {
@@ -88,7 +65,7 @@ class CommissioningProviderTest {
*/
@Test
void testGetControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -125,7 +102,7 @@ class CommissioningProviderTest {
*/
@Test
void testCreateControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("createCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -154,7 +131,7 @@ class CommissioningProviderTest {
*/
@Test
void testDeleteControlLoopDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("deleteCLDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
@@ -182,7 +159,7 @@ class CommissioningProviderTest {
*/
@Test
void testGetControlLoopElementDefinitions() throws Exception {
- ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLElDefinitions");
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
index 2b4abaa3b..461c8b558 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
@@ -33,8 +33,8 @@ import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
-import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterHandler;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusListener;
+import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
@@ -52,8 +52,7 @@ class MessageDispatcherActivatorTest {
@Test
void testStartAndStop() throws Exception {
- final String path = "src/test/resources/parameters/TestParameters.json";
- ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterHandler().getParameters(path);
+ ClRuntimeParameterGroup parameterGroup = CommonTestData.geParameterGroup("dbtest");
var publisherFirst = spy(mock(Publisher.class));
var publisherSecond = spy(mock(Publisher.class));
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index b92f341eb..b474b0cdf 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -100,7 +100,7 @@ class ControlLoopInstantiationProviderTest {
*/
@BeforeAll
public static void setupDbProviderParameters() throws PfModelException {
- ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup(0, "instantproviderdb");
+ ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb");
modelsProvider =
CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
index c47211a2d..5f885ec97 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java
@@ -97,7 +97,7 @@ class TestMonitoringProvider {
@Test
void testCreateParticipantStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createparStat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("createparStat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -123,7 +123,7 @@ class TestMonitoringProvider {
@Test
void testGetParticipantStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getparStat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -156,7 +156,7 @@ class TestMonitoringProvider {
@Test
void testCreateClElementStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createelemstat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("createelemstat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
@@ -183,14 +183,13 @@ class TestMonitoringProvider {
@Test
void testGetClElementStatistics() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstat");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getelemstat");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
MonitoringProvider provider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
-
assertThatThrownBy(() -> {
provider.fetchFilteredClElementStatistics(null, null, null, null, null, 0);
}).hasMessageMatching("name is marked .*null but is null");
@@ -217,7 +216,7 @@ class TestMonitoringProvider {
@Test
void testGetParticipantStatsPerCL() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStatCL");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getparStatCL");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
var mockClProvider = Mockito.mock(ControlLoopProvider.class);
@@ -253,7 +252,7 @@ class TestMonitoringProvider {
mockCL.setElements(new LinkedHashMap<>());
mockCL.getElements().put(mockClElement.getId(), mockClElement);
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstatPerCL");
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup("getelemstatPerCL");
participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
ControlLoopProvider mockClProvider = Mockito.mock(ControlLoopProvider.class);
@@ -265,8 +264,8 @@ class TestMonitoringProvider {
monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- ClElementStatisticsList getResponse;
- getResponse = monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
+ ClElementStatisticsList getResponse =
+ monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
assertThat(getResponse.getClElementStatistics()).hasSize(2);
assertEquals(getResponse.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""),
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
index f08cda12b..305850cbd 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -20,8 +20,6 @@
package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
-import static org.assertj.core.api.Assertions.assertThat;
-
import java.time.Instant;
import java.util.Collections;
import java.util.List;
@@ -79,7 +77,7 @@ class SupervisionMessagesTest extends CommonRestController {
*/
@BeforeAll
public static void setupDbProviderParameters() throws PfModelException {
- ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup(0, "instantproviderdb");
+ ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb");
modelsProvider =
CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
index 464c14354..300c662ce 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java
@@ -38,19 +38,18 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
*
*/
public class CommonTestData {
- private static final Coder coder = new StandardCoder();
+ private static final Coder CODER = new StandardCoder();
/**
* Gets the standard Control Loop parameters.
*
- * @param port port to be inserted into the parameters
* @param dbName the database name
* @return the standard Control Loop parameters
* @throws ControlLoopRuntimeException on errors reading the control loop parameters
*/
- public static ClRuntimeParameterGroup geParameterGroup(final int port, final String dbName) {
+ public static ClRuntimeParameterGroup geParameterGroup(final String dbName) {
try {
- return coder.decode(getParameterGroupAsString(port, dbName), ClRuntimeParameterGroup.class);
+ return CODER.convert(getParameterGroupAsString(dbName), ClRuntimeParameterGroup.class);
} catch (CoderException e) {
throw new ControlLoopRuntimeException(Status.NOT_ACCEPTABLE, "cannot read Control Loop parameters", e);
@@ -60,13 +59,12 @@ public class CommonTestData {
/**
* Gets the standard Control Loop parameters, as a String.
*
- * @param port port to be inserted into the parameters
* @param dbName the database name
* @return the standard Control Loop parameters as string
*/
- public static String getParameterGroupAsString(final int port, final String dbName) {
- return ResourceUtils.getResourceAsString("src/test/resources/parameters/InstantiationConfigParametersStd.json")
- .replace("${port}", String.valueOf(port)).replace("${dbName}", "jdbc:h2:mem:" + dbName);
+ public static String getParameterGroupAsString(final String dbName) {
+ return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
+ .replace("${dbName}", "jdbc:h2:mem:" + dbName);
}
/**