aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-06-14 10:24:11 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2024-06-14 09:45:47 +0000
commit8c76c17a2d589d4e94571f4b6dce40261c0bb62d (patch)
tree7c6860eac2b8aaa4b411dc4d5636462ce71a2ad2 /models
parentb52e095b34ee7c576f7ee83df05e2a09366a8c8a (diff)
Add ParticipantReplica repository in ACM
Add ParticipantReplica repository in ACM, and align topics in properties files. Issue-ID: POLICY-5045 Change-Id: I283abf91db6264c7b08c51e6ad37736dca147180 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java1
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java10
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java65
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantReplicaRepository.java33
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java1
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java133
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java6
8 files changed, 225 insertions, 27 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java
index 3f0dff2bb..3d1b5df33 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java
@@ -44,6 +44,8 @@ public class AcElementRestart {
@NonNull
private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private UUID participantId;
+
// State of the AutomationCompositionElement
private DeployState deployState;
@@ -69,6 +71,7 @@ public class AcElementRestart {
public AcElementRestart(final AcElementRestart otherElement) {
this.id = otherElement.id;
this.definition = new ToscaConceptIdentifier(otherElement.definition);
+ this.participantId = otherElement.participantId;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
this.operationalState = otherElement.operationalState;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
index 119cdf030..98c7d1071 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
@@ -66,6 +66,7 @@ public class ParticipantRestart extends ParticipantMessage {
*/
public ParticipantRestart(ParticipantRestart source) {
super(source);
+ this.state = source.state;
this.participantDefinitionUpdates =
PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new);
this.automationcompositionList = PfUtils.mapList(source.automationcompositionList, ParticipantRestartAc::new);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
index 33a730941..962b6137c 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
@@ -20,6 +20,9 @@
package org.onap.policy.clamp.models.acm.messages.kafka.participant;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@@ -29,6 +32,10 @@ import lombok.ToString;
@ToString(callSuper = true)
public class ParticipantSync extends ParticipantRestart {
+ private Set<UUID> excludeReplicas = new HashSet<>();
+ private boolean restarting = false;
+ private boolean delete = false;
+
/**
* Constructor.
*/
@@ -43,5 +50,8 @@ public class ParticipantSync extends ParticipantRestart {
*/
public ParticipantSync(ParticipantSync source) {
super(source);
+ this.excludeReplicas = new HashSet<>(source.excludeReplicas);
+ this.restarting = source.restarting;
+ this.delete = source.delete;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
index 3b80aca77..b3437c06f 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
+import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import java.util.HashMap;
import java.util.List;
@@ -33,9 +34,13 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantReplica;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository;
+import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantReplicaRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -56,6 +61,7 @@ public class ParticipantProvider {
private final NodeTemplateStateRepository nodeTemplateStateRepository;
+ private final ParticipantReplicaRepository replicaRepository;
/**
* Get all participants.
@@ -142,7 +148,6 @@ public class ParticipantProvider {
return jpaDeleteParticipantOpt.get().toAuthorative();
}
-
/**
* Get a map with SupportedElement as key and the participantId as value.
*
@@ -160,7 +165,6 @@ public class ParticipantProvider {
return map;
}
-
/**
* Retrieve a list of automation composition elements associated with a participantId.
*
@@ -186,11 +190,64 @@ public class ParticipantProvider {
/**
* Get a list of compositionId associated with a participantId from ac definitions.
* @param participantId the participant id associated with the automation composition elements
- * @return the list of compositionId
+ * @return the set of compositionId
*/
public Set<UUID> getCompositionIds(@NonNull final UUID participantId) {
return nodeTemplateStateRepository.findByParticipantId(participantId.toString()).stream()
.map(nodeTemplateState -> UUID.fromString(nodeTemplateState.getCompositionId()))
.collect(Collectors.toSet());
}
+
+ /**
+ * Get participant replica.
+ *
+ * @param replicaId the Id of the replica to get
+ * @return the replica found
+ */
+ @Transactional(readOnly = true)
+ public Optional<ParticipantReplica> findParticipantReplica(@NonNull final UUID replicaId) {
+ return replicaRepository.findById(replicaId.toString()).map(JpaParticipantReplica::toAuthorative);
+ }
+
+ /**
+ * Save participant replica.
+ *
+ * @param replica replica to save
+ */
+ public void saveParticipantReplica(@NonNull final ParticipantReplica replica) {
+ var jpa = replicaRepository.getReferenceById(replica.getReplicaId().toString());
+ jpa.fromAuthorative(replica);
+ replicaRepository.save(jpa);
+ }
+
+ /**
+ * Delete participant replica.
+ *
+ * @param replicaId the Id of the replica to delete
+ */
+ public void deleteParticipantReplica(@NonNull UUID replicaId) {
+ replicaRepository.deleteById(replicaId.toString());
+ }
+
+ public List<ParticipantReplica> findReplicasOnLine() {
+ return ProviderUtils.asEntityList(replicaRepository.findByParticipantState(ParticipantState.ON_LINE));
+ }
+
+ /**
+ * Verify Participant state.
+ *
+ * @param participantIds The list of UUIDs of the participants to get
+ * @throws PfModelRuntimeException in case the participant is offline
+ */
+ public void verifyParticipantState(Set<UUID> participantIds) {
+ for (UUID participantId : participantIds) {
+ var jpaParticipant = participantRepository.getReferenceById(participantId.toString());
+ var replicaOnline = jpaParticipant.getReplicas().stream()
+ .filter(replica -> ParticipantState.ON_LINE.equals(replica.getParticipantState())).findFirst();
+ if (replicaOnline.isEmpty()) {
+ throw new PfModelRuntimeException(Response.Status.CONFLICT,
+ "Participant: " + participantId + " is OFFLINE");
+ }
+ }
+ }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantReplicaRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantReplicaRepository.java
new file mode 100644
index 000000000..c9621ee93
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantReplicaRepository.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 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.models.acm.persistence.repository;
+
+import java.util.List;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantReplica;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ParticipantReplicaRepository extends JpaRepository<JpaParticipantReplica, String> {
+
+ List<JpaParticipantReplica> findByParticipantState(ParticipantState participantState);
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
index 5f523ad27..f19d5db8b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
@@ -441,6 +441,7 @@ public final class AcmUtils {
var acElementRestart = new AcElementRestart();
acElementRestart.setId(element.getId());
acElementRestart.setDefinition(new ToscaConceptIdentifier(element.getDefinition()));
+ acElementRestart.setParticipantId(element.getParticipantId());
acElementRestart.setDeployState(element.getDeployState());
acElementRestart.setLockState(element.getLockState());
acElementRestart.setOperationalState(element.getOperationalState());
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index 2a5c15a09..9ceeef640 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,11 +26,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,12 +41,15 @@ import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository;
+import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantReplicaRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
@@ -63,27 +69,24 @@ class ParticipantProviderTest {
private final List<Participant> inputParticipants = new ArrayList<>();
private List<JpaParticipant> jpaParticipantList;
- private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
-
- private AutomationCompositions inputAutomationCompositions;
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
- private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
- private final String nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON);
-
- private List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>();
+ private final List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>();
private List<JpaNodeTemplateState> jpaNodeTemplateStateList;
@BeforeEach
void beforeSetup() throws Exception {
+ var originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
inputParticipants.add(CODER.decode(originalJson, Participant.class));
jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
- inputAutomationCompositions = CODER.decode(originalAcJson, AutomationCompositions.class);
+ var originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
+ var inputAutomationCompositions = CODER.decode(originalAcJson, AutomationCompositions.class);
inputAutomationCompositionsJpa =
ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
JpaAutomationComposition::new, "automation compositions");
+ var nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON);
nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class));
nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED);
jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList,
@@ -97,7 +100,8 @@ class ParticipantProviderTest {
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThatThrownBy(() -> participantProvider.saveParticipant(null)).hasMessageMatching(LIST_IS_NULL);
@@ -116,7 +120,8 @@ class ParticipantProviderTest {
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL);
@@ -133,7 +138,8 @@ class ParticipantProviderTest {
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty();
@@ -156,7 +162,8 @@ class ParticipantProviderTest {
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThatThrownBy(() -> participantProvider.getParticipantById(INVALID_ID)).isInstanceOf(
PfModelRuntimeException.class).hasMessageMatching("Participant Not Found with ID:.*.");
@@ -168,7 +175,8 @@ class ParticipantProviderTest {
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
var participantId = inputParticipants.get(0).getParticipantId();
assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId))
@@ -187,13 +195,14 @@ class ParticipantProviderTest {
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
var acElementList = inputAutomationCompositionsJpa.get(0).getElements();
var participantId = UUID.randomUUID();
when(automationCompositionElementRepository.findByParticipantId(participantId.toString()))
- .thenReturn(acElementList);
+ .thenReturn(acElementList);
var listOfAcElements = participantProvider.getAutomationCompositionElements(participantId);
@@ -210,7 +219,8 @@ class ParticipantProviderTest {
when(nodeTemplateStateRepository.findByParticipantId(participantId)).thenReturn(jpaNodeTemplateStateList);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(UUID.fromString(participantId));
@@ -224,7 +234,8 @@ class ParticipantProviderTest {
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThrows(NullPointerException.class, () -> participantProvider.getParticipantById(null));
assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
@@ -233,6 +244,9 @@ class ParticipantProviderTest {
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null));
+ assertThrows(NullPointerException.class, () -> participantProvider.findParticipantReplica(null));
+ assertThrows(NullPointerException.class, () -> participantProvider.saveParticipantReplica(null));
+ assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipantReplica(null));
}
@Test
@@ -242,7 +256,8 @@ class ParticipantProviderTest {
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
var result = participantProvider.getSupportedElementMap();
assertThat(result).hasSize(2);
@@ -258,11 +273,89 @@ class ParticipantProviderTest {
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository);
+ automationCompositionElementRepository, nodeTemplateStateRepository,
+ mock(ParticipantReplicaRepository.class));
assertThatThrownBy(() -> participantProvider.getCompositionIds(null)).hasMessageMatching(LIST_IS_NULL);
var result = participantProvider.getCompositionIds(participantId);
assertThat(result).hasSize(1);
}
+
+ @Test
+ void testFindParticipantReplica() {
+ var replicaRepository = mock(ParticipantReplicaRepository.class);
+ var replica = inputParticipants.get(0).getReplicas().values().iterator().next();
+ var jpaReplica = jpaParticipantList.get(0).getReplicas().get(0);
+ when(replicaRepository.findById(replica.getReplicaId().toString())).thenReturn(Optional.of(jpaReplica));
+ var participantProvider = new ParticipantProvider(mock(ParticipantRepository.class),
+ mock(AutomationCompositionElementRepository.class), mock(NodeTemplateStateRepository.class),
+ replicaRepository);
+
+ var result = participantProvider.findParticipantReplica(replica.getReplicaId());
+ assertThat(result).isNotEmpty();
+ assertEquals(replica.getReplicaId(), result.get().getReplicaId());
+ }
+
+ @Test
+ void testFindReplicasOnLine() {
+ var replicaRepository = mock(ParticipantReplicaRepository.class);
+ var replica = inputParticipants.get(0).getReplicas().values().iterator().next();
+ var jpaReplica = jpaParticipantList.get(0).getReplicas().get(0);
+ jpaReplica.fromAuthorative(replica);
+ when(replicaRepository.findByParticipantState(ParticipantState.ON_LINE)).thenReturn(List.of(jpaReplica));
+ var participantProvider = new ParticipantProvider(mock(ParticipantRepository.class),
+ mock(AutomationCompositionElementRepository.class), mock(NodeTemplateStateRepository.class),
+ replicaRepository);
+
+ var result = participantProvider.findReplicasOnLine();
+ assertThat(result).hasSize(1);
+ assertEquals(replica.getReplicaId(), result.get(0).getReplicaId());
+ }
+
+ @Test
+ void testSaveParticipantReplica() {
+ var jpaReplica = jpaParticipantList.get(0).getReplicas().get(0);
+ var replicaRepository = mock(ParticipantReplicaRepository.class);
+ when(replicaRepository.getReferenceById(jpaReplica.getReplicaId())).thenReturn(jpaReplica);
+ var participantProvider = new ParticipantProvider(mock(ParticipantRepository.class),
+ mock(AutomationCompositionElementRepository.class), mock(NodeTemplateStateRepository.class),
+ replicaRepository);
+
+ var replica = inputParticipants.get(0).getReplicas().values().iterator().next();
+ participantProvider.saveParticipantReplica(replica);
+ verify(replicaRepository).save(any());
+ }
+
+ @Test
+ void testDeleteParticipantReplica() {
+ var replicaRepository = mock(ParticipantReplicaRepository.class);
+ var participantProvider = new ParticipantProvider(mock(ParticipantRepository.class),
+ mock(AutomationCompositionElementRepository.class), mock(NodeTemplateStateRepository.class),
+ replicaRepository);
+ participantProvider.deleteParticipantReplica(CommonTestData.getReplicaId());
+ verify(replicaRepository).deleteById(CommonTestData.getReplicaId().toString());
+ }
+
+ @Test
+ void testVerifyParticipantState() {
+ var jpaParticipant = new JpaParticipant(jpaParticipantList.get(0));
+ var participantId = jpaParticipant.getParticipantId();
+ var participantRepository = mock(ParticipantRepository.class);
+ when(participantRepository.getReferenceById(participantId)).thenReturn(jpaParticipant);
+
+ var replicaRepository = mock(ParticipantReplicaRepository.class);
+ var participantProvider = new ParticipantProvider(participantRepository,
+ mock(AutomationCompositionElementRepository.class), mock(NodeTemplateStateRepository.class),
+ replicaRepository);
+
+ jpaParticipant.setReplicas(List.of());
+ var set = Set.of(UUID.fromString(participantId));
+ assertThatThrownBy(() -> participantProvider.verifyParticipantState(set))
+ .hasMessageMatching("Participant: " + participantId + " is OFFLINE");
+
+ when(participantRepository.getReferenceById(participantId)).thenReturn(jpaParticipantList.get(0));
+ participantProvider.verifyParticipantState(set);
+ verify(participantRepository, times(2)).getReferenceById(participantId);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
index 3bd1549ad..1d111b868 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
@@ -37,7 +37,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
*/
public class CommonTestData {
- public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
+ public static final UUID PARTICIPANT_ID = UUID.randomUUID();
public static final UUID REPLICA_ID = UUID.randomUUID();
private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
@@ -47,7 +47,7 @@ public class CommonTestData {
* @return participant Id
*/
public static UUID getParticipantId() {
- return PARTCICIPANT_ID;
+ return PARTICIPANT_ID;
}
/**
@@ -65,7 +65,7 @@ public class CommonTestData {
* @return participant Id
*/
public static String getJpaParticipantId() {
- return PARTCICIPANT_ID.toString();
+ return PARTICIPANT_ID.toString();
}
/**