summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-17 09:56:52 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-23 15:22:35 +0000
commitc5e57c1b1cd0e778ebf47edd20fd9a340471ab72 (patch)
treef567d2bc52cf070bcccb83bad0f4ab5f70d2415f /models
parenta263a250f7185fd9ddc4b600d96452fdbf21fffb (diff)
Refactor participantId as UUID
As part of endpoint refactoring, refactor participantId as UUID in ACM. Issue-ID: POLICY-4521 Change-Id: I8ac652d9b2fadf9ce3220febb9c2c3ac0d3786cc 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/AutomationCompositionElement.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java25
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java4
-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/JpaParticipant.java100
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java5
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java21
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java122
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java23
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java17
14 files changed, 80 insertions, 276 deletions
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 e5c85dd10..bea2278a8 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
@@ -50,7 +50,7 @@ public class AutomationCompositionElement {
private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
@NonNull
- private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private UUID participantId = UUID.randomUUID();
@NonNull
private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED;
@@ -75,7 +75,7 @@ public class AutomationCompositionElement {
this.id = otherElement.id;
this.definition = new ToscaConceptIdentifier(otherElement.definition);
this.participantType = new ToscaConceptIdentifier(otherElement.participantType);
- this.participantId = new ToscaConceptIdentifier(otherElement.participantId);
+ this.participantId = otherElement.participantId;
this.state = otherElement.state;
this.orderedState = otherElement.orderedState;
this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
index 56c01837f..4741bafca 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
@@ -26,22 +26,18 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
/**
* Class to represent details of a running participant instance.
*/
@NoArgsConstructor
@Data
-@EqualsAndHashCode(callSuper = true)
-public class Participant extends ToscaEntity implements Comparable<Participant> {
+@EqualsAndHashCode
+public class Participant {
@NonNull
private UUID participantId;
- @NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
@NonNull
private ParticipantState participantState = ParticipantState.ON_LINE;
@@ -52,29 +48,12 @@ public class Participant extends ToscaEntity implements Comparable<Participant>
@NonNull
private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes;
- @Override
- public String getType() {
- return definition.getName();
- }
-
- @Override
- public String getTypeVersion() {
- return definition.getVersion();
- }
-
- @Override
- public int compareTo(final Participant other) {
- return compareNameVersion(this, other);
- }
-
/**
* Copy constructor.
*
* @param otherParticipant the participant to copy from
*/
public Participant(Participant otherParticipant) {
- super(otherParticipant);
- this.definition = new ToscaConceptIdentifier(otherParticipant.definition);
this.participantState = otherParticipant.participantState;
this.participantType = otherParticipant.participantType;
this.participantId = otherParticipant.participantId;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java
index 949a7c47d..aff619873 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.concepts;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -38,7 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@ToString
public class ParticipantDefinition {
- private ToscaConceptIdentifier participantId;
+ private UUID participantId;
private ToscaConceptIdentifier participantType;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java
index 1872a6144..031fd5c02 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java
@@ -22,12 +22,12 @@ package org.onap.policy.clamp.models.acm.concepts;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent a participant definition update instance.
@@ -38,7 +38,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@ToString
public class ParticipantUpdates {
- private ToscaConceptIdentifier participantId;
+ private UUID participantId;
// List of AutomationCompositionElement values for a particular participant
private List<AutomationCompositionElement> automationCompositionElementList = new ArrayList<>();
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
index c6d56904d..8d847f8d4 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
@@ -55,7 +55,7 @@ public class ParticipantAckMessage {
/**
* Participant ID, or {@code null} for messages from participants.
*/
- private ToscaConceptIdentifier participantId;
+ private UUID participantId;
/**
* Participant State, or {@code null} for messages from participants.
@@ -94,7 +94,7 @@ public class ParticipantAckMessage {
* @return {@code true} if this message applies to this participant, {@code false} otherwise
*/
public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType,
- @NonNull final ToscaConceptIdentifier participantId) {
+ @NonNull final UUID participantId) {
// Broadcast message to all participants
if (this.participantType == null) {
return true;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java
index c1ef4b416..525dab75f 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java
@@ -55,7 +55,7 @@ public class ParticipantMessage {
/**
* Participant ID, or {@code null} for messages from participants.
*/
- private ToscaConceptIdentifier participantId;
+ private UUID participantId;
/**
* Automation Composition ID, or {@code null} for messages to participants.
@@ -94,7 +94,7 @@ public class ParticipantMessage {
* @return {@code true} if this message applies to this participant, {@code false} otherwise
*/
public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType,
- @NonNull final ToscaConceptIdentifier participantId) {
+ @NonNull final UUID participantId) {
// Broadcast message to all participants
if (this.participantType == null) {
return true;
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 79576f6eb..23fc0a93e 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
@@ -85,11 +85,9 @@ public class JpaAutomationCompositionElement extends Validated
@AttributeOverride(name = "version", column = @Column(name = "participant_type_version"))
private PfConceptKey participantType;
+ @Column
@NotNull
- @AttributeOverride(name = "name", column = @Column(name = "participant_name"))
- @AttributeOverride(name = "version", column = @Column(name = "participant_version"))
- private PfConceptKey participantId;
- // @formatter:on
+ private String participantId;
@Column
@NotNull
@@ -154,7 +152,7 @@ public class JpaAutomationCompositionElement extends Validated
this.instanceId = copyConcept.instanceId;
this.definition = new PfConceptKey(copyConcept.definition);
this.participantType = new PfConceptKey(copyConcept.participantType);
- this.participantId = new PfConceptKey(copyConcept.participantId);
+ this.participantId = copyConcept.participantId;
this.state = copyConcept.state;
this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
@@ -177,7 +175,7 @@ public class JpaAutomationCompositionElement extends Validated
element.setId(UUID.fromString(elementId));
element.setDefinition(new ToscaConceptIdentifier(definition));
element.setParticipantType(new ToscaConceptIdentifier(participantType));
- element.setParticipantId(new ToscaConceptIdentifier(participantId));
+ element.setParticipantId(UUID.fromString(participantId));
element.setState(state);
element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
element.setDescription(description);
@@ -190,7 +188,7 @@ public class JpaAutomationCompositionElement extends Validated
public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
this.definition = element.getDefinition().asConceptKey();
this.participantType = element.getParticipantType().asConceptKey();
- this.participantId = element.getParticipantId().asConceptKey();
+ this.participantId = element.getParticipantId().toString();
this.state = element.getState();
this.orderedState = element.getOrderedState();
this.description = element.getDescription();
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
index 7d043ace0..b7e95cfa7 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
@@ -28,10 +28,10 @@ import java.util.UUID;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
-import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
+import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
@@ -46,10 +46,8 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
-import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.validation.annotations.VerifyKey;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -62,28 +60,16 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaParticipant extends PfConcept implements PfAuthorative<Participant>, Serializable {
+public class JpaParticipant extends Validated
+ implements PfAuthorative<Participant>, Comparable<JpaParticipant>, Serializable {
private static final long serialVersionUID = -4697758484642403483L;
- @Column
+ @Id
@NotNull
private String participantId;
- @EmbeddedId
- @VerifyKey
- @NotNull
- private PfConceptKey key;
-
- // @formatter:off
- @VerifyKey
@NotNull
- @AttributeOverride(name = "name", column = @Column(name = "definition_name"))
- @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
- private PfConceptKey definition;
- // @formatter:on
-
- @NotNull
- @AttributeOverride(name = "name", column = @Column(name = "participant_type_name"))
+ @AttributeOverride(name = "name", column = @Column(name = "participant_type_name"))
@AttributeOverride(name = "version", column = @Column(name = "participant_type_version"))
private PfConceptKey participantType;
@@ -104,36 +90,20 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
* The Default Constructor creates a {@link JpaParticipant} object with a null key.
*/
public JpaParticipant() {
- this(new PfConceptKey());
- }
-
- /**
- * The Key Constructor creates a {@link JpaParticipant} object with the given concept key.
- *
- * @param key the key
- */
- public JpaParticipant(@NonNull final PfConceptKey key) {
- this(UUID.randomUUID().toString(), key, new PfConceptKey(), ParticipantState.ON_LINE, new ArrayList<>());
+ this(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>());
}
/**
* The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields.
*
* @param participantId the participant id
- * @param key the key
- * @param definition the TOSCA definition of the participant
* @param participantState the state of the participant
*/
- public JpaParticipant(@NotNull String participantId,
- @NonNull final PfConceptKey key,
- @NonNull final PfConceptKey definition,
- @NonNull final ParticipantState participantState,
- @NonNull final List<JpaParticipantSupportedElementType> supportedAcElementTypes) {
- this.key = key;
- this.definition = definition;
- this.participantState = participantState;
+ public JpaParticipant(@NonNull String participantId, @NonNull final ParticipantState participantState,
+ @NonNull final List<JpaParticipantSupportedElementType> supportedElements) {
this.participantId = participantId;
- this.supportedElements = supportedAcElementTypes;
+ this.participantState = participantState;
+ this.supportedElements = supportedElements;
}
/**
@@ -142,9 +112,6 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
* @param copyConcept the concept to copy from
*/
public JpaParticipant(@NonNull final JpaParticipant copyConcept) {
- super(copyConcept);
- this.key = new PfConceptKey(copyConcept.key);
- this.definition = new PfConceptKey(copyConcept.definition);
this.participantState = copyConcept.participantState;
this.description = copyConcept.description;
this.participantType = copyConcept.participantType;
@@ -165,11 +132,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
public Participant toAuthorative() {
var participant = new Participant();
- participant.setName(key.getName());
- participant.setVersion(key.getVersion());
- participant.setDefinition(new ToscaConceptIdentifier(definition));
participant.setParticipantState(participantState);
- participant.setDescription(description);
participant.setParticipantType(new ToscaConceptIdentifier(participantType));
participant.setParticipantId(UUID.fromString(participantId));
participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size()));
@@ -183,13 +146,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
@Override
public void fromAuthorative(@NonNull final Participant participant) {
- if (this.key == null || this.getKey().isNullKey()) {
- this.setKey(new PfConceptKey(participant.getName(), participant.getVersion()));
- }
-
- this.definition = participant.getDefinition().asConceptKey();
this.setParticipantState(participant.getParticipantState());
- this.setDescription(participant.getDescription());
this.participantType = participant.getParticipantType().asConceptKey();
this.participantId = participant.getParticipantId().toString();
this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size());
@@ -203,42 +160,15 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa
}
@Override
- public List<PfKey> getKeys() {
- List<PfKey> keyList = getKey().getKeys();
-
- keyList.add(definition);
- keyList.add(participantType);
-
- return keyList;
- }
-
- @Override
- public void clean() {
- key.clean();
- definition.clean();
- description = (description == null ? null : description.trim());
- participantType.clean();
- }
-
- @Override
- public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
+ public int compareTo(final JpaParticipant other) {
+ if (other == null) {
return -1;
}
- if (this == otherConcept) {
+ if (this == other) {
return 0;
}
- if (getClass() != otherConcept.getClass()) {
- return getClass().getName().compareTo(otherConcept.getClass().getName());
- }
-
- final JpaParticipant other = (JpaParticipant) otherConcept;
- int result = key.compareTo(other.key);
- if (result != 0) {
- return result;
- }
- result = definition.compareTo(other.definition);
+ var result = participantId.compareTo(other.participantId);
if (result != 0) {
return result;
}
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 fa8979d58..7b8ebc038 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
@@ -29,9 +29,7 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -60,11 +58,10 @@ public class ParticipantProvider {
*
* @param participantId the id of the participant to get
* @return the participant found
- * @throws PfModelException on errors getting participant
*/
@Transactional(readOnly = true)
public Participant getParticipantById(UUID participantId) {
- var participant = participantRepository.findByParticipantId(participantId.toString());
+ var participant = participantRepository.findById(participantId.toString());
if (participant.isEmpty()) {
throw new PfModelRuntimeException(Status.NOT_FOUND,
"Participant Not Found with ID: " + participantId);
@@ -80,8 +77,8 @@ public class ParticipantProvider {
* @return the participant found
*/
@Transactional(readOnly = true)
- public Optional<Participant> findParticipant(@NonNull final ToscaConceptIdentifier participantId) {
- return participantRepository.findById(participantId.asConceptKey()).map(JpaParticipant::toAuthorative);
+ public Optional<Participant> findParticipant(@NonNull final UUID participantId) {
+ return participantRepository.findById(participantId.toString()).map(JpaParticipant::toAuthorative);
}
/**
@@ -91,7 +88,6 @@ public class ParticipantProvider {
* @return the participant created
*/
public Participant saveParticipant(@NonNull final Participant participant) {
- participant.setParticipantId(UUID.randomUUID());
var result = participantRepository
.save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant"));
@@ -120,7 +116,7 @@ public class ParticipantProvider {
* @return the participant deleted
*/
public Participant deleteParticipant(@NonNull final UUID participantId) {
- var jpaDeleteParticipantOpt = participantRepository.findByParticipantId(participantId.toString());
+ var jpaDeleteParticipantOpt = participantRepository.findById(participantId.toString());
if (jpaDeleteParticipantOpt.isEmpty()) {
String errorMessage =
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
index b448731ba..310d9981c 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java
@@ -20,14 +20,11 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
-import java.util.Optional;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
-import org.onap.policy.models.base.PfConceptKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface ParticipantRepository extends JpaRepository<JpaParticipant, PfConceptKey> {
+public interface ParticipantRepository extends JpaRepository<JpaParticipant, String> {
- Optional<JpaParticipant> findByParticipantId(String participantId);
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
index f6eb3e0ff..0ae1a90e2 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
@@ -27,22 +27,9 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
class ParticipantTest {
- @Test
- void testParticipant() {
-
- Participant p0 = new Participant();
- p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
- assertEquals("dfName", p0.getType());
- assertEquals("1.2.3", p0.getTypeVersion());
-
- Participant p1 = new Participant(p0);
- assertEquals(p0, p1);
-
- assertEquals(0, p0.compareTo(p1));
- }
@Test
void testParticipantLombok() {
@@ -57,11 +44,8 @@ class ParticipantTest {
Participant p1 = new Participant();
- p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
- p1.setDescription("Description");
- p1.setName("Name");
+ p1.setParticipantId(CommonTestData.getParticipantId());
p1.setParticipantState(ParticipantState.ON_LINE);
- p1.setVersion("0.0.1");
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
@@ -73,7 +57,6 @@ class ParticipantTest {
Participant p2 = new Participant();
// @formatter:off
- assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
// @formatter:on
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
index b798fb093..f293085c3 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
@@ -28,13 +28,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -42,71 +40,34 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
*/
class JpaParticipantTest {
- private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String NULL_KEY_ERROR = "participantId is marked .*ull but is null";
@Test
void testJpaParticipantConstructor() {
assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null))
.hasMessageMatching("copyConcept is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant((PfConceptKey) null)).hasMessageMatching(NULL_KEY_ERROR);
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, null, null, null, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(
- () -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, ParticipantState.ON_LINE, new ArrayList<>()))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE, null))
- .hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, null, null))
- .hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, null, null))
- .hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, ParticipantState.ON_LINE, null))
- .hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, ParticipantState.ON_LINE, null
- )).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null, new ArrayList<>()))
.hasMessageMatching("participantState is marked .*ull but is null");
- assertThatThrownBy(
- () -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null, null))
- .hasMessageMatching("participantState is marked .*ull but is null");
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE, null))
+ .hasMessageMatching("supportedElements is marked .*ull but is null");
assertNotNull(new JpaParticipant());
- assertNotNull(new JpaParticipant((new PfConceptKey())));
- assertNotNull(new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(),
- ParticipantState.ON_LINE, new ArrayList<>()));
- assertNotNull(new JpaParticipant(UUID.randomUUID().toString(), new PfConceptKey(),
- new PfConceptKey(), ParticipantState.ON_LINE, new ArrayList<>()));
+ assertNotNull(new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>()));
+
}
@Test
void testJpaParticipant() {
- JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+ var testJpaParticipant = createJpaParticipantInstance();
- Participant participant = createParticipantInstance();
+ var participant = createParticipantInstance();
participant.setParticipantId(testJpaParticipant.toAuthorative().getParticipantId());
@@ -117,38 +78,19 @@ class JpaParticipantTest {
assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)).isInstanceOf(NullPointerException.class);
- JpaParticipant testJpaParticipantFa = new JpaParticipant();
- testJpaParticipantFa.setKey(null);
+ var testJpaParticipantFa = new JpaParticipant();
testJpaParticipantFa.fromAuthorative(participant);
testJpaParticipantFa.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, testJpaParticipantFa);
- testJpaParticipantFa.setKey(PfConceptKey.getNullKey());
- testJpaParticipantFa.fromAuthorative(participant);
- assertEquals(testJpaParticipant, testJpaParticipantFa);
- testJpaParticipantFa.setKey(new PfConceptKey("participant", "0.0.1"));
- testJpaParticipantFa.fromAuthorative(participant);
- assertEquals(testJpaParticipant, testJpaParticipantFa);
-
- assertEquals("participant", testJpaParticipant.getKey().getName());
- assertEquals("participant", new JpaParticipant(createJpaParticipantInstance()).getKey().getName());
- assertEquals("participant",
- ((PfConceptKey) new JpaParticipant(createJpaParticipantInstance()).getKeys().get(0)).getName());
-
- testJpaParticipant.clean();
- assertEquals("participant", testJpaParticipant.getKey().getName());
- testJpaParticipant.setDescription(" A Message ");
- testJpaParticipant.clean();
- assertEquals("A Message", testJpaParticipant.getDescription());
-
- JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant);
+ var testJpaParticipant2 = new JpaParticipant(testJpaParticipant);
testJpaParticipant2.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, testJpaParticipant2);
}
@Test
void testJpaParticipantValidation() {
- JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+ var testJpaParticipant = createJpaParticipantInstance();
assertThatThrownBy(() -> testJpaParticipant.validate(null))
.hasMessageMatching("fieldName is marked .*ull but is null");
@@ -158,32 +100,22 @@ class JpaParticipantTest {
@Test
void testJpaParticipantCompareTo() {
- JpaParticipant testJpaParticipant = createJpaParticipantInstance();
+ var testJpaParticipant = createJpaParticipantInstance();
- JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant);
+ var otherJpaParticipant = new JpaParticipant(testJpaParticipant);
otherJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
assertEquals(-1, testJpaParticipant.compareTo(null));
assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant));
assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild()));
- testJpaParticipant.setKey(new PfConceptKey("BadValue", "0.0.1"));
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setKey(new PfConceptKey("participant", "0.0.1"));
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
-
- testJpaParticipant.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1"));
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
-
testJpaParticipant.setParticipantState(ParticipantState.OFF_LINE);
assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
testJpaParticipant.setParticipantState(ParticipantState.ON_LINE);
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
- JpaParticipant newJpaParticipant = new JpaParticipant(testJpaParticipant);
+ var newJpaParticipant = new JpaParticipant(testJpaParticipant);
newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, newJpaParticipant);
}
@@ -191,7 +123,7 @@ class JpaParticipantTest {
@Test
void testJpaParticipantLombok() {
assertNotNull(new Participant());
- JpaParticipant p0 = new JpaParticipant();
+ var p0 = new JpaParticipant();
assertThat(p0.toString()).contains("JpaParticipant(");
assertThat(p0.hashCode()).isNotZero();
@@ -199,11 +131,7 @@ class JpaParticipantTest {
assertNotEquals(null, p0);
- JpaParticipant p1 = new JpaParticipant();
-
- p1.setDefinition(new PfConceptKey("defName", "0.0.1"));
- p1.setDescription("Description");
- p1.setKey(new PfConceptKey("participant", "0.0.1"));
+ var p1 = new JpaParticipant();
p1.setParticipantState(ParticipantState.ON_LINE);
assertThat(p1.toString()).contains("Participant(");
@@ -213,28 +141,24 @@ class JpaParticipantTest {
assertNotEquals(p1, p0);
- JpaParticipant p2 = new JpaParticipant();
+ var p2 = new JpaParticipant();
p2.setParticipantId(p0.getParticipantId());
assertEquals(p2, p0);
}
private JpaParticipant createJpaParticipantInstance() {
- Participant testParticipant = createParticipantInstance();
- JpaParticipant testJpaParticipant = new JpaParticipant();
- testJpaParticipant.setKey(null);
+ var testParticipant = createParticipantInstance();
+ var testJpaParticipant = new JpaParticipant();
testParticipant.setParticipantId(UUID.fromString(testJpaParticipant.getParticipantId()));
testJpaParticipant.fromAuthorative(testParticipant);
- testJpaParticipant.setKey(PfConceptKey.getNullKey());
testJpaParticipant.fromAuthorative(testParticipant);
return testJpaParticipant;
}
private Participant createParticipantInstance() {
- Participant testParticipant = new Participant();
- testParticipant.setName("participant");
- testParticipant.setVersion("0.0.1");
- testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1"));
+ var testParticipant = new Participant();
+ testParticipant.setParticipantId(UUID.randomUUID());
testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1"));
testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>());
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 325272b69..a40d1cc1f 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
@@ -38,22 +38,20 @@ import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantReposi
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ParticipantProviderTest {
private static final Coder CODER = new StandardCoder();
private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
- private static final ToscaConceptIdentifier INVALID_ID = new ToscaConceptIdentifier("invalid_name", "1.0.1");
+ private static final UUID INVALID_ID = UUID.randomUUID();
private final List<Participant> inputParticipants = new ArrayList<>();
private List<JpaParticipant> jpaParticipantList;
private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
@BeforeEach
- void beforeSetupDao() throws Exception {
+ void beforeSetup() throws Exception {
inputParticipants.add(CODER.decode(originalJson, Participant.class));
jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
}
@@ -62,7 +60,7 @@ class ParticipantProviderTest {
void testParticipantSave() {
var participantRepository = mock(ParticipantRepository.class);
for (var participant : jpaParticipantList) {
- when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
+ when(participantRepository.getById(participant.getParticipantId()))
.thenReturn(participant);
}
var participantProvider = new ParticipantProvider(participantRepository);
@@ -71,7 +69,7 @@ class ParticipantProviderTest {
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
- Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0));
+ var savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0));
savedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
assertThat(savedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0));
@@ -81,7 +79,7 @@ class ParticipantProviderTest {
void testParticipantUpdate() {
var participantRepository = mock(ParticipantRepository.class);
for (var participant : jpaParticipantList) {
- when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
+ when(participantRepository.getById(participant.getParticipantId()))
.thenReturn(participant);
}
var participantProvider = new ParticipantProvider(participantRepository);
@@ -91,7 +89,7 @@ class ParticipantProviderTest {
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
- Participant updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0));
+ var updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0));
updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
assertThat(updatedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0));
}
@@ -106,7 +104,7 @@ class ParticipantProviderTest {
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size());
- when(participantRepository.findByParticipantId(any())).thenReturn(
+ when(participantRepository.findById(any())).thenReturn(
Optional.ofNullable(jpaParticipantList.get(0)));
var participant = participantProvider.getParticipantById(inputParticipants.get(0)
@@ -120,15 +118,14 @@ class ParticipantProviderTest {
var participantRepository = mock(ParticipantRepository.class);
var participantProvider = new ParticipantProvider(participantRepository);
- var participantId = UUID.randomUUID();
+ var participantId = inputParticipants.get(0).getParticipantId();
assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId))
.hasMessageMatching(".*.failed, participant does not exist");
- when(participantRepository.findByParticipantId(participantId.toString()))
+ when(participantRepository.findById(participantId.toString()))
.thenReturn(Optional.of(jpaParticipantList.get(0)));
- Participant deletedParticipant =
- participantProvider.deleteParticipant(participantId);
+ var deletedParticipant = participantProvider.deleteParticipant(participantId);
assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(deletedParticipant);
}
}
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 0d47fa6e3..88ace1706 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
@@ -20,8 +20,7 @@
package org.onap.policy.clamp.models.acm.utils;
-import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import java.util.UUID;
/**
* Class to hold/create all parameters for test cases.
@@ -29,14 +28,14 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
*/
public class CommonTestData {
- public static final ToscaConceptIdentifier PARTCICIPANT_ID = new ToscaConceptIdentifier("id", "1.2.3");
+ public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
/**
* Returns participantId for test cases.
*
* @return participant Id
*/
- public static ToscaConceptIdentifier getParticipantId() {
+ public static UUID getParticipantId() {
return PARTCICIPANT_ID;
}
@@ -45,16 +44,16 @@ public class CommonTestData {
*
* @return participant Id
*/
- public static PfConceptKey getJpaParticipantId() {
- return PARTCICIPANT_ID.asConceptKey();
+ public static String getJpaParticipantId() {
+ return PARTCICIPANT_ID.toString();
}
/**
- * Returns second participantId for test cases.
+ * Returns random participantId for test cases.
*
* @return participant Id
*/
- public static ToscaConceptIdentifier getRndParticipantId() {
- return new ToscaConceptIdentifier("idDiff", "1.2.3");
+ public static UUID getRndParticipantId() {
+ return UUID.randomUUID();
}
}