diff options
author | saul.gill <saul.gill@est.tech> | 2023-01-13 17:24:23 +0000 |
---|---|---|
committer | saul.gill <saul.gill@est.tech> | 2023-01-19 13:07:33 +0000 |
commit | 46964ab900060a560b9b41f7d34ab0e26ac7fd61 (patch) | |
tree | d4d15350f492cc19ee657df6cb926349bd724919 /models | |
parent | 48df549e1fd90c2768a78c0c88e87dc3834b6222 (diff) |
Add supported ac elements to participants
Added new supported elements table
Added supported element names and versions
to participant application.yaml files
Issue-ID: POLICY-4512
Change-Id: I97d7f571f2906846514ac0804b4827f0601177d7
Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'models')
13 files changed, 560 insertions, 27 deletions
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 c6da3c3d1..56c01837f 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 @@ -20,6 +20,7 @@ package org.onap.policy.clamp.models.acm.concepts; +import java.util.Map; import java.util.UUID; import lombok.Data; import lombok.EqualsAndHashCode; @@ -48,6 +49,9 @@ public class Participant extends ToscaEntity implements Comparable<Participant> @NonNull private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(); + @NonNull + private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes; + @Override public String getType() { return definition.getName(); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformation.java index c2f61aa74..a6a65fec5 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformation.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformation.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java new file mode 100644 index 000000000..310577167 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.concepts; + +import java.util.UUID; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.springframework.validation.annotation.Validated; + +@NoArgsConstructor +@Getter +@Setter +@Validated +public class ParticipantSupportedElementType { + + @NotNull + private UUID id = UUID.randomUUID(); + + @NotNull + private String typeName; + + @NotNull + private String typeVersion; + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param otherParticipantSupportedElementType the other element to copy from + */ + public ParticipantSupportedElementType(final ParticipantSupportedElementType otherParticipantSupportedElementType) { + this.id = otherParticipantSupportedElementType.getId(); + this.typeName = otherParticipantSupportedElementType.getTypeName(); + this.typeVersion = otherParticipantSupportedElementType.getTypeVersion(); + } +} 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 8b33d3172..c6d56904d 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java index 7b315dbe0..d8f9a4caf 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2023 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,9 +20,11 @@ package org.onap.policy.clamp.models.acm.messages.dmaap.participant; +import java.util.List; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; /** * Class to represent the PARTICIPANT_REGISTER message that all the participants send to the ACM runtime. @@ -32,6 +34,8 @@ import lombok.ToString; @ToString(callSuper = true) public class ParticipantRegister extends ParticipantMessage { + private List<ParticipantSupportedElementType> participantSupportedElementType; + /** * Constructor for instantiating ParticipantRegister class with message name. * @@ -47,5 +51,6 @@ public class ParticipantRegister extends ParticipantMessage { */ public ParticipantRegister(final ParticipantRegister source) { super(source); + this.participantSupportedElementType = source.getParticipantSupportedElementType(); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java index 31a42c548..2412bddcb 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java @@ -28,6 +28,7 @@ import lombok.ToString; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.models.base.PfUtils; /** @@ -47,10 +48,12 @@ public class ParticipantStatus extends ParticipantMessage { // List of AutomationCompositionInfo types with AutomationCompositionId and its state private List<AutomationCompositionInfo> automationCompositionInfoList = new ArrayList<>(); + private List<ParticipantSupportedElementType> participantSupportedElementType; /** * Constructor for instantiating ParticipantStatus class with message name. * */ + public ParticipantStatus() { super(ParticipantMessageType.PARTICIPANT_STATUS); } @@ -68,5 +71,6 @@ public class ParticipantStatus extends ParticipantMessage { PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new); this.automationCompositionInfoList = PfUtils.mapList(source.automationCompositionInfoList, AutomationCompositionInfo::new); + this.participantSupportedElementType = source.getParticipantSupportedElementType(); } } 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 398daa245..7d043ace0 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 @@ -21,14 +21,21 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; 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.Inheritance; import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; @@ -37,6 +44,7 @@ import org.apache.commons.lang3.ObjectUtils; import org.onap.policy.clamp.models.acm.concepts.Participant; 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; @@ -86,6 +94,12 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa @Column private String description; + @NotNull + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @JoinColumn(name = "participantId", referencedColumnName = "participantId", + foreignKey = @ForeignKey(name = "supported_element_fk")) + private List<@NotNull @Valid JpaParticipantSupportedElementType> supportedElements; + /** * The Default Constructor creates a {@link JpaParticipant} object with a null key. */ @@ -99,7 +113,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa * @param key the key */ public JpaParticipant(@NonNull final PfConceptKey key) { - this(UUID.randomUUID().toString(), key, new PfConceptKey(), ParticipantState.ON_LINE); + this(UUID.randomUUID().toString(), key, new PfConceptKey(), ParticipantState.ON_LINE, new ArrayList<>()); } /** @@ -113,11 +127,13 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa public JpaParticipant(@NotNull String participantId, @NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, - @NonNull final ParticipantState participantState) { + @NonNull final ParticipantState participantState, + @NonNull final List<JpaParticipantSupportedElementType> supportedAcElementTypes) { this.key = key; this.definition = definition; this.participantState = participantState; this.participantId = participantId; + this.supportedElements = supportedAcElementTypes; } /** @@ -133,6 +149,7 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa this.description = copyConcept.description; this.participantType = copyConcept.participantType; this.participantId = copyConcept.participantId; + this.supportedElements = copyConcept.supportedElements; } /** @@ -155,6 +172,11 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa participant.setDescription(description); participant.setParticipantType(new ToscaConceptIdentifier(participantType)); participant.setParticipantId(UUID.fromString(participantId)); + participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size())); + for (var element : this.supportedElements) { + participant.getParticipantSupportedElementTypes() + .put(UUID.fromString(element.getId()), element.toAuthorative()); + } return participant; } @@ -170,6 +192,14 @@ public class JpaParticipant extends PfConcept implements PfAuthorative<Participa this.setDescription(participant.getDescription()); this.participantType = participant.getParticipantType().asConceptKey(); this.participantId = participant.getParticipantId().toString(); + this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size()); + + for (var elementEntry : participant.getParticipantSupportedElementTypes().entrySet()) { + var jpaParticipantSupportedElementType = new JpaParticipantSupportedElementType(); + jpaParticipantSupportedElementType.setParticipantId(this.participantId); + jpaParticipantSupportedElementType.fromAuthorative(elementEntry.getValue()); + this.supportedElements.add(jpaParticipantSupportedElementType); + } } @Override diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java new file mode 100644 index 000000000..906f66fa9 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementType.java @@ -0,0 +1,176 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.concepts; + +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.Validated; + +@Entity +@Table(name = "ParticipantSupportedAcElements") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaParticipantSupportedElementType extends Validated + implements PfAuthorative<ParticipantSupportedElementType>, Comparable<JpaParticipantSupportedElementType> { + + @NotNull + @Column + @Id + private String id; + @NotNull + @Column + private String participantId; + + @NotNull + @Column + private String typeName; + + @NotNull + @Column + private String typeVersion; + + /** + * The default Constructor creates a {@link JpaParticipantSupportedElementType} with a generated id. + * + */ + public JpaParticipantSupportedElementType() { + this(UUID.randomUUID().toString()); + } + + /** + * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with just a generated id parameter. + * + * @param id the main id of the element type + */ + public JpaParticipantSupportedElementType(@NonNull String id) { + this(id, UUID.randomUUID().toString()); + } + + /** + * The Key Constructor creates a {@link JpaParticipantSupportedElementType} with id and participantId. + * + * @param id the main id of the element type + * @param participantId the participant id + */ + public JpaParticipantSupportedElementType(@NonNull String id, @NonNull String participantId) { + this(id, participantId, "", ""); + } + + /** + * The Key Constructor creates a {@link JpaParticipantSupportedElementType} object with all mandatory fields. + * + * @param id the main id of the element type + * @param participantId the participant id + * @param typeName the type name of the supported element + * @param typeVersion the type version of the supported element + */ + public JpaParticipantSupportedElementType(@NonNull String id, + @NonNull String participantId, + @NonNull String typeName, + @NonNull String typeVersion) { + this.id = id; + this.participantId = participantId; + this.typeName = typeName; + this.typeVersion = typeVersion; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaParticipantSupportedElementType(@NonNull final JpaParticipantSupportedElementType copyConcept) { + this.id = copyConcept.id; + this.participantId = copyConcept.participantId; + this.typeName = copyConcept.typeName; + this.typeVersion = copyConcept.typeVersion; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaParticipantSupportedElementType(@NonNull final ParticipantSupportedElementType authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public int compareTo(final JpaParticipantSupportedElementType other) { + if (other == null) { + return -1; + } + if (this == other) { + return 0; + } + + var result = ObjectUtils.compare(participantId, other.participantId); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(typeName, other.typeName); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(id, other.id); + if (result != 0) { + return result; + } + + result = typeVersion.compareTo(other.typeVersion); + if (result != 0) { + return result; + } + + return 0; + } + + @Override + public ParticipantSupportedElementType toAuthorative() { + var element = new ParticipantSupportedElementType(); + element.setId(UUID.fromString(id)); + element.setTypeName(typeName); + element.setTypeVersion(typeVersion); + return element; + } + + @Override + public void fromAuthorative(@NonNull ParticipantSupportedElementType participantSupportedElementType) { + this.id = participantSupportedElementType.getId().toString(); + this.typeName = participantSupportedElementType.getTypeName(); + this.typeVersion = participantSupportedElementType.getTypeVersion(); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java new file mode 100644 index 000000000..fac98043d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.UUID; +import org.junit.jupiter.api.Test; + +public class ParticipantsSupportedElementTypesTest { + + private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e"; + private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a"; + + @Test + void testParticipant() { + + ParticipantSupportedElementType p0 = new ParticipantSupportedElementType(); + p0.setId(UUID.fromString(ID)); + assertEquals(ID, p0.getId().toString()); + + ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(p0); + + assertThat(p0).usingRecursiveComparison().isEqualTo(p1); + } + + @Test + void testParticipantLombok() { + assertNotNull(new ParticipantSupportedElementType()); + ParticipantSupportedElementType p0 = new ParticipantSupportedElementType(); + + assertThat(p0.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType"); + assertThat(p0.hashCode()).isNotZero(); + assertThat(p0).usingRecursiveComparison().isEqualTo(new ParticipantSupportedElementType(p0)); + assertNotEquals(null, p0); + + + ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(); + + p1.setId(UUID.fromString(ID)); + p1.setTypeName("name"); + p1.setTypeVersion("1.0.0"); + + assertThat(p1.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType"); + assertNotEquals(0, p1.hashCode()); + assertNotEquals(p1, p0); + assertNotEquals(null, p1); + + + ParticipantSupportedElementType p2 = new ParticipantSupportedElementType(); + p2.setId(p0.getId()); + + assertThat(p0).usingRecursiveComparison().isEqualTo(p2); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java new file mode 100644 index 000000000..2faf9e17a --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 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.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; + +/** + * Test the {@link JpaParticipantSupportedElementType} class. + */ +public class JpaParticipantSupportedElementTypeTest { + + private static final String NULL_PARTICIPANT_ID_ERROR = "participantId is marked .*ull but is null"; + private static final String NULL_ID_ERROR = "id is marked .*ull but is null"; + private static final String NULL_ERROR = " is marked .*ull but is null"; + private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e"; + private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a"; + + @Test + void testJpaAutomationCompositionElementConstructor() { + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType((JpaParticipantSupportedElementType) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType("key", null); + }).hasMessageMatching(NULL_PARTICIPANT_ID_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType(null, "key"); + }).hasMessageMatching(NULL_ID_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType(null, null); + }).hasMessageMatching(NULL_ID_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType(null, null, null, null); + }).hasMessageMatching(NULL_ID_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType("key", null, null, null); + }).hasMessageMatching(NULL_PARTICIPANT_ID_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType("key", "key", null, "1.0.0"); + }).hasMessageMatching("typeName" + NULL_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantSupportedElementType("key", "key", "name", null); + }).hasMessageMatching("typeVersion" + NULL_ERROR); + + assertNotNull(new JpaParticipantSupportedElementType()); + assertNotNull(new JpaParticipantSupportedElementType("key", "key")); + assertNotNull(new JpaParticipantSupportedElementType("key", "key", "name", + "1.0.0")); + } + + @Test + void testJpaParticipantSupportedElementType() { + var testJpaSupportElement = createJpaParticipantSupportedElementType(); + + var testSupportedElement = createParticipantSupportedElementType(); + assertEquals(testSupportedElement.getId(), testJpaSupportElement.toAuthorative().getId()); + assertEquals(testSupportedElement.getTypeName(), testJpaSupportElement.toAuthorative().getTypeName()); + assertEquals(testSupportedElement.getTypeVersion(), testJpaSupportElement.toAuthorative().getTypeVersion()); + + assertThatThrownBy(() -> { + testJpaSupportElement.fromAuthorative(null); + }).hasMessageMatching("participantSupportedElementType is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipantSupportedElementType((JpaParticipantSupportedElementType) null)) + .isInstanceOf(NullPointerException.class); + + var testJpaSupportElementFa = + new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(), + testJpaSupportElement.getParticipantId()); + testJpaSupportElementFa.fromAuthorative(testSupportedElement); + assertEquals(testJpaSupportElement, testJpaSupportElementFa); + + assertEquals(ID, testJpaSupportElement.getId()); + + var testJpaSupportElement2 = new JpaParticipantSupportedElementType(testJpaSupportElement); + assertEquals(testJpaSupportElement, testJpaSupportElement2); + } + + @Test + void testJpaAutomationCompositionElementCompareTo() { + var testJpaSupportElement = createJpaParticipantSupportedElementType(); + + var otherJpaSupportElement = + new JpaParticipantSupportedElementType(testJpaSupportElement); + assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + assertEquals(-1, testJpaSupportElement.compareTo(null)); + assertEquals(0, testJpaSupportElement.compareTo(testJpaSupportElement)); + + testJpaSupportElement.setId("BadValue"); + assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + testJpaSupportElement.setId(ID); + assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + + testJpaSupportElement.setParticipantId("BadValue"); + assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + testJpaSupportElement.setParticipantId(PARTICIPANT_ID); + assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + + testJpaSupportElement.setTypeName("BadName"); + assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + testJpaSupportElement.setTypeName("type"); + assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + + testJpaSupportElement.setTypeVersion("BadVersion"); + assertNotEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + testJpaSupportElement.setTypeVersion("1.0.0"); + assertEquals(0, testJpaSupportElement.compareTo(otherJpaSupportElement)); + + assertEquals(testJpaSupportElement, + new JpaParticipantSupportedElementType(otherJpaSupportElement)); + } + + private JpaParticipantSupportedElementType createJpaParticipantSupportedElementType() { + var testSupportedElement = createParticipantSupportedElementType(); + var testJpaSupportElement = new JpaParticipantSupportedElementType(testSupportedElement.getId().toString(), + PARTICIPANT_ID); + + testJpaSupportElement.fromAuthorative(testSupportedElement); + + return testJpaSupportElement; + } + + private ParticipantSupportedElementType createParticipantSupportedElementType() { + var testSupportedElement = new ParticipantSupportedElementType(); + testSupportedElement.setId(UUID.fromString(ID)); + testSupportedElement.setTypeName("type"); + testSupportedElement.setTypeVersion("1.0.0"); + + return testSupportedElement; + } +} 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 0fbdaa2bc..b798fb093 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 @@ -27,6 +27,9 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; 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; @@ -48,54 +51,55 @@ class JpaParticipantTest { assertThatThrownBy(() -> new JpaParticipant((PfConceptKey) null)).hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(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, null)) + assertThatThrownBy(() -> new JpaParticipant(null, null, null, null, null)) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE)) + assertThatThrownBy(() -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE, null)) .hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy( - () -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE)) + () -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE, null)) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null)) + assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null, null)) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null)) + assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null, null)) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE)) + 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)) + assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE, null)) .hasMessageMatching(NULL_KEY_ERROR); - assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, 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, 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)) + 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 + 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)) + assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null, null)) .hasMessageMatching("participantState is marked .*ull but is null"); assertThatThrownBy( - () -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null)) + () -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null, null)) .hasMessageMatching("participantState 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)); + 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 PfConceptKey(), ParticipantState.ON_LINE, new ArrayList<>())); } @Test @@ -232,6 +236,7 @@ class JpaParticipantTest { testParticipant.setVersion("0.0.1"); testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1")); testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1")); + testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>()); return testParticipant; } 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 ccb20ea8e..325272b69 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,7 +22,6 @@ 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.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -74,7 +73,8 @@ class ParticipantProviderTest { Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0)); savedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId()); - assertEquals(savedParticipant, inputParticipants.get(0)); + + assertThat(savedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0)); } @Test @@ -93,7 +93,7 @@ class ParticipantProviderTest { Participant updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0)); updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId()); - assertEquals(updatedParticipant, inputParticipants.get(0)); + assertThat(updatedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0)); } @Test @@ -112,7 +112,7 @@ class ParticipantProviderTest { var participant = participantProvider.getParticipantById(inputParticipants.get(0) .getParticipantId()); - assertThat(participant).isEqualTo(inputParticipants.get(0)); + assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(participant); } @Test @@ -127,7 +127,8 @@ class ParticipantProviderTest { when(participantRepository.findByParticipantId(participantId.toString())) .thenReturn(Optional.of(jpaParticipantList.get(0))); - var deletedParticipant = participantProvider.deleteParticipant(participantId); - assertEquals(inputParticipants.get(0), deletedParticipant); + Participant deletedParticipant = + participantProvider.deleteParticipant(participantId); + assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(deletedParticipant); } } diff --git a/models/src/test/resources/providers/TestParticipant.json b/models/src/test/resources/providers/TestParticipant.json index 99284cb6a..2f4f910f1 100644 --- a/models/src/test/resources/providers/TestParticipant.json +++ b/models/src/test/resources/providers/TestParticipant.json @@ -11,5 +11,19 @@ "participantType":{ "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition", "version": "1.0.0" + }, + "participantSupportedElementTypes": { + "68fe8c61-7629-4be7-99d8-18bc6a92d178": { + "id": "68fe8c61-7629-4be7-99d8-18bc6a92d178", + "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6", + "typeName": "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", + "typeVersion": "1.0.0" + }, + "e2429b9d-7195-4690-a5ea-8ccebff19a14": { + "id": "e2429b9d-7195-4690-a5ea-8ccebff19a14", + "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6", + "typeName": "org.onap.policy.clamp.acm.AutomationCompositionElement", + "typeVersion": "1.0.0" + } } } |