aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop/src/test
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-11-25 10:54:56 +0000
committerGerrit Code Review <gerrit@onap.org>2021-11-25 10:54:56 +0000
commit7aec29b8f64f15c838d8946532ff32aeb9f6fb96 (patch)
treecb0994e197b918f2b8a3e12789c33ad732453bf1 /runtime-controlloop/src/test
parent0d622ac3879f6a49450da4f390c79803cd28dc0b (diff)
parent0574c7df7944828a7e8a03c1eacf93605c43b154 (diff)
Merge "Add support transaction in ParticipantProvider"
Diffstat (limited to 'runtime-controlloop/src/test')
-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
6 files changed, 41 insertions, 35 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 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 ece676a71..5ed4a4fc0 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;
@@ -162,8 +163,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());
@@ -177,7 +178,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantDeregisterMessage);
- verify(participantProvider).updateParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
@@ -201,7 +202,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantRegisterMessage);
- verify(participantProvider).createParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), participantId,
participantType);
}
@@ -214,8 +215,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);
@@ -228,7 +229,7 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantUpdateAckMessage);
- verify(participantProvider).updateParticipants(anyList());
+ verify(participantProvider).saveParticipant(any());
}
@Test
@@ -248,7 +249,7 @@ class SupervisionHandlerTest {
ControlLoopOrderedState.PASSIVE);
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);