aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-07-19 13:24:46 +0000
committerGerrit Code Review <gerrit@onap.org>2021-07-19 13:24:46 +0000
commit931424fc681b1d41afbba98a190253283f9a6eba (patch)
treea14b7d2480607709346c7f0b6f81b83144d58e3d /runtime-controlloop/src/test
parent1bf974165f360d5850865974e7251cb0bd628057 (diff)
parent741b6c5c5eac437ae2a54a6dd5518513cdfe9034 (diff)
Merge "Convert Control Loop components to Spring and Supervision refactor"
Diffstat (limited to 'runtime-controlloop/src/test')
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java163
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java100
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java343
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivatorTest.java65
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java280
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java17
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java20
-rw-r--r--runtime-controlloop/src/test/resources/parameters/TestParameters.json7
8 files changed, 554 insertions, 441 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 fdddcf996..440380781 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
@@ -26,13 +26,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import org.junit.jupiter.api.AfterEach;
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;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
@@ -47,6 +51,9 @@ class CommissioningProviderTest {
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")
@@ -64,6 +71,16 @@ class CommissioningProviderTest {
}
}
+ @AfterEach
+ void close() throws Exception {
+ if (modelsProvider != null) {
+ modelsProvider.close();
+ }
+ if (clProvider != null) {
+ clProvider.close();
+ }
+ }
+
/**
* Test the fetching of control loop definitions (ToscaServiceTemplates).
*
@@ -71,33 +88,34 @@ class CommissioningProviderTest {
*/
@Test
void testGetControlLoopDefinitions() throws Exception {
- List<ToscaNodeTemplate> listOfTemplates;
ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ ToscaServiceTemplate serviceTemplate = yamlTranslator
+ .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+
+ List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).isEmpty();
+
+ provider.createControlLoopDefinitions(serviceTemplate);
+ listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).hasSize(2);
+
+ // Test Filtering
+ listOfTemplates = provider.getControlLoopDefinitions("org.onap.domain.pmsh.PMSHControlLoopDefinition", "1.2.3");
+ assertThat(listOfTemplates).hasSize(1);
+ for (ToscaNodeTemplate template : listOfTemplates) {
+ // Other CL elements contain PMSD instead of PMSH in their name
+ assertThat(template.getName()).doesNotContain("PMSD");
+ }
- try (var provider = new CommissioningProvider(clRuntimeParameterGroup)) {
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
-
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
-
- provider.createControlLoopDefinitions(serviceTemplate);
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
-
- // Test Filtering
- listOfTemplates =
- provider.getControlLoopDefinitions("org.onap.domain.pmsh.PMSHControlLoopDefinition", "1.2.3");
- assertThat(listOfTemplates).hasSize(1);
- for (ToscaNodeTemplate template : listOfTemplates) {
- // Other CL elements contain PMSD instead of PMSH in their name
- assertThat(template.getName()).doesNotContain("PMSD");
- }
+ // Test Wrong Name
+ listOfTemplates = provider.getControlLoopDefinitions("WrongControlLoopName", "0.0.0");
+ assertThat(listOfTemplates).isEmpty();
- // Test Wrong Name
- listOfTemplates = provider.getControlLoopDefinitions("WrongControlLoopName", "0.0.0");
- assertThat(listOfTemplates).isEmpty();
- }
}
/**
@@ -107,25 +125,26 @@ class CommissioningProviderTest {
*/
@Test
void testCreateControlLoopDefinitions() throws Exception {
- List<ToscaNodeTemplate> listOfTemplates;
ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
-
- try (var provider = new CommissioningProvider(clRuntimeParameterGroup)) {
- // Test Service template is null
- assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL);
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
-
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
-
- // Response should return the number of node templates present in the service template
- List<ToscaConceptIdentifier> affectedDefinitions =
- provider.createControlLoopDefinitions(serviceTemplate).getAffectedControlLoopDefinitions();
- assertThat(affectedDefinitions).hasSize(13);
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
- }
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ // Test Service template is null
+ assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL);
+ List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).isEmpty();
+
+ ToscaServiceTemplate serviceTemplate = yamlTranslator
+ .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+
+ // Response should return the number of node templates present in the service template
+ List<ToscaConceptIdentifier> affectedDefinitions =
+ provider.createControlLoopDefinitions(serviceTemplate).getAffectedControlLoopDefinitions();
+ assertThat(affectedDefinitions).hasSize(13);
+ listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).hasSize(2);
}
/**
@@ -135,24 +154,25 @@ class CommissioningProviderTest {
*/
@Test
void testDeleteControlLoopDefinitions() throws Exception {
- List<ToscaNodeTemplate> listOfTemplates;
ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- try (var provider = new CommissioningProvider(clRuntimeParameterGroup)) {
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ ToscaServiceTemplate serviceTemplate = yamlTranslator
+ .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
+ List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).isEmpty();
- provider.createControlLoopDefinitions(serviceTemplate);
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
+ provider.createControlLoopDefinitions(serviceTemplate);
+ listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).hasSize(2);
- provider.deleteControlLoopDefinition(serviceTemplate.getName(), serviceTemplate.getVersion());
- listOfTemplates = provider.getControlLoopDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
- }
+ provider.deleteControlLoopDefinition(serviceTemplate.getName(), serviceTemplate.getVersion());
+ listOfTemplates = provider.getControlLoopDefinitions(null, null);
+ assertThat(listOfTemplates).isEmpty();
}
/**
@@ -163,26 +183,29 @@ class CommissioningProviderTest {
@Test
void testGetControlLoopElementDefinitions() throws Exception {
ClRuntimeParameterGroup clRuntimeParameterGroup = getClRuntimeParameterGroup();
- try (var provider = new CommissioningProvider(clRuntimeParameterGroup)) {
- ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
- ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- provider.getControlLoopDefinitions(null, null);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ ToscaServiceTemplate serviceTemplate = yamlTranslator
+ .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
- provider.createControlLoopDefinitions(serviceTemplate);
- List<ToscaNodeTemplate> controlLoopDefinitionList =
- provider.getControlLoopDefinitions("org.onap.domain.pmsh.PMSHControlLoopDefinition", "1.2.3");
+ provider.getControlLoopDefinitions(null, null);
- List<ToscaNodeTemplate> controlLoopElementNodeTemplates =
- provider.getControlLoopElementDefinitions(controlLoopDefinitionList.get(0));
+ provider.createControlLoopDefinitions(serviceTemplate);
+ List<ToscaNodeTemplate> controlLoopDefinitionList =
+ provider.getControlLoopDefinitions("org.onap.domain.pmsh.PMSHControlLoopDefinition", "1.2.3");
- // 4 PMSH control loop elements definitions.
- assertThat(controlLoopElementNodeTemplates).hasSize(4);
+ List<ToscaNodeTemplate> controlLoopElementNodeTemplates =
+ provider.getControlLoopElementDefinitions(controlLoopDefinitionList.get(0));
- List<ToscaNodeType> derivedTypes = getDerivedNodeTypes(serviceTemplate);
- for (ToscaNodeTemplate template : controlLoopElementNodeTemplates) {
- assertTrue(checkNodeType(template, derivedTypes));
- }
+ // 4 PMSH control loop elements definitions.
+ assertThat(controlLoopElementNodeTemplates).hasSize(4);
+
+ List<ToscaNodeType> derivedTypes = getDerivedNodeTypes(serviceTemplate);
+ for (ToscaNodeTemplate template : controlLoopElementNodeTemplates) {
+ assertTrue(checkNodeType(template, derivedTypes));
}
}
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
new file mode 100644
index 000000000..2b4abaa3b
--- /dev/null
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/config/messaging/MessageDispatcherActivatorTest.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.clamp.controlloop.runtime.config.messaging;
+
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+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.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
+
+/**
+ * Class to perform unit test of {@link MessageDispatcherActivator}}.
+ *
+ */
+class MessageDispatcherActivatorTest {
+
+ private static final Coder CODER = new StandardCoder();
+
+ private static final String TOPIC_FIRST = "TOPIC1";
+ private static final String TOPIC_SECOND = "TOPIC2";
+
+ @Test
+ void testStartAndStop() throws Exception {
+ final String path = "src/test/resources/parameters/TestParameters.json";
+ ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterHandler().getParameters(path);
+
+ var publisherFirst = spy(mock(Publisher.class));
+ var publisherSecond = spy(mock(Publisher.class));
+ var publishers = new Publisher[] {publisherFirst, publisherSecond};
+
+ var listenerFirst = spy(mock(ParticipantStatusListener.class));
+ when(listenerFirst.getType()).thenReturn(TOPIC_FIRST);
+ when(listenerFirst.getScoListener()).thenReturn(listenerFirst);
+
+ var listenerSecond = spy(mock(ParticipantStatusListener.class));
+ when(listenerSecond.getType()).thenReturn(TOPIC_SECOND);
+ when(listenerSecond.getScoListener()).thenReturn(listenerSecond);
+
+ var listeners = new Listener[] {listenerFirst, listenerSecond};
+
+ try (var activator = new MessageDispatcherActivator(parameterGroup, publishers, listeners)) {
+
+ assertFalse(activator.isAlive());
+ activator.start();
+ assertTrue(activator.isAlive());
+
+ // repeat start - should throw an exception
+ assertThatIllegalStateException().isThrownBy(() -> activator.start());
+ assertTrue(activator.isAlive());
+ verify(publisherFirst, times(1)).active(anyList());
+ verify(publisherSecond, times(1)).active(anyList());
+
+ StandardCoderObject sco = CODER.decode("{messageType:" + TOPIC_FIRST + "}", StandardCoderObject.class);
+ activator.getMsgDispatcher().onTopicEvent(null, "msg", sco);
+ verify(listenerFirst, times(1)).onTopicEvent(any(), any(), any());
+
+ sco = CODER.decode("{messageType:" + TOPIC_SECOND + "}", StandardCoderObject.class);
+ activator.getMsgDispatcher().onTopicEvent(null, "msg", sco);
+ verify(listenerSecond, times(1)).onTopicEvent(any(), any(), any());
+
+ activator.stop();
+ assertFalse(activator.isAlive());
+
+ // repeat stop - should throw an exception
+ assertThatIllegalStateException().isThrownBy(() -> activator.stop());
+ assertFalse(activator.isAlive());
+ }
+ }
+}
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 b93bd0f0e..1d7a00b18 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
@@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -33,15 +33,21 @@ import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeExce
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantStatisticsProvider;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopStateChangePublisher;
+import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantControlLoopUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -79,9 +85,10 @@ class ControlLoopInstantiationProviderTest {
+ " item \"ControlLoop\" value \"org.onap.domain.PMSHControlLoopDefinition\" INVALID,"
+ " Commissioned control loop definition not FOUND\n";
- private static ClRuntimeParameterGroup controlLoopParameters;
private static SupervisionHandler supervisionHandler;
private static CommissioningProvider commissioningProvider;
+ private static ControlLoopProvider clProvider;
+ private static PolicyModelsProvider modelsProvider;
/**
* setup Db Provider Parameters.
@@ -90,12 +97,29 @@ class ControlLoopInstantiationProviderTest {
*/
@BeforeAll
public static void setupDbProviderParameters() throws PfModelException {
- controlLoopParameters = CommonTestData.geParameterGroup(0, "instantproviderdb");
- commissioningProvider = new CommissioningProvider(controlLoopParameters);
- var monitoringProvider = new MonitoringProvider(controlLoopParameters);
- supervisionHandler = new SupervisionHandler(controlLoopParameters, monitoringProvider, commissioningProvider);
- supervisionHandler.startProviders();
- supervisionHandler.startAndRegisterPublishers(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup(0, "instantproviderdb");
+
+ modelsProvider =
+ CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var participantStatisticsProvider =
+ new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var clElementStatisticsProvider =
+ new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
+ commissioningProvider = new CommissioningProvider(modelsProvider, clProvider);
+ var monitoringProvider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
+ var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var controlLoopUpdatePublisher = Mockito.mock(ParticipantControlLoopUpdatePublisher.class);
+ var controlLoopStateChangePublisher = Mockito.mock(ParticipantControlLoopStateChangePublisher.class);
+ supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
+ controlLoopUpdatePublisher, controlLoopStateChangePublisher);
+ }
+
+ @AfterAll
+ public static void closeDbProvider() throws PfModelException {
+ clProvider.close();
+ modelsProvider.close();
}
@Test
@@ -104,77 +128,75 @@ class ControlLoopInstantiationProviderTest {
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud");
ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // to validate control Loop, it needs to define ToscaServiceTemplate
+ InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
- InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
+ InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
- controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
- assertThat(controlLoopsDb.getControlLoopList()).isNotEmpty();
- assertThat(controlLoopsCreate).isEqualTo(controlLoopsDb);
-
- for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
- assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
- }
+ controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
+ assertThat(controlLoopsDb.getControlLoopList()).isNotEmpty();
+ assertThat(controlLoopsCreate).isEqualTo(controlLoopsDb);
- ControlLoops controlLoopsUpdate =
- InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_UPDATE_JSON, "Crud");
- assertThat(controlLoopsUpdate).isNotEqualTo(controlLoopsDb);
+ for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
+ assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
+ }
- instantiationResponse = instantiationProvider.updateControlLoops(controlLoopsUpdate);
- InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsUpdate);
+ ControlLoops controlLoopsUpdate =
+ InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_UPDATE_JSON, "Crud");
+ assertThat(controlLoopsUpdate).isNotEqualTo(controlLoopsDb);
- controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
- assertThat(controlLoopsDb.getControlLoopList()).isNotEmpty();
- assertThat(controlLoopsUpdate).isEqualTo(controlLoopsDb);
+ instantiationResponse = instantiationProvider.updateControlLoops(controlLoopsUpdate);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsUpdate);
- InstantiationCommand instantiationCommand =
- InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
- instantiationResponse = instantiationProvider.issueControlLoopCommand(instantiationCommand);
- InstantiationUtils.assertInstantiationResponse(instantiationResponse, instantiationCommand);
+ controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
+ assertThat(controlLoopsDb.getControlLoopList()).isNotEmpty();
+ assertThat(controlLoopsUpdate).isEqualTo(controlLoopsDb);
- for (ToscaConceptIdentifier toscaConceptIdentifier : instantiationCommand.getControlLoopIdentifierList()) {
- ControlLoops controlLoopsGet = instantiationProvider.getControlLoops(toscaConceptIdentifier.getName(),
- toscaConceptIdentifier.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
- assertThat(instantiationCommand.getOrderedState())
- .isEqualTo(controlLoopsGet.getControlLoopList().get(0).getOrderedState());
- }
+ InstantiationCommand instantiationCommand =
+ InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
+ instantiationResponse = instantiationProvider.issueControlLoopCommand(instantiationCommand);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, instantiationCommand);
- // in order to delete a controlLoop the state must be UNINITIALISED
- controlLoopsCreate.getControlLoopList().forEach(cl -> cl.setState(ControlLoopState.UNINITIALISED));
- instantiationProvider.updateControlLoops(controlLoopsCreate);
+ for (ToscaConceptIdentifier toscaConceptIdentifier : instantiationCommand.getControlLoopIdentifierList()) {
+ ControlLoops controlLoopsGet = instantiationProvider.getControlLoops(toscaConceptIdentifier.getName(),
+ toscaConceptIdentifier.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
+ assertThat(instantiationCommand.getOrderedState())
+ .isEqualTo(controlLoopsGet.getControlLoopList().get(0).getOrderedState());
+ }
- for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
- instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
- }
+ // in order to delete a controlLoop the state must be UNINITIALISED
+ controlLoopsCreate.getControlLoopList().forEach(cl -> cl.setState(ControlLoopState.UNINITIALISED));
+ instantiationProvider.updateControlLoops(controlLoopsCreate);
- controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
- assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
+ for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
+ instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
}
+
+ controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
+ assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
}
private ControlLoops getControlLoopsFromDb(ControlLoops controlLoopsSource) throws Exception {
ControlLoops controlLoopsDb = new ControlLoops();
controlLoopsDb.setControlLoopList(new ArrayList<>());
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- for (ControlLoop controlLoop : controlLoopsSource.getControlLoopList()) {
- ControlLoops controlLoopsFromDb =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- controlLoopsDb.getControlLoopList().addAll(controlLoopsFromDb.getControlLoopList());
- }
- return controlLoopsDb;
+ for (ControlLoop controlLoop : controlLoopsSource.getControlLoopList()) {
+ ControlLoops controlLoopsFromDb =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ controlLoopsDb.getControlLoopList().addAll(controlLoopsFromDb.getControlLoopList());
}
+ return controlLoopsDb;
}
@Test
@@ -185,37 +207,36 @@ class ControlLoopInstantiationProviderTest {
ControlLoop controlLoop0 = controlLoops.getControlLoopList().get(0);
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // to validate control Loop, it needs to define ToscaServiceTemplate
+ InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- assertThatThrownBy(
- () -> instantiationProvider.deleteControlLoop(controlLoop0.getName(), controlLoop0.getVersion()))
- .hasMessageMatching(CONTROL_LOOP_NOT_FOUND);
+ assertThatThrownBy(
+ () -> instantiationProvider.deleteControlLoop(controlLoop0.getName(), controlLoop0.getVersion()))
+ .hasMessageMatching(CONTROL_LOOP_NOT_FOUND);
- InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoops),
- controlLoops);
+ InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoops),
+ controlLoops);
- for (ControlLoopState state : ControlLoopState.values()) {
- if (!ControlLoopState.UNINITIALISED.equals(state)) {
- assertThatDeleteThrownBy(controlLoops, state);
- }
+ for (ControlLoopState state : ControlLoopState.values()) {
+ if (!ControlLoopState.UNINITIALISED.equals(state)) {
+ assertThatDeleteThrownBy(controlLoops, state);
}
+ }
- controlLoop0.setState(ControlLoopState.UNINITIALISED);
- instantiationProvider.updateControlLoops(controlLoops);
+ controlLoop0.setState(ControlLoopState.UNINITIALISED);
+ instantiationProvider.updateControlLoops(controlLoops);
- for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
- instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
- }
+ for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
+ instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
+ }
- for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
- }
+ for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
}
}
@@ -224,14 +245,13 @@ class ControlLoopInstantiationProviderTest {
controlLoop.setState(state);
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- instantiationProvider.updateControlLoops(controlLoops);
- assertThatThrownBy(
- () -> instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion()))
- .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
- }
+ instantiationProvider.updateControlLoops(controlLoops);
+ assertThatThrownBy(
+ () -> instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion()))
+ .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
}
@Test
@@ -242,21 +262,20 @@ class ControlLoopInstantiationProviderTest {
ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // to validate control Loop, it needs to define ToscaServiceTemplate
+ InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
- InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
+ InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
- assertThatThrownBy(() -> instantiationProvider.createControlLoops(controlLoopsCreate)).hasMessageMatching(
- controlLoopsCreate.getControlLoopList().get(0).getKey().asIdentifier() + " already defined");
+ assertThatThrownBy(() -> instantiationProvider.createControlLoops(controlLoopsCreate)).hasMessageMatching(
+ controlLoopsCreate.getControlLoopList().get(0).getKey().asIdentifier() + " already defined");
- for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
- instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
- }
+ for (ControlLoop controlLoop : controlLoopsCreate.getControlLoopList()) {
+ instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
}
}
@@ -265,17 +284,15 @@ class ControlLoopInstantiationProviderTest {
ControlLoops controlLoops = InstantiationUtils
.getControlLoopsFromResource(CL_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "ClElementNotFound");
- try (ControlLoopInstantiationProvider provider = new ControlLoopInstantiationProvider(controlLoopParameters,
- commissioningProvider, supervisionHandler)) {
+ var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // to validate control Loop, it needs to define ToscaServiceTemplate
+ InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
+ assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
- assertThatThrownBy(() -> provider.createControlLoops(controlLoops))
- .hasMessageMatching(CONTROLLOOP_ELEMENT_NAME_NOT_FOUND);
- }
+ assertThatThrownBy(() -> provider.createControlLoops(controlLoops))
+ .hasMessageMatching(CONTROLLOOP_ELEMENT_NAME_NOT_FOUND);
}
@Test
@@ -285,20 +302,17 @@ class ControlLoopInstantiationProviderTest {
assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
- try (ControlLoopInstantiationProvider provider = new ControlLoopInstantiationProvider(controlLoopParameters,
- commissioningProvider, supervisionHandler)) {
- assertThatThrownBy(() -> provider.createControlLoops(controlLoops))
- .hasMessageMatching(CONTROLLOOP_DEFINITION_NOT_FOUND);
- }
+ var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
+ assertThatThrownBy(() -> provider.createControlLoops(controlLoops))
+ .hasMessageMatching(CONTROLLOOP_DEFINITION_NOT_FOUND);
}
@Test
void testIssueControlLoopCommand_OrderedStateInvalid() throws ControlLoopRuntimeException, IOException {
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
- assertThatThrownBy(() -> instantiationProvider.issueControlLoopCommand(new InstantiationCommand()))
- .hasMessageMatching(ORDERED_STATE_INVALID);
- }
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
+ assertThatThrownBy(() -> instantiationProvider.issueControlLoopCommand(new InstantiationCommand()))
+ .hasMessageMatching(ORDERED_STATE_INVALID);
}
@Test
@@ -309,61 +323,60 @@ class ControlLoopInstantiationProviderTest {
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V1");
assertThat(getControlLoopsFromDb(controlLoopsV1).getControlLoopList()).isEmpty();
- try (ControlLoopInstantiationProvider instantiationProvider = new ControlLoopInstantiationProvider(
- controlLoopParameters, commissioningProvider, supervisionHandler)) {
+ var instantiationProvider =
+ new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // to validate control Loop, it needs to define ToscaServiceTemplate
+ InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV1),
- controlLoopsV1);
+ InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV1),
+ controlLoopsV1);
- // create controlLoops V2
- ControlLoops controlLoopsV2 =
- InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V2");
- assertThat(getControlLoopsFromDb(controlLoopsV2).getControlLoopList()).isEmpty();
- InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV2),
- controlLoopsV2);
+ // create controlLoops V2
+ ControlLoops controlLoopsV2 =
+ InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V2");
+ assertThat(getControlLoopsFromDb(controlLoopsV2).getControlLoopList()).isEmpty();
+ InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV2),
+ controlLoopsV2);
- // GET controlLoops V2
- for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
- assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
- }
+ // GET controlLoops V2
+ for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
+ assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
+ }
- // DELETE controlLoops V1
- for (ControlLoop controlLoop : controlLoopsV1.getControlLoopList()) {
- instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
- }
+ // DELETE controlLoops V1
+ for (ControlLoop controlLoop : controlLoopsV1.getControlLoopList()) {
+ instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
+ }
- // GET controlLoops V1 is not available
- for (ControlLoop controlLoop : controlLoopsV1.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
- }
+ // GET controlLoops V1 is not available
+ for (ControlLoop controlLoop : controlLoopsV1.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
+ }
- // GET controlLoops V2 is still available
- for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
- assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
- }
+ // GET controlLoops V2 is still available
+ for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
+ assertThat(controlLoop).isEqualTo(controlLoopsGet.getControlLoopList().get(0));
+ }
- // DELETE controlLoops V2
- for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
- instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
- }
+ // DELETE controlLoops V2
+ for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
+ instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion());
+ }
- // GET controlLoops V2 is not available
- for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
- ControlLoops controlLoopsGet =
- instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
- assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
- }
+ // GET controlLoops V2 is not available
+ for (ControlLoop controlLoop : controlLoopsV2.getControlLoopList()) {
+ ControlLoops controlLoopsGet =
+ instantiationProvider.getControlLoops(controlLoop.getName(), controlLoop.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
}
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivatorTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivatorTest.java
deleted file mode 100644
index 7eb567259..000000000
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/main/startstop/ClRuntimeActivatorTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.clamp.controlloop.runtime.main.startstop;
-
-import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-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.SupervisionHandler;
-
-/**
- * Class to perform unit test of {@link ClRuntimeActivator}}.
- *
- */
-class ClRuntimeActivatorTest {
-
- @Test
- void testStartAndStop() throws Exception {
- final String path = "src/test/resources/parameters/TestParameters.json";
- ClRuntimeParameterGroup parameterGroup = new ClRuntimeParameterHandler().getParameters(path);
- var supervisionHandler = Mockito.mock(SupervisionHandler.class);
-
- try (var activator = new ClRuntimeActivator(parameterGroup, supervisionHandler)) {
-
- assertFalse(activator.isAlive());
- activator.start();
- assertTrue(activator.isAlive());
- assertTrue(activator.getParameterGroup().isValid());
-
- // repeat start - should throw an exception
- assertThatIllegalStateException().isThrownBy(() -> activator.start());
- assertTrue(activator.isAlive());
- assertTrue(activator.getParameterGroup().isValid());
-
- activator.stop();
- assertFalse(activator.isAlive());
-
- // repeat stop - should throw an exception
- assertThatIllegalStateException().isThrownBy(() -> activator.stop());
- assertFalse(activator.isAlive());
- }
- }
-}
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 580b30f9e..c47211a2d 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
@@ -23,15 +23,15 @@ package org.onap.policy.clamp.controlloop.runtime.monitoring;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import java.io.File;
-import java.lang.reflect.Field;
import java.time.Instant;
-import java.util.ArrayList;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -39,7 +39,9 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementSt
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantStatisticsProvider;
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;
@@ -59,14 +61,16 @@ class TestMonitoringProvider {
"src/test/resources/rest/monitoring/TestClElementStatistics_Invalid.json";
private static final Coder CODER = new StandardCoder();
- private static final String CL_PROVIDER_FIELD = "controlLoopProvider";
-
private static final String LIST_IS_NULL = ".*StatisticsList is marked .*ull but is null";
private static ParticipantStatisticsList inputParticipantStatistics;
private static ParticipantStatisticsList invalidParticipantInput;
private static ClElementStatisticsList inputClElementStatistics;
private static ClElementStatisticsList invalidClElementInput;
+ private ParticipantStatisticsProvider participantStatisticsProvider = null;
+ private ClElementStatisticsProvider clElementStatisticsProvider = null;
+ private ControlLoopProvider clProvider = null;
+
@BeforeAll
public static void beforeSetupStatistics() throws CoderException {
// Reading input json for statistics data
@@ -78,141 +82,167 @@ class TestMonitoringProvider {
invalidClElementInput = CODER.decode(new File(INVALID_CL_ELEMENT_JSON_INPUT), ClElementStatisticsList.class);
}
+ @AfterEach
+ void close() throws Exception {
+ if (participantStatisticsProvider != null) {
+ participantStatisticsProvider.close();
+ }
+ if (clElementStatisticsProvider != null) {
+ clElementStatisticsProvider.close();
+ }
+ if (clProvider != null) {
+ clProvider.close();
+ }
+ }
+
@Test
void testCreateParticipantStatistics() throws Exception {
ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createparStat");
-
- try (MonitoringProvider provider = new MonitoringProvider(parameters)) {
- // Creating statistics data in db with null input
- assertThatThrownBy(() -> {
- provider.createParticipantStatistics(null);
- }).hasMessageMatching(LIST_IS_NULL);
-
- assertThatThrownBy(() -> {
- provider.createParticipantStatistics(invalidParticipantInput.getStatisticsList());
- }).hasMessageMatching("participantStatisticsList is marked .*null but is null");
-
- // Creating statistics data from input json
- ParticipantStatisticsList createResponse =
- provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
-
- assertThat(createResponse.getStatisticsList()).hasSize(3);
- assertEquals(createResponse.getStatisticsList().toString().replaceAll("\\s+", ""),
- inputParticipantStatistics.getStatisticsList().toString().replaceAll("\\s+", ""));
- }
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
+ MonitoringProvider provider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
+ // Creating statistics data in db with null input
+ assertThatThrownBy(() -> {
+ provider.createParticipantStatistics(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ provider.createParticipantStatistics(invalidParticipantInput.getStatisticsList());
+ }).hasMessageMatching("participantStatisticsList is marked .*null but is null");
+
+ // Creating statistics data from input json
+ ParticipantStatisticsList createResponse =
+ provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
+
+ assertThat(createResponse.getStatisticsList()).hasSize(3);
+ assertEquals(createResponse.getStatisticsList().toString().replaceAll("\\s+", ""),
+ inputParticipantStatistics.getStatisticsList().toString().replaceAll("\\s+", ""));
}
@Test
void testGetParticipantStatistics() throws Exception {
ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStat");
- try (MonitoringProvider provider = new MonitoringProvider(parameters)) {
- ParticipantStatisticsList getResponse;
-
- provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
-
- assertThatThrownBy(() -> {
- provider.fetchFilteredParticipantStatistics(null, null, 0, null, null);
- }).hasMessageMatching("name is marked .*null but is null");
-
- // Fetch specific statistics record with name, version and record count
- getResponse = provider.fetchFilteredParticipantStatistics("name2", "1.001", 1, null, null);
- assertThat(getResponse.getStatisticsList()).hasSize(1);
- assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
- inputParticipantStatistics.getStatisticsList().get(2).toString().replaceAll("\\s+", ""));
-
- // Fetch statistics using timestamp
- getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0, null,
- Instant.parse("2021-01-10T15:00:00.000Z"));
- assertThat(getResponse.getStatisticsList()).hasSize(1);
-
- getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0,
- Instant.parse("2021-01-11T12:00:00.000Z"), Instant.parse("2021-01-11T16:00:00.000Z"));
-
- assertThat(getResponse.getStatisticsList()).isEmpty();
- }
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
+ MonitoringProvider provider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
+
+ provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
+
+ assertThatThrownBy(() -> {
+ provider.fetchFilteredParticipantStatistics(null, null, 0, null, null);
+ }).hasMessageMatching("name is marked .*null but is null");
+
+ // Fetch specific statistics record with name, version and record count
+ ParticipantStatisticsList getResponse =
+ provider.fetchFilteredParticipantStatistics("name2", "1.001", 1, null, null);
+ assertThat(getResponse.getStatisticsList()).hasSize(1);
+ assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
+ inputParticipantStatistics.getStatisticsList().get(2).toString().replaceAll("\\s+", ""));
+
+ // Fetch statistics using timestamp
+ getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0, null,
+ Instant.parse("2021-01-10T15:00:00.000Z"));
+ assertThat(getResponse.getStatisticsList()).hasSize(1);
+
+ getResponse = provider.fetchFilteredParticipantStatistics("name1", "1.001", 0,
+ Instant.parse("2021-01-11T12:00:00.000Z"), Instant.parse("2021-01-11T16:00:00.000Z"));
+
+ assertThat(getResponse.getStatisticsList()).isEmpty();
}
@Test
void testCreateClElementStatistics() throws Exception {
ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "createelemstat");
-
- try (MonitoringProvider provider = new MonitoringProvider(parameters)) {
- // Creating statistics data in db with null input
- assertThatThrownBy(() -> {
- provider.createClElementStatistics(null);
- }).hasMessageMatching(LIST_IS_NULL);
-
- assertThatThrownBy(() -> {
- provider.createClElementStatistics(invalidClElementInput.getClElementStatistics());
- }).hasMessageMatching("clElementStatisticsList is marked .*null but is null");
-
- // Creating clElement statistics data from input json
- ClElementStatisticsList createResponse =
- provider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
-
- assertThat(createResponse.getClElementStatistics()).hasSize(4);
- assertEquals(createResponse.getClElementStatistics().toString().replaceAll("\\s+", ""),
- inputClElementStatistics.getClElementStatistics().toString().replaceAll("\\s+", ""));
- }
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
+
+ MonitoringProvider provider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
+ // Creating statistics data in db with null input
+ assertThatThrownBy(() -> {
+ provider.createClElementStatistics(null);
+ }).hasMessageMatching(LIST_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ provider.createClElementStatistics(invalidClElementInput.getClElementStatistics());
+ }).hasMessageMatching("clElementStatisticsList is marked .*null but is null");
+
+ // Creating clElement statistics data from input json
+ ClElementStatisticsList createResponse =
+ provider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
+
+ assertThat(createResponse.getClElementStatistics()).hasSize(4);
+ assertEquals(createResponse.getClElementStatistics().toString().replaceAll("\\s+", ""),
+ inputClElementStatistics.getClElementStatistics().toString().replaceAll("\\s+", ""));
}
@Test
void testGetClElementStatistics() throws Exception {
ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstat");
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clProvider = new ControlLoopProvider(parameters.getDatabaseProviderParameters());
- try (MonitoringProvider provider = new MonitoringProvider(parameters)) {
- ClElementStatisticsList getResponse;
+ MonitoringProvider provider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
- assertThatThrownBy(() -> {
- provider.fetchFilteredClElementStatistics(null, null, null, null, null, 0);
- }).hasMessageMatching("name is marked .*null but is null");
+ assertThatThrownBy(() -> {
+ provider.fetchFilteredClElementStatistics(null, null, null, null, null, 0);
+ }).hasMessageMatching("name is marked .*null but is null");
- provider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
+ provider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- getResponse = provider.fetchFilteredClElementStatistics("name1", null, null, null, null, 0);
+ ClElementStatisticsList getResponse =
+ provider.fetchFilteredClElementStatistics("name1", null, null, null, null, 0);
- assertThat(getResponse.getClElementStatistics()).hasSize(2);
- assertEquals(getResponse.getClElementStatistics().get(0).toString().replaceAll("\\s+", ""),
- inputClElementStatistics.getClElementStatistics().get(0).toString().replaceAll("\\s+", ""));
+ assertThat(getResponse.getClElementStatistics()).hasSize(2);
+ assertEquals(getResponse.getClElementStatistics().get(0).toString().replaceAll("\\s+", ""),
+ inputClElementStatistics.getClElementStatistics().get(0).toString().replaceAll("\\s+", ""));
- // Fetch specific statistics record with name, id and record count
- getResponse = provider.fetchFilteredClElementStatistics("name1", "1.001",
- "709c62b3-8918-41b9-a747-d21eb79c6c20", null, null, 0);
- assertThat(getResponse.getClElementStatistics()).hasSize(2);
+ // Fetch specific statistics record with name, id and record count
+ getResponse = provider.fetchFilteredClElementStatistics("name1", "1.001",
+ "709c62b3-8918-41b9-a747-d21eb79c6c20", null, null, 0);
+ assertThat(getResponse.getClElementStatistics()).hasSize(2);
- // Fetch statistics using timestamp
- getResponse = provider.fetchFilteredClElementStatistics("name1", "1.001", null,
- Instant.parse("2021-01-10T13:45:00.000Z"), null, 0);
- assertThat(getResponse.getClElementStatistics()).hasSize(2);
- }
+ // Fetch statistics using timestamp
+ getResponse = provider.fetchFilteredClElementStatistics("name1", "1.001", null,
+ Instant.parse("2021-01-10T13:45:00.000Z"), null, 0);
+ assertThat(getResponse.getClElementStatistics()).hasSize(2);
}
@Test
void testGetParticipantStatsPerCL() throws Exception {
ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getparStatCL");
-
- try (MonitoringProvider provider = Mockito.spy(new MonitoringProvider(parameters))) {
-
- provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
- // Mock the response for fetching participant conceptIdentifiers per control loop
- List<ToscaConceptIdentifier> conceptIdentifiers = new ArrayList<>();
- conceptIdentifiers.add(new ToscaConceptIdentifier("name1", "1.001"));
- when(provider.getAllParticipantIdsPerControlLoop("testName", "1.001")).thenReturn(conceptIdentifiers);
- ParticipantStatisticsList getResponse;
- getResponse = provider.fetchParticipantStatsPerControlLoop("testName", "1.001");
- assertThat(getResponse.getStatisticsList()).hasSize(2);
- assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
- inputParticipantStatistics.getStatisticsList().get(0).toString().replaceAll("\\s+", ""));
- assertThat(provider.fetchParticipantStatsPerControlLoop("invalidCLName", "1.002").getStatisticsList())
- .isEmpty();
- }
-
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
+ var mockClProvider = Mockito.mock(ControlLoopProvider.class);
+ var provider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, mockClProvider);
+
+ provider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
+
+ var controlLoop = new ControlLoop();
+ var element = new ControlLoopElement();
+ element.setParticipantId(new ToscaConceptIdentifier("name1", "1.001"));
+ controlLoop.setElements(Map.of(UUID.randomUUID(), element));
+ when(mockClProvider.getControlLoop(eq(new ToscaConceptIdentifier("testName", "1.001"))))
+ .thenReturn(controlLoop);
+
+ ParticipantStatisticsList getResponse = provider.fetchParticipantStatsPerControlLoop("testName", "1.001");
+ assertThat(getResponse.getStatisticsList()).hasSize(2);
+ assertEquals(getResponse.getStatisticsList().get(0).toString().replaceAll("\\s+", ""),
+ inputParticipantStatistics.getStatisticsList().get(0).toString().replaceAll("\\s+", ""));
+ assertThat(provider.fetchParticipantStatsPerControlLoop("invalidCLName", "1.002").getStatisticsList())
+ .isEmpty();
}
@Test
void testClElementStatsPerCL() throws Exception {
- ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstatPerCL");
-
// Setup a dummy Control loop data
ControlLoopElement mockClElement = new ControlLoopElement();
mockClElement.setId(inputClElementStatistics.getClElementStatistics().get(0).getId());
@@ -223,30 +253,32 @@ class TestMonitoringProvider {
mockCL.setElements(new LinkedHashMap<>());
mockCL.getElements().put(mockClElement.getId(), mockClElement);
- // Mock controlloop data to be returned for the given CL Id
+ ClRuntimeParameterGroup parameters = CommonTestData.geParameterGroup(0, "getelemstatPerCL");
+ participantStatisticsProvider = new ParticipantStatisticsProvider(parameters.getDatabaseProviderParameters());
+ clElementStatisticsProvider = new ClElementStatisticsProvider(parameters.getDatabaseProviderParameters());
ControlLoopProvider mockClProvider = Mockito.mock(ControlLoopProvider.class);
+ var monitoringProvider =
+ new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, mockClProvider);
+
+ // Mock controlloop data to be returned for the given CL Id
when(mockClProvider.getControlLoop(new ToscaConceptIdentifier("testCLName", "1.001"))).thenReturn(mockCL);
- try (MonitoringProvider monitoringProvider = new MonitoringProvider(parameters)) {
- monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- Field controlLoopProviderField = monitoringProvider.getClass().getDeclaredField(CL_PROVIDER_FIELD);
- controlLoopProviderField.setAccessible(true);
- controlLoopProviderField.set(monitoringProvider, mockClProvider);
+ monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- ClElementStatisticsList getResponse;
- getResponse = monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
+ ClElementStatisticsList getResponse;
+ getResponse = monitoringProvider.fetchClElementStatsPerControlLoop("testCLName", "1.001");
- assertThat(getResponse.getClElementStatistics()).hasSize(2);
- assertEquals(getResponse.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""),
- inputClElementStatistics.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""));
+ assertThat(getResponse.getClElementStatistics()).hasSize(2);
+ assertEquals(getResponse.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""),
+ inputClElementStatistics.getClElementStatistics().get(1).toString().replaceAll("\\s+", ""));
- assertThat(monitoringProvider.fetchClElementStatsPerControlLoop("invalidCLName", "1.002")
- .getClElementStatistics()).isEmpty();
+ assertThat(
+ monitoringProvider.fetchClElementStatsPerControlLoop("invalidCLName", "1.002").getClElementStatistics())
+ .isEmpty();
- Map<String, ToscaConceptIdentifier> clElementIds =
- monitoringProvider.getAllClElementsIdPerControlLoop("testCLName", "1.001");
- assertThat(clElementIds)
- .containsKey(inputClElementStatistics.getClElementStatistics().get(0).getId().toString());
- }
+ Map<String, ToscaConceptIdentifier> clElementIds =
+ monitoringProvider.getAllClElementsIdPerControlLoop("testCLName", "1.001");
+ assertThat(clElementIds)
+ .containsKey(inputClElementStatistics.getClElementStatistics().get(0).getId().toString());
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
index 95b2113cd..77742aea9 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/rest/MonitoringQueryControllerTest.java
@@ -34,7 +34,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
-import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
import org.onap.policy.common.utils.coder.Coder;
@@ -70,7 +69,7 @@ class MonitoringQueryControllerTest extends CommonRestController {
private static final String CLELEMENT_STATS_PER_CL_ENDPOINT = "monitoring/clelements/controlloop";
@Autowired
- private ClRuntimeParameterGroup clRuntimeParameterGroup;
+ private MonitoringProvider monitoringProvider;
@LocalServerPort
private int randomServerPort;
@@ -92,14 +91,12 @@ class MonitoringQueryControllerTest extends CommonRestController {
public void setUpBeforeEach() throws Exception {
super.setHttpPrefix(randomServerPort);
- try (var monitoringProvider = new MonitoringProvider(clRuntimeParameterGroup)) {
- // Insert Participant statistics to DB
- participantStatisticsList =
- monitoringProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
- // Insert CL Element statistics to DB
- clElementStatisticsList =
- monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
- }
+ // Insert Participant statistics to DB
+ participantStatisticsList =
+ monitoringProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList());
+ // Insert CL Element statistics to DB
+ clElementStatisticsList =
+ monitoringProvider.createClElementStatistics(inputClElementStatistics.getClElementStatistics());
}
@Test
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 aa17e9c4f..464c14354 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
@@ -27,6 +27,11 @@ 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.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
/**
* Class to hold/create all parameters for test cases.
@@ -63,4 +68,19 @@ public class CommonTestData {
return ResourceUtils.getResourceAsString("src/test/resources/parameters/InstantiationConfigParametersStd.json")
.replace("${port}", String.valueOf(port)).replace("${dbName}", "jdbc:h2:mem:" + dbName);
}
+
+ /**
+ * Create a new PolicyModelsProvider.
+ *
+ * @param databaseProviderParameters the database Provider Parameters
+ * @return a new PolicyModelsProvider
+ */
+ public static PolicyModelsProvider getPolicyModelsProvider(
+ PolicyModelsProviderParameters databaseProviderParameters) {
+ try {
+ return new PolicyModelsProviderFactory().createPolicyModelsProvider(databaseProviderParameters);
+ } catch (PfModelException e) {
+ throw new PfModelRuntimeException(e);
+ }
+ }
}
diff --git a/runtime-controlloop/src/test/resources/parameters/TestParameters.json b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
index 9bcd764cb..680e070f2 100644
--- a/runtime-controlloop/src/test/resources/parameters/TestParameters.json
+++ b/runtime-controlloop/src/test/resources/parameters/TestParameters.json
@@ -50,13 +50,6 @@
"localhost"
],
"topicCommInfrastructure": "dmaap"
- },
- {
- "topic": "POLICY-NOTIFICATION",
- "servers": [
- "localhost"
- ],
- "topicCommInfrastructure": "dmaap"
}
]
}