diff options
Diffstat (limited to 'models/src/test/java')
4 files changed, 267 insertions, 22 deletions
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); } } |