summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-18 10:31:34 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-23 09:11:13 +0000
commit3164fd8bd0cb8d3c682fa02093a866c7655cd111 (patch)
tree2c364929b3421919257481b3e453b1b3d90adfdd /participant
parent46964ab900060a560b9b41f7d34ab0e26ac7fd61 (diff)
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 <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/resources/META-INF/persistence.xml78
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java11
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java7
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java15
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java26
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java9
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java72
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java25
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java76
9 files changed, 135 insertions, 184 deletions
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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- 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.
- 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=========================================================
--->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="ToscaConceptTest" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.models.base.PfConceptKey</class>
- <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
- <class>org.onap.policy.models.dao.converters.Uuid2String</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaParameter</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirement</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirements</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class>
- <class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantSupportedElementType</class>
- <properties>
- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
-
- <!-- property name="eclipselink.logging.level" value="ALL" />
- <property name="eclipselink.logging.level.jpa" value="ALL" />
- <property name="eclipselink.logging.level.ddl" value="ALL" />
- <property name="eclipselink.logging.level.connection" value="ALL" />
- <property name="eclipselink.logging.level.sql" value="ALL" />
- <property name="eclipselink.logging.level.transaction" value="ALL" />
- <property name="eclipselink.logging.level.sequencing" value="ALL" />
- <property name="eclipselink.logging.level.server" value="ALL" />
- <property name="eclipselink.logging.level.query" value="ALL" />
- <property name="eclipselink.logging.level.properties" value="ALL" /-->
- </properties>
- <shared-cache-mode>NONE</shared-cache-mode>
- </persistence-unit>
-</persistence>
-
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<>());
}
@@ -159,12 +159,21 @@ public class CommonTestData {
}
/**
+ * 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<String> 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<String> 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) {
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
index bc5db8571..9b0f910ea 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
@@ -31,19 +31,18 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedSta
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ParticipantIntermediaryApiImplTest {
private final CommonTestData commonTestData = new CommonTestData();
- private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
- private static final String ID_VERSION = "1.0.1";
@Test
void mockParticipantIntermediaryApiImplTest() throws CoderException {
var uuid = UUID.randomUUID();
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- var automationComposiitonHandler = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var definition = CommonTestData.getDefinition();
+ var participantId = CommonTestData.getParticipantId();
+ var automationComposiitonHandler =
+ commonTestData.setTestAutomationCompositionHandler(definition, uuid, participantId);
var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler);
var acElementListener = Mockito.mock(AutomationCompositionElementListener.class);
apiImpl.registerAutomationCompositionElementListener(acElementListener);
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index 8b52c1cfe..dc9e3d307 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
-import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -41,7 +40,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -83,11 +81,12 @@ class AutomationCompositionHandlerTest {
}
@Test
- void updateAutomationCompositionHandlerTest() throws CoderException {
+ void updateAutomationCompositionHandlerTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
var key = ach.getElementsOnThisParticipant().keySet().iterator().next();
var value = ach.getElementsOnThisParticipant().get(key);
assertEquals(AutomationCompositionState.UNINITIALISED, value.getState());
@@ -108,26 +107,27 @@ class AutomationCompositionHandlerTest {
}
@Test
- void handleAutomationCompositionUpdateExceptionTest() throws CoderException {
+ void handleAutomationCompositionUpdateExceptionTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
- var stateChange = getStateChange(id, uuid, AutomationCompositionOrderedState.RUNNING);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var stateChange = commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.RUNNING);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
assertDoesNotThrow(() -> ach
.handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
ach.handleAutomationCompositionStateChange(stateChange, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ var newPartecipantId = CommonTestData.getRndParticipantId();
stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(newid);
+ stateChange.setParticipantId(newPartecipantId);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
var acd = new AutomationCompositionElementDefinition();
- acd.setAcElementDefinitionId(id);
+ acd.setAcElementDefinitionId(definition);
var updateMsg = new AutomationCompositionUpdate();
updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setMessageId(uuid);
- updateMsg.setParticipantId(id);
+ updateMsg.setParticipantId(partecipantId);
updateMsg.setStartPhase(0);
var acElementDefinitions = List.of(acd);
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
@@ -144,60 +144,50 @@ class AutomationCompositionHandlerTest {
updateMsg.setStartPhase(1);
var participantUpdate = new ParticipantUpdates();
- participantUpdate.setParticipantId(id);
+ participantUpdate.setParticipantId(partecipantId);
var element = new AutomationCompositionElement();
- element.setParticipantType(id);
- element.setDefinition(id);
+ element.setParticipantType(definition);
+ element.setDefinition(definition);
participantUpdate.setAutomationCompositionElementList(List.of(element));
updateMsg.setParticipantUpdatesList(List.of(participantUpdate));
var acd2 = new AutomationCompositionElementDefinition();
- acd2.setAcElementDefinitionId(id);
+ acd2.setAcElementDefinitionId(definition);
acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, List.of(acd2)));
}
@Test
- void automationCompositionStateChangeUninitialisedTest() throws CoderException {
+ void automationCompositionStateChangeUninitialisedTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var stateChangeUninitialised = getStateChange(id, uuid, AutomationCompositionOrderedState.UNINITIALISED);
+ var stateChangeUninitialised =
+ commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.UNINITIALISED);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID());
- stateChangeUninitialised.setParticipantId(newid);
+ stateChangeUninitialised.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()));
}
@Test
- void automationCompositionStateChangePassiveTest() throws CoderException {
+ void automationCompositionStateChangePassiveTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var stateChangePassive = getStateChange(id, uuid, AutomationCompositionOrderedState.PASSIVE);
+ var stateChangePassive =
+ commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.PASSIVE);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
ach.handleAutomationCompositionStateChange(stateChangePassive, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChangePassive.setAutomationCompositionId(UUID.randomUUID());
- stateChangePassive.setParticipantId(newid);
+ stateChangePassive.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()));
}
- private AutomationCompositionStateChange getStateChange(ToscaConceptIdentifier id, UUID uuid,
- AutomationCompositionOrderedState state) {
- var stateChange = new AutomationCompositionStateChange();
- stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(id);
- stateChange.setMessageId(uuid);
- stateChange.setOrderedState(state);
- stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED);
- stateChange.setTimestamp(Instant.ofEpochMilli(3000));
- return stateChange;
- }
-
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
index f6988b0e8..8e65abffb 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Instant;
-import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -62,39 +61,37 @@ class ParticipantHandlerTest {
var participantHandler = commonTestData.getMockParticipantHandler();
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantType = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantId = CommonTestData.getParticipantId();
participantUpdateMsg.setAutomationCompositionId(CommonTestData.AC_ID_1);
participantUpdateMsg.setCompositionId(CommonTestData.AC_ID_1);
- participantUpdateMsg.setParticipantId(id);
- participantUpdateMsg.setParticipantType(id);
+ participantUpdateMsg.setParticipantId(participantId);
+ participantUpdateMsg.setParticipantType(participantType);
participantUpdateMsg.setMessageId(UUID.randomUUID());
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
var heartbeatF = participantHandler.makeHeartbeat(false);
- assertEquals(id, heartbeatF.getParticipantId());
+ assertEquals(participantId, heartbeatF.getParticipantId());
assertThat(heartbeatF.getAutomationCompositionInfoList()).isEmpty();
participantHandler.handleParticipantUpdate(participantUpdateMsg);
var heartbeatT = participantHandler.makeHeartbeat(true);
- assertEquals(id, heartbeatT.getParticipantId());
+ assertEquals(participantId, heartbeatT.getParticipantId());
assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
- assertEquals(id, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
+ assertEquals(participantId, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
var pum = setListParticipantDefinition(participantUpdateMsg);
participantHandler.handleParticipantUpdate(pum);
var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
- assertEquals(id, heartbeatTAfterUpdate.getParticipantId());
+ assertEquals(participantId, heartbeatTAfterUpdate.getParticipantId());
}
private ParticipantUpdate setListParticipantDefinition(ParticipantUpdate participantUpdateMsg) {
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
var def = new ParticipantDefinition();
- def.setParticipantId(id);
- def.setParticipantType(id);
- participantDefinitionUpdates.add(def);
- participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ def.setParticipantId(CommonTestData.getParticipantId());
+ def.setParticipantType(new ToscaConceptIdentifier(ID_NAME, ID_VERSION));
+ participantUpdateMsg.setParticipantDefinitionUpdates(List.of(def));
return participantUpdateMsg;
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index 0e35c480b..b7d66bec6 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -21,9 +21,9 @@
package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
import java.io.File;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -38,7 +38,9 @@ import org.onap.policy.clamp.acm.participant.intermediary.parameters.Participant
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
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;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
@@ -59,6 +61,8 @@ public class CommonTestData {
private static final Object lockit = new Object();
public static final UUID AC_ID_0 = UUID.randomUUID();
public static final UUID AC_ID_1 = UUID.randomUUID();
+ public static final ToscaConceptIdentifier PARTCICIPANT_ID =
+ new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
/**
* Get ParticipantIntermediaryParameters.
@@ -110,7 +114,7 @@ public class CommonTestData {
map.put("name", name);
map.put("participantId", getParticipantId());
map.put("description", DESCRIPTION);
- map.put("participantType", getParticipantId());
+ map.put("participantType", getDefinition());
map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
map.put("participantSupportedElementTypes", new ArrayList<>());
@@ -152,6 +156,14 @@ public class CommonTestData {
* @return participant Id
*/
public static ToscaConceptIdentifier getParticipantId() {
+ return PARTCICIPANT_ID;
+ }
+
+ public static ToscaConceptIdentifier getRndParticipantId() {
+ return new ToscaConceptIdentifier("diff", "0.0.0");
+ }
+
+ public static ToscaConceptIdentifier getDefinition() {
return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
}
@@ -221,7 +233,7 @@ public class CommonTestData {
*
* @throws CoderException if there is an error with .json file.
*/
- public Map<UUID, AutomationComposition> getTestAutomationCompositionMap() throws CoderException {
+ public Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
var automationCompositions = getTestAutomationCompositions();
var automationComposition = automationCompositions.getAutomationCompositionList().get(1);
Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
@@ -236,26 +248,32 @@ public class CommonTestData {
*
* @throws CoderException if there is an error with .json file.
*/
- public AutomationCompositions getTestAutomationCompositions() throws CoderException {
- var automationCompositions = new StandardCoder().decode(
- new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
- automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
- automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
- return automationCompositions;
+ public AutomationCompositions getTestAutomationCompositions() {
+ try {
+ var automationCompositions =
+ new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
+ AutomationCompositions.class);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
+ return automationCompositions;
+ } catch (Exception e) {
+ throw new RuntimeException("cannot read TestAutomationCompositions.json");
+ }
}
/**
* Returns a map for a elementsOnThisParticipant for test cases.
*
- * @param uuid UUID and id ToscaConceptIdentifier
+ * @param uuid UUID
+ * @param definition ToscaConceptIdentifier
* @return a map suitable for elementsOnThisParticipant
*/
public Map<UUID, AutomationCompositionElement> setAutomationCompositionElementTest(UUID uuid,
- ToscaConceptIdentifier id) {
+ ToscaConceptIdentifier definition, ToscaConceptIdentifier participantId) {
var acElement = new AutomationCompositionElement();
acElement.setId(uuid);
- acElement.setParticipantId(id);
- acElement.setDefinition(id);
+ acElement.setParticipantId(participantId);
+ acElement.setDefinition(definition);
acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
@@ -264,24 +282,44 @@ public class CommonTestData {
}
/**
- * Returns a AutomationCompositionHandler with elements on the id,uuid.
+ * Returns a AutomationCompositionHandler with elements on the definition,uuid.
*
- * @param id ToscaConceptIdentifier and uuid UUID
+ * @param definition ToscaConceptIdentifier
+ * @param uuid UUID
* @return a AutomationCompositionHander with elements
*/
- public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier id, UUID uuid)
- throws CoderException {
+ public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition,
+ UUID uuid, ToscaConceptIdentifier participantId) {
var ach = getMockAutomationCompositionHandler();
var key = getTestAutomationCompositionMap().keySet().iterator().next();
var value = getTestAutomationCompositionMap().get(key);
ach.getAutomationCompositionMap().put(key, value);
- var keyElem = setAutomationCompositionElementTest(uuid, id).keySet().iterator().next();
- var valueElem = setAutomationCompositionElementTest(uuid, id).get(keyElem);
+ var keyElem = setAutomationCompositionElementTest(uuid, definition, participantId).keySet().iterator().next();
+ var valueElem = setAutomationCompositionElementTest(uuid, definition, participantId).get(keyElem);
ach.getElementsOnThisParticipant().put(keyElem, valueElem);
return ach;
}
+ /**
+ * Return a AutomationCompositionStateChange.
+ *
+ * @param participantId the participantId
+ * @param uuid UUID
+ * @param state a AutomationCompositionOrderedState
+ * @return a AutomationCompositionStateChange
+ */
+ public AutomationCompositionStateChange getStateChange(ToscaConceptIdentifier participantId, UUID uuid,
+ AutomationCompositionOrderedState state) {
+ var stateChange = new AutomationCompositionStateChange();
+ stateChange.setAutomationCompositionId(UUID.randomUUID());
+ stateChange.setParticipantId(participantId);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(state);
+ stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+ return stateChange;
+ }
}