diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-01-17 09:56:52 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-01-23 15:22:35 +0000 |
commit | c5e57c1b1cd0e778ebf47edd20fd9a340471ab72 (patch) | |
tree | f567d2bc52cf070bcccb83bad0f4ab5f70d2415f /models/src/test | |
parent | a263a250f7185fd9ddc4b600d96452fdbf21fffb (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/src/test')
4 files changed, 43 insertions, 140 deletions
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(); } } |