summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-07-07 13:50:59 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-07-07 13:05:12 +0000
commitb28ae291bc1b4a7426d4c6e5098c0a20f3948796 (patch)
tree7e3f325e60f976101b5a028fd3650c22945f296a
parentfdd9179e8713e68916a16ea949b1125a358b560e (diff)
Add restart support in composition and in instance
Add restart support in Automation Composition Definition and in Automation Composition Instance. Issue-ID: POLICY-4766 Change-Id: I8d169caf7fe74b6d2fcd40c106e4a1646a89a915 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java11
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java15
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java10
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java11
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java75
12 files changed, 103 insertions, 53 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
index 54c9b6190..b92b03fba 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
@@ -42,6 +42,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
@NonNull
private UUID compositionId;
+ private Boolean restarting;
+
@NonNull
private DeployState deployState = DeployState.UNDEPLOYED;
@@ -61,6 +63,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
super(otherAutomationComposition);
this.instanceId = otherAutomationComposition.instanceId;
this.compositionId = otherAutomationComposition.compositionId;
+ this.restarting = otherAutomationComposition.restarting;
this.deployState = otherAutomationComposition.deployState;
this.lockState = otherAutomationComposition.lockState;
this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
index eb8a919d6..548bc4549 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
@@ -41,6 +41,8 @@ public class AutomationCompositionDefinition {
@NonNull
private ToscaServiceTemplate serviceTemplate;
+ private Boolean restarting;
+
@NonNull
private AcTypeState state;
@@ -58,6 +60,7 @@ public class AutomationCompositionDefinition {
public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) {
this.compositionId = otherAcmDefinition.compositionId;
this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate);
+ this.restarting = otherAcmDefinition.restarting;
this.state = otherAcmDefinition.state;
this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new);
this.stateChangeResult = otherAcmDefinition.stateChangeResult;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
index ea54076ba..95ee55f8d 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
@@ -48,6 +48,8 @@ public class AutomationCompositionElement {
@NonNull
private UUID participantId = UUID.randomUUID();
+ private Boolean restarting;
+
@NonNull
private DeployState deployState = DeployState.UNDEPLOYED;
@@ -77,6 +79,7 @@ public class AutomationCompositionElement {
this.description = otherElement.description;
this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
+ this.restarting = otherElement.restarting;
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/concepts/NodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
index 62e92087e..add4f1078 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
@@ -38,6 +38,8 @@ public class NodeTemplateState {
private ToscaConceptIdentifier nodeTemplateId;
+ private Boolean restarting;
+
private AcTypeState state;
private String message;
@@ -51,6 +53,7 @@ public class NodeTemplateState {
this.nodeTemplateStateId = copyConstructor.nodeTemplateStateId;
this.participantId = copyConstructor.participantId;
this.nodeTemplateId = new ToscaConceptIdentifier(copyConstructor.nodeTemplateId);
+ this.restarting = copyConstructor.restarting;
this.state = copyConstructor.state;
this.message = copyConstructor.message;
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
index 3a448f262..7f2a1e5ae 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
@@ -81,6 +81,9 @@ public class JpaAutomationComposition extends Validated
private String compositionId;
@Column
+ private Boolean restarting;
+
+ @Column
@NotNull
private DeployState deployState;
@@ -140,6 +143,7 @@ public class JpaAutomationComposition extends Validated
this.name = copyConcept.name;
this.version = copyConcept.version;
this.compositionId = copyConcept.compositionId;
+ this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.description = copyConcept.description;
@@ -164,6 +168,7 @@ public class JpaAutomationComposition extends Validated
automationComposition.setName(name);
automationComposition.setVersion(version);
automationComposition.setCompositionId(UUID.fromString(compositionId));
+ automationComposition.setRestarting(restarting);
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setDescription(description);
@@ -182,6 +187,7 @@ public class JpaAutomationComposition extends Validated
this.name = automationComposition.getName();
this.version = automationComposition.getVersion();
this.compositionId = automationComposition.getCompositionId().toString();
+ this.restarting = automationComposition.getRestarting();
this.deployState = automationComposition.getDeployState();
this.lockState = automationComposition.getLockState();
this.description = automationComposition.getDescription();
@@ -224,6 +230,11 @@ public class JpaAutomationComposition extends Validated
return result;
}
+ result = ObjectUtils.compare(restarting, other.restarting);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
index 50949d751..f82152ddc 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
@@ -74,6 +74,9 @@ public class JpaAutomationCompositionDefinition extends Validated
private String version;
@Column
+ private Boolean restarting;
+
+ @Column
@NotNull
private AcTypeState state;
@@ -94,6 +97,7 @@ public class JpaAutomationCompositionDefinition extends Validated
public AutomationCompositionDefinition toAuthorative() {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.fromString(this.compositionId));
+ acmDefinition.setRestarting(this.restarting);
acmDefinition.setState(this.state);
acmDefinition.setStateChangeResult(this.stateChangeResult);
acmDefinition.setServiceTemplate(this.serviceTemplate.toAuthorative());
@@ -107,6 +111,7 @@ public class JpaAutomationCompositionDefinition extends Validated
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
this.compositionId = copyConcept.getCompositionId().toString();
+ this.restarting = copyConcept.getRestarting();
this.state = copyConcept.getState();
this.stateChangeResult = copyConcept.getStateChangeResult();
this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
index 60a911b21..8c679146e 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
@@ -81,10 +81,14 @@ public class JpaAutomationCompositionElement extends Validated
})
private PfConceptKey definition;
+ @Column
@NotNull
private String participantId;
@Column
+ private Boolean restarting;
+
+ @Column
@NotNull
private DeployState deployState;
@@ -168,6 +172,7 @@ public class JpaAutomationCompositionElement extends Validated
this.outProperties =
(copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
: null);
+ this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.operationalState = copyConcept.operationalState;
@@ -194,6 +199,7 @@ public class JpaAutomationCompositionElement extends Validated
element.setDescription(description);
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
+ element.setRestarting(restarting);
element.setDeployState(deployState);
element.setLockState(lockState);
element.setOperationalState(operationalState);
@@ -210,6 +216,7 @@ public class JpaAutomationCompositionElement extends Validated
this.description = element.getDescription();
this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
+ this.restarting = element.getRestarting();
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
this.operationalState = element.getOperationalState();
@@ -246,6 +253,11 @@ public class JpaAutomationCompositionElement extends Validated
return result;
}
+ result = ObjectUtils.compare(restarting, other.restarting);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
index 8ee1075f6..809e13911 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
@@ -67,6 +67,9 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
private PfConceptKey nodeTemplateId;
@Column
+ private Boolean restarting;
+
+ @Column
@NotNull
private AcTypeState state;
@@ -98,6 +101,7 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
this.participantId = copyConcept.getParticipantId().toString();
}
this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
+ this.restarting = copyConcept.getRestarting();
this.state = copyConcept.getState();
this.message = copyConcept.getMessage();
}
@@ -110,6 +114,7 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
}
nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
+ nodeTemplateState.setRestarting(this.restarting);
nodeTemplateState.setState(this.state);
nodeTemplateState.setMessage(this.message);
return nodeTemplateState;
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 597606e17..7e8b353ad 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
@@ -24,13 +24,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
-import org.onap.policy.clamp.models.acm.concepts.LockState;
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.persistence.concepts.JpaParticipant;
@@ -182,4 +182,15 @@ public class ParticipantProvider {
return ProviderUtils.asEntityList(nodeTemplateStateRepository
.findByParticipantId(participantId.toString()));
}
+
+ /**
+ * 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
+ */
+ public Set<UUID> getCompositionIds(@NonNull final UUID participantId) {
+ return nodeTemplateStateRepository.findByParticipantId(participantId.toString()).stream()
+ .map(nodeTemplateState -> UUID.fromString(nodeTemplateState.getCompositionId()))
+ .collect(Collectors.toSet());
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
index 2a79aee08..7cb8f840f 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
@@ -193,6 +193,16 @@ class JpaAutomationCompositionElementTest {
testJpaAcElement.setOperationalState("DEFAULT");
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setMessage("Message");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setMessage(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setRestarting(true);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setRestarting(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
index bc01e74be..04a874419 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
@@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.models.base.PfConceptKey;
/**
@@ -172,6 +173,16 @@ class JpaAutomationCompositionTest {
testJpaAutomationComposition.setDescription(null);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setRestarting(true);
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setRestarting(null);
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
+ testJpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setStateChangeResult(null);
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition));
}
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 22523e2a7..2a5c15a09 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
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
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.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -31,13 +32,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.DeployState;
-import org.onap.policy.clamp.models.acm.concepts.LockState;
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.persistence.concepts.JpaAutomationComposition;
@@ -59,9 +57,6 @@ class ParticipantProviderTest {
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
- private static final String AUTOMATION_COMPOSITION_JSON_DEREGISTER =
- "src/test/resources/providers/TestAutomationCompositionsDeregister.json";
-
private static final String NODE_TEMPLATE_STATE_JSON = "src/test/resources/providers/NodeTemplateState.json";
private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
private static final UUID INVALID_ID = UUID.randomUUID();
@@ -72,12 +67,8 @@ class ParticipantProviderTest {
private AutomationCompositions inputAutomationCompositions;
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
- private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
-
- private AutomationCompositions inputAutomationCompositionsDeregister;
- private List<JpaAutomationComposition> inputAutomationCompositionsJpaDeregister;
- private final String deregisterAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON_DEREGISTER);
+ 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<>();
@@ -93,11 +84,6 @@ class ParticipantProviderTest {
ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
JpaAutomationComposition::new, "automation compositions");
- inputAutomationCompositionsDeregister = CODER.decode(deregisterAcJson, AutomationCompositions.class);
- inputAutomationCompositionsJpaDeregister =
- ProviderUtils.getJpaAndValidateList(inputAutomationCompositionsDeregister.getAutomationCompositionList(),
- JpaAutomationComposition::new, "automation compositions");
-
nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class));
nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED);
jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList,
@@ -132,8 +118,7 @@ class ParticipantProviderTest {
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- assertThatThrownBy(() -> participantProvider.updateParticipant(null))
- .hasMessageMatching(LIST_IS_NULL);
+ assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL);
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
@@ -150,7 +135,6 @@ class ParticipantProviderTest {
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
-
assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty();
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
@@ -159,11 +143,9 @@ class ParticipantProviderTest {
assertThatThrownBy(() -> participantProvider.getParticipantById(inputParticipants.get(0).getParticipantId()))
.hasMessageMatching("Participant Not Found with ID: " + inputParticipants.get(0).getParticipantId());
- when(participantRepository.findById(any())).thenReturn(
- Optional.ofNullable(jpaParticipantList.get(0)));
+ when(participantRepository.findById(any())).thenReturn(Optional.ofNullable(jpaParticipantList.get(0)));
- var participant = participantProvider.getParticipantById(inputParticipants.get(0)
- .getParticipantId());
+ var participant = participantProvider.getParticipantById(inputParticipants.get(0).getParticipantId());
assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(participant);
}
@@ -207,16 +189,16 @@ class ParticipantProviderTest {
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- var acElementList = inputAutomationCompositionsJpa
- .stream().map(c -> c.getElements()).collect(Collectors.toList());
-
- when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0));
+ var acElementList = inputAutomationCompositionsJpa.get(0).getElements();
- var listOfAcElements = participantProvider.getAutomationCompositionElements(UUID.randomUUID());
-
- assertThat(acElementList.get(0).equals(listOfAcElements));
+ var participantId = UUID.randomUUID();
+ when(automationCompositionElementRepository.findByParticipantId(participantId.toString()))
+ .thenReturn(acElementList);
+ var listOfAcElements = participantProvider.getAutomationCompositionElements(participantId);
+ assertThat(listOfAcElements).hasSameSizeAs(acElementList);
+ assertEquals(UUID.fromString(acElementList.get(0).getElementId()), listOfAcElements.get(0).getId());
}
@Test
@@ -224,16 +206,15 @@ class ParticipantProviderTest {
var participantRepository = mock(ParticipantRepository.class);
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
- when(nodeTemplateStateRepository.findByParticipantId(any())).thenReturn(jpaNodeTemplateStateList);
+ var participantId = jpaParticipantList.get(0).getParticipantId();
+ when(nodeTemplateStateRepository.findByParticipantId(participantId)).thenReturn(jpaNodeTemplateStateList);
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(
- UUID.fromString(jpaParticipantList.get(0).getParticipantId()));
-
- assertThat(listOfNodeTemplateState.equals(nodeTemplateStateList));
+ var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(UUID.fromString(participantId));
+ assertEquals(listOfNodeTemplateState, nodeTemplateStateList);
}
@Test
@@ -268,28 +249,20 @@ class ParticipantProviderTest {
}
@Test
- void testResetParticipantAcElementState() {
+ void testGetCompositionIds() {
+ var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
+ var participantId = UUID.randomUUID();
+ when(nodeTemplateStateRepository.findByParticipantId(participantId.toString()))
+ .thenReturn(jpaNodeTemplateStateList);
var participantRepository = mock(ParticipantRepository.class);
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
- var acElementList = inputAutomationCompositionsJpaDeregister
- .stream().map(c -> c.getElements()).collect(Collectors.toList());
-
- when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0));
-
- var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- acElementList.get(0).stream().forEach(e -> {
- assertThat(e.getDeployState().equals(DeployState.DEPLOYED));
- assertThat(e.getLockState().equals(LockState.LOCKED));
- });
-
- acElementList.get(0).stream().forEach(e -> {
- assertThat(e.getDeployState().equals(DeployState.UNDEPLOYED));
- assertThat(e.getLockState().equals(LockState.NONE));
- });
+ assertThatThrownBy(() -> participantProvider.getCompositionIds(null)).hasMessageMatching(LIST_IS_NULL);
+ var result = participantProvider.getCompositionIds(participantId);
+ assertThat(result).hasSize(1);
}
}