summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-controlloop/src')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java13
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java2
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java47
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java5
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java19
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java19
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java5
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java17
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java14
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java2
10 files changed, 71 insertions, 72 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
index d055ba266..eac1ac305 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
@@ -104,7 +104,7 @@ public class CommissioningProvider {
synchronized (lockit) {
serviceTemplateProvider.createServiceTemplate(serviceTemplate);
- List<Participant> participantList = participantProvider.getParticipants(null, null);
+ List<Participant> participantList = participantProvider.getParticipants();
if (!participantList.isEmpty()) {
supervisionHandler.handleSendCommissionMessage(serviceTemplate.getName(), serviceTemplate.getVersion());
}
@@ -137,7 +137,7 @@ public class CommissioningProvider {
}
synchronized (lockit) {
- List<Participant> participantList = participantProvider.getParticipants(null, null);
+ List<Participant> participantList = participantProvider.getParticipants();
if (!participantList.isEmpty()) {
supervisionHandler.handleSendDeCommissionMessage();
}
@@ -145,8 +145,7 @@ public class CommissioningProvider {
}
var response = new CommissioningResponse();
- response.setAffectedControlLoopDefinitions(
- Collections.singletonList(new ToscaConceptIdentifier(name, version)));
+ response.setAffectedControlLoopDefinitions(List.of(new ToscaConceptIdentifier(name, version)));
return response;
}
@@ -262,13 +261,11 @@ public class CommissioningProvider {
* @return the tosca service template
* @throws PfModelException on errors getting tosca service template
*/
- public String getToscaServiceTemplateReduced(String name, String version)
- throws PfModelException {
+ public String getToscaServiceTemplateReduced(String name, String version) throws PfModelException {
var serviceTemplateList = serviceTemplateProvider.getServiceTemplateList(name, version);
- List<ToscaServiceTemplate> filteredServiceTemplateList = filterToscaNodeTemplateInstance(
- serviceTemplateList);
+ List<ToscaServiceTemplate> filteredServiceTemplateList = filterToscaNodeTemplateInstance(serviceTemplateList);
if (filteredServiceTemplateList.isEmpty()) {
throw new PfModelException(Status.BAD_REQUEST, "Invalid Service Template");
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
index 98ceacc3a..40d9b249d 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
@@ -350,7 +350,7 @@ public class ControlLoopInstantiationProvider {
}
synchronized (lockit) {
- var participants = participantProvider.getParticipants(null, null);
+ var participants = participantProvider.getParticipants();
if (participants.isEmpty()) {
throw new ControlLoopException(Status.BAD_REQUEST, "No participants registered");
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index f011d9392..7f0b85588 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -174,16 +174,15 @@ public class SupervisionHandler {
public void handleParticipantMessage(ParticipantDeregister participantDeregisterMessage) {
LOGGER.debug("Participant Deregister received {}", participantDeregisterMessage);
try {
- var participantList =
- participantProvider.getParticipants(participantDeregisterMessage.getParticipantId().getName(),
+ var participantOpt =
+ participantProvider.findParticipant(participantDeregisterMessage.getParticipantId().getName(),
participantDeregisterMessage.getParticipantId().getVersion());
- if (participantList != null) {
- for (Participant participant : participantList) {
- participant.setParticipantState(ParticipantState.TERMINATED);
- participant.setHealthStatus(ParticipantHealthStatus.OFF_LINE);
- }
- participantProvider.updateParticipants(participantList);
+ if (participantOpt.isPresent()) {
+ var participant = participantOpt.get();
+ participant.setParticipantState(ParticipantState.TERMINATED);
+ participant.setHealthStatus(ParticipantHealthStatus.OFF_LINE);
+ participantProvider.saveParticipant(participant);
}
} catch (PfModelException pfme) {
LOGGER.warn("Model exception occured with participant id {}",
@@ -202,15 +201,14 @@ public class SupervisionHandler {
public void handleParticipantMessage(ParticipantUpdateAck participantUpdateAckMessage) {
LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage);
try {
- var participantList =
- participantProvider.getParticipants(participantUpdateAckMessage.getParticipantId().getName(),
+ var participantOpt =
+ participantProvider.findParticipant(participantUpdateAckMessage.getParticipantId().getName(),
participantUpdateAckMessage.getParticipantId().getVersion());
- if (participantList != null) {
- for (Participant participant : participantList) {
- participant.setParticipantState(participantUpdateAckMessage.getState());
- }
- participantProvider.updateParticipants(participantList);
+ if (participantOpt.isPresent()) {
+ var participant = participantOpt.get();
+ participant.setParticipantState(participantUpdateAckMessage.getState());
+ participantProvider.saveParticipant(participant);
} else {
LOGGER.warn("Participant not found in database {}", participantUpdateAckMessage.getParticipantId());
}
@@ -439,10 +437,10 @@ public class SupervisionHandler {
if (participantMessage.getParticipantId() == null) {
exceptionOccured(Response.Status.NOT_FOUND, "Participant ID on PARTICIPANT_STATUS message is null");
}
- List<Participant> participantList = participantProvider.getParticipants(
- participantMessage.getParticipantId().getName(), participantMessage.getParticipantId().getVersion());
+ var participantOpt = participantProvider.findParticipant(participantMessage.getParticipantId().getName(),
+ participantMessage.getParticipantId().getVersion());
- if (CollectionUtils.isEmpty(participantList)) {
+ if (participantOpt.isEmpty()) {
var participant = new Participant();
participant.setName(participantMessage.getParticipantId().getName());
participant.setVersion(participantMessage.getParticipantId().getVersion());
@@ -451,14 +449,13 @@ public class SupervisionHandler {
participant.setParticipantState(participantState);
participant.setHealthStatus(healthStatus);
- participantList.add(participant);
- participantProvider.createParticipants(participantList);
+ participantProvider.saveParticipant(participant);
} else {
- for (Participant participant : participantList) {
- participant.setParticipantState(participantState);
- participant.setHealthStatus(healthStatus);
- }
- participantProvider.updateParticipants(participantList);
+ var participant = participantOpt.get();
+ participant.setParticipantState(participantState);
+ participant.setHealthStatus(healthStatus);
+
+ participantProvider.saveParticipant(participant);
}
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
index 900a117bd..5ebacdac7 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
@@ -23,7 +23,6 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
@@ -121,7 +120,7 @@ public class SupervisionScanner {
if (counterCheck) {
try {
- for (Participant participant : participantProvider.getParticipants(null, null)) {
+ for (var participant : participantProvider.getParticipants()) {
scanParticipantStatus(participant);
}
} catch (PfModelException pfme) {
@@ -188,7 +187,7 @@ public class SupervisionScanner {
participantStatusCounter.setFault(id);
participant.setHealthStatus(ParticipantHealthStatus.OFF_LINE);
}
- participantProvider.updateParticipants(List.of(participant));
+ participantProvider.saveParticipant(participant);
}
}
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 3fd74f22e..22fb51cb5 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
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.controlloop.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
@@ -63,7 +64,6 @@ class CommissioningProviderTest {
private ControlLoopProvider clProvider = null;
private static final Coder CODER = new StandardCoder();
private final ObjectMapper mapper = new ObjectMapper();
- private ParticipantProvider participantProvider;
@AfterEach
void close() throws Exception {
@@ -73,9 +73,6 @@ class CommissioningProviderTest {
if (clProvider != null) {
clProvider.close();
}
- if (participantProvider != null) {
- participantProvider.close();
- }
}
/**
@@ -89,7 +86,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -127,7 +124,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -157,7 +154,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -186,7 +183,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -215,7 +212,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -261,7 +258,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
@@ -290,7 +287,7 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
CommissioningProvider provider = new CommissioningProvider(new ServiceTemplateProvider(modelsProvider),
clProvider, null, participantProvider);
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 564109e5d..caad5a4e9 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
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
@@ -105,7 +106,6 @@ class ControlLoopInstantiationProviderTest {
private static CommissioningProvider commissioningProvider;
private static ControlLoopProvider clProvider;
private static PolicyModelsProvider modelsProvider;
- private static ParticipantProvider participantProvider;
@BeforeAll
public static void setUpBeforeClass() throws Exception {
@@ -123,7 +123,7 @@ class ControlLoopInstantiationProviderTest {
modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
- participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var participantStatisticsProvider = Mockito.mock(ParticipantStatisticsProvider.class);
var clElementStatisticsProvider = mock(ClElementStatisticsProvider.class);
@@ -131,7 +131,6 @@ class ControlLoopInstantiationProviderTest {
participantProvider);
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
- var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
var controlLoopUpdatePublisher = Mockito.mock(ControlLoopUpdatePublisher.class);
var controlLoopStateChangePublisher = Mockito.mock(ControlLoopStateChangePublisher.class);
var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
@@ -162,6 +161,7 @@ class ControlLoopInstantiationProviderTest {
@Test
void testIntanceResponses() throws PfModelException {
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
var instancePropertyList = instantiationProvider.createInstanceProperties(serviceTemplate);
@@ -180,7 +180,9 @@ class ControlLoopInstantiationProviderTest {
@Test
void testInstantiationCrud() throws Exception {
- participantProvider.createParticipants(CommonTestData.createParticipants());
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
+ var participants = CommonTestData.createParticipants();
+ when(participantProvider.getParticipants()).thenReturn(participants);
ControlLoops controlLoopsCreate =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud");
@@ -242,6 +244,7 @@ class ControlLoopInstantiationProviderTest {
ControlLoops controlLoopsDb = new ControlLoops();
controlLoopsDb.setControlLoopList(new ArrayList<>());
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
@@ -262,6 +265,7 @@ class ControlLoopInstantiationProviderTest {
assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
ControlLoop controlLoop0 = controlLoops.getControlLoopList().get(0);
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
@@ -295,8 +299,8 @@ class ControlLoopInstantiationProviderTest {
private void assertThatDeleteThrownBy(ControlLoops controlLoops, ControlLoopState state) throws Exception {
ControlLoop controlLoop = controlLoops.getControlLoopList().get(0);
-
controlLoop.setState(state);
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
@@ -316,6 +320,7 @@ class ControlLoopInstantiationProviderTest {
ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
@@ -336,6 +341,7 @@ class ControlLoopInstantiationProviderTest {
ControlLoops controlLoops = InstantiationUtils
.getControlLoopsFromResource(CL_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "ClElementNotFound");
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler,
participantProvider);
@@ -355,6 +361,7 @@ class ControlLoopInstantiationProviderTest {
assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler,
participantProvider);
assertThatThrownBy(() -> provider.createControlLoops(controlLoops))
@@ -363,6 +370,7 @@ class ControlLoopInstantiationProviderTest {
@Test
void testIssueControlLoopCommand_OrderedStateInvalid() throws ControlLoopRuntimeException, IOException {
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
assertThatThrownBy(() -> instantiationProvider.issueControlLoopCommand(new InstantiationCommand()))
@@ -376,6 +384,7 @@ class ControlLoopInstantiationProviderTest {
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V1");
assertThat(getControlLoopsFromDb(controlLoopsV1).getControlLoopList()).isEmpty();
+ var participantProvider = Mockito.mock(ParticipantProvider.class);
var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider,
supervisionHandler, participantProvider);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
index e361ff469..0fc473106 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -326,7 +326,10 @@ class InstantiationControllerTest extends CommonRestController {
var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Command");
instantiationProvider.createControlLoops(controlLoops);
- participantProvider.createParticipants(CommonTestData.createParticipants());
+ var participants = CommonTestData.createParticipants();
+ for (var participant : participants) {
+ participantProvider.saveParticipant(participant);
+ }
InstantiationCommand command =
InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON, "Command");
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
index a314b30a0..abaa52c12 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -136,8 +137,8 @@ class SupervisionHandlerTest {
participant.setParticipantType(participantType);
var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants(participantId.getName(), participantId.getVersion()))
- .thenReturn(List.of(participant));
+ when(participantProvider.findParticipant(participantId.getName(), participantId.getVersion()))
+ .thenReturn(Optional.of(participant));
var participantDeregisterMessage = new ParticipantDeregister();
participantDeregisterMessage.setMessageId(UUID.randomUUID());
@@ -151,7 +152,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantDeregisterMessage);
- verify(participantProvider).updateParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
@@ -175,7 +176,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantRegisterMessage);
- verify(participantProvider).createParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), participantId,
participantType);
}
@@ -188,8 +189,8 @@ class SupervisionHandlerTest {
participant.setParticipantType(participantType);
var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants(participantId.getName(), participantId.getVersion()))
- .thenReturn(List.of(participant));
+ when(participantProvider.findParticipant(participantId.getName(), participantId.getVersion()))
+ .thenReturn(Optional.of(participant));
var participantUpdateAckMessage = new ParticipantUpdateAck();
participantUpdateAckMessage.setParticipantId(participantId);
@@ -202,7 +203,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantUpdateAckMessage);
- verify(participantProvider).updateParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
}
@Test
@@ -221,7 +222,7 @@ class SupervisionHandlerTest {
mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class));
handler.handleParticipantMessage(participantStatusMessage);
- verify(participantProvider).createParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
verify(monitoringProvider).createParticipantStatistics(anyList());
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
index 50672a84e..62029f009 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
@@ -20,7 +20,6 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -192,8 +191,8 @@ class SupervisionScannerTest {
participant.setParticipantState(ParticipantState.ACTIVE);
participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0"));
participant.setParticipantType(new ToscaConceptIdentifier("ParticipantType1", "1.0.0"));
- var participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- participantProvider.updateParticipants(List.of(participant));
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.getParticipants()).thenReturn(List.of(participant));
var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
@@ -206,13 +205,10 @@ class SupervisionScannerTest {
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
- verify(participantStatusReqPublisher, times(1)).send(any(ToscaConceptIdentifier.class));
-
- List<Participant> participants = participantProvider.getParticipants(null, null);
- assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.NOT_HEALTHY);
+ verify(participantStatusReqPublisher).send(any(ToscaConceptIdentifier.class));
+ verify(participantProvider).saveParticipant(any());
supervisionScanner.run(true);
- participants = participantProvider.getParticipants(null, null);
- assertThat(participants.get(0).getHealthStatus()).isEqualTo(ParticipantHealthStatus.OFF_LINE);
+ verify(participantProvider, times(2)).saveParticipant(any());
}
}
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 93433f59c..b64bd9fbe 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
@@ -80,7 +80,7 @@ class SupervisionMessagesTest extends CommonRestController {
var clElementStatisticsProvider = mock(ClElementStatisticsProvider.class);
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
- var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+ var participantProvider = mock(ParticipantProvider.class);
var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
var controlLoopUpdatePublisher = Mockito.mock(ControlLoopUpdatePublisher.class);
var controlLoopStateChangePublisher = Mockito.mock(ControlLoopStateChangePublisher.class);