From 3164fd8bd0cb8d3c682fa02093a866c7655cd111 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 18 Jan 2023 10:31:34 +0000 Subject: Remove reference type of participantId in Unit Tests in ACM As part of the participantId refactoring, reduce the impact of the changes by removing the reference type of participantId in unit tests. Issue-ID: POLICY-4524 Change-Id: I08837a0739f229a0a8c439c8b12578823277aa32 Signed-off-by: FrancescoFioraEst --- .../src/main/resources/META-INF/persistence.xml | 78 ---------------------- .../policy/endtoend/ParticipantMessagesTest.java | 11 ++- .../AutomationCompositionElementHandlerTest.java | 7 +- .../policy/main/parameters/CommonTestData.java | 15 ++++- .../policy/main/utils/TestListenerUtils.java | 26 ++++---- 5 files changed, 32 insertions(+), 105 deletions(-) delete mode 100644 participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml (limited to 'participant/participant-impl/participant-impl-policy/src') diff --git a/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml b/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index d5eae7390..000000000 --- a/participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - org.eclipse.persistence.jpa.PersistenceProvider - - org.onap.policy.models.base.PfConceptKey - org.onap.policy.models.dao.converters.CDataConditioner - org.onap.policy.models.dao.converters.Uuid2String - org.onap.policy.models.pdp.persistence.concepts.JpaPdp - org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup - org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics - org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup - org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment - org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments - org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityType - org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityTypes - org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType - org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes - org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate - org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates - org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType - org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes - org.onap.policy.models.tosca.simple.concepts.JpaToscaParameter - org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies - org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy - org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType - org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes - org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty - org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipType - org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipTypes - org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirement - org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirements - org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate - org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate - org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger - org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition - org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement - org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant - org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantSupportedElementType - - - - - - - - NONE - - - diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java index 091e3c13c..6d52d7a94 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java @@ -35,6 +35,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantRegisterAckListener; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantUpdateListener; import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; +import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData; import org.onap.policy.clamp.acm.participant.policy.main.utils.TestListenerUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; @@ -67,7 +68,7 @@ class ParticipantMessagesTest { @Test void testSendParticipantRegisterMessage() { final ParticipantRegister participantRegisterMsg = new ParticipantRegister(); - participantRegisterMsg.setParticipantId(getParticipantId()); + participantRegisterMsg.setParticipantId(CommonTestData.getParticipantId()); participantRegisterMsg.setTimestamp(Instant.now()); participantRegisterMsg.setParticipantType(getParticipantType()); @@ -98,7 +99,7 @@ class ParticipantMessagesTest { @Test void testSendParticipantDeregisterMessage() { final ParticipantDeregister participantDeregisterMsg = new ParticipantDeregister(); - participantDeregisterMsg.setParticipantId(getParticipantId()); + participantDeregisterMsg.setParticipantId(CommonTestData.getParticipantId()); participantDeregisterMsg.setTimestamp(Instant.now()); participantDeregisterMsg.setParticipantType(getParticipantType()); @@ -136,7 +137,7 @@ class ParticipantMessagesTest { } // Verify the result of GET participants with what is stored - assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName()); + assertEquals(CommonTestData.getParticipantId(), participantHandler.getParticipantId()); } @Test @@ -164,10 +165,6 @@ class ParticipantMessagesTest { } } - private ToscaConceptIdentifier getParticipantId() { - return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); - } - private ToscaConceptIdentifier getParticipantType() { return new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"); } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java index c28355d7f..4fc10b828 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java @@ -33,6 +33,7 @@ import org.mockito.Mockito; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient; import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient; +import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; @@ -49,7 +50,7 @@ class AutomationCompositionElementHandlerTest { private static final String ID_VERSION = "1.0.1"; private static final UUID automationCompositionElementId = UUID.randomUUID(); public static final UUID AC_ID = UUID.randomUUID(); - private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); + private static final ToscaConceptIdentifier DEFINITION = new ToscaConceptIdentifier(ID_NAME, ID_VERSION); private PolicyApiHttpClient api = Mockito.mock(PolicyApiHttpClient.class); private PolicyPapHttpClient pap = Mockito.mock(PolicyPapHttpClient.class); @@ -77,11 +78,11 @@ class AutomationCompositionElementHandlerTest { private AutomationCompositionElement getTestingAcElement() { var element = new AutomationCompositionElement(); - element.setDefinition(PARTICIPANT_ID); + element.setDefinition(DEFINITION); element.setDescription("Description"); element.setId(automationCompositionElementId); element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - element.setParticipantId(PARTICIPANT_ID); + element.setParticipantId(CommonTestData.getParticipantId()); element.setState(AutomationCompositionState.UNINITIALISED); var template = new ToscaServiceTemplate(); template.setToscaTopologyTemplate(new ToscaTopologyTemplate()); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java index bfba15551..b69c5c353 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java @@ -122,7 +122,7 @@ public class CommonTestData { map.put("reportingTimeIntervalMs", TIME_INTERVAL); map.put("description", DESCRIPTION); map.put("participantId", getParticipantId()); - map.put("participantType", getParticipantId()); + map.put("participantType", getParticipantType()); map.put("clampAutomationCompositionTopics", getTopicParametersMap(false)); map.put("participantSupportedElementTypes", new ArrayList<>()); } @@ -158,13 +158,22 @@ public class CommonTestData { return topicParams; } + /** + * Returns participantType for test cases. + * + * @return participant Type + */ + public static ToscaConceptIdentifier getParticipantType() { + return new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); + } + + /** * Returns participantId for test cases. * * @return participant Id */ public static ToscaConceptIdentifier getParticipantId() { - return new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); + return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); } - } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java index 59d64e754..31d62c70e 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java @@ -25,10 +25,10 @@ import static org.junit.Assert.assertTrue; import java.io.FileNotFoundException; import java.time.Instant; import java.util.ArrayList; -import java.util.Set; import java.util.UUID; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -49,10 +49,10 @@ public final class TestListenerUtils { * @return ParticipantUpdate message */ public static ParticipantUpdate createParticipantUpdateMsg() { - final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate(); - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); - ToscaConceptIdentifier participantType = - new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"); + final var participantUpdateMsg = new ParticipantUpdate(); + var participantId = CommonTestData.getParticipantId(); + var participantType = + new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"); participantUpdateMsg.setParticipantId(participantId); participantUpdateMsg.setTimestamp(Instant.now()); @@ -60,7 +60,7 @@ public final class TestListenerUtils { participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); participantUpdateMsg.setMessageId(UUID.randomUUID()); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); + var toscaServiceTemplate = testAutomationCompositionRead(); // Add policies to the toscaServiceTemplate TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate); @@ -69,8 +69,7 @@ public final class TestListenerUtils { } private static ToscaServiceTemplate testAutomationCompositionRead() { - Set automationCompositionDirectoryContents = - ResourceUtils.getDirectoryContents("clamp/acm/test"); + var automationCompositionDirectoryContents = ResourceUtils.getDirectoryContents("clamp/acm/test"); boolean atLeastOneAutomationCompositionTested = false; ToscaServiceTemplate toscaServiceTemplate = null; @@ -91,13 +90,13 @@ public final class TestListenerUtils { } private static void addPolicyTypesToToscaServiceTemplate(ToscaServiceTemplate toscaServiceTemplate) { - Set policyTypeDirectoryContents = ResourceUtils.getDirectoryContents("policytypes"); + var policyTypeDirectoryContents = ResourceUtils.getDirectoryContents("policytypes"); for (String policyTypeFilePath : policyTypeDirectoryContents) { String policyTypeString = ResourceUtils.getResourceAsString(policyTypeFilePath); - ToscaServiceTemplate foundPolicyTypeSt = - yamlTranslator.fromYaml(policyTypeString, ToscaServiceTemplate.class); + var foundPolicyTypeSt = + yamlTranslator.fromYaml(policyTypeString, ToscaServiceTemplate.class); toscaServiceTemplate.setDerivedFrom(foundPolicyTypeSt.getDerivedFrom()); toscaServiceTemplate.setDescription(foundPolicyTypeSt.getDescription()); @@ -138,8 +137,7 @@ public final class TestListenerUtils { var policiesString = ResourceUtils.getResourceAsString(policiesFilePath); - var foundPoliciesSt = - yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class); + var foundPoliciesSt = yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class); if (foundPoliciesSt.getToscaTopologyTemplate() != null && foundPoliciesSt.getToscaTopologyTemplate().getPolicies() != null) { toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() @@ -149,7 +147,7 @@ public final class TestListenerUtils { } private static ToscaServiceTemplate testAutomationCompositionYamlSerialization( - String automationCompositionFilePath) { + String automationCompositionFilePath) { try { String automationCompositionString = ResourceUtils.getResourceAsString(automationCompositionFilePath); if (automationCompositionString == null) { -- cgit 1.2.3-korg