aboutsummaryrefslogtreecommitdiffstats
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
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>
-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
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java34
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java31
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java15
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java9
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java6
15 files changed, 175 insertions, 251 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;
+ }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
index abc3ccb1a..b913cfac9 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
@@ -26,17 +26,11 @@ import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionAspectTest {
- private static final ToscaConceptIdentifier PARTICIPANT_ID =
- new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
-
- private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", "1.0.0");
-
@Test
void testSchedule() throws Exception {
var supervisionScanner = mock(SupervisionScanner.class);
@@ -59,12 +53,12 @@ class SupervisionAspectTest {
@Test
void testHandleParticipantStatus() throws Exception {
var participantStatusMessage = new ParticipantStatus();
- participantStatusMessage.setParticipantId(PARTICIPANT_ID);
+ participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
var supervisionScanner = mock(SupervisionScanner.class);
try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
supervisionAspect.handleParticipantStatus(participantStatusMessage);
- verify(supervisionScanner, timeout(500)).handleParticipantStatus(PARTICIPANT_ID);
+ verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
}
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index fd6c9a008..4516ccd97 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -39,12 +39,12 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
@@ -56,9 +56,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionHandlerTest {
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
- private static final UUID identifier = UUID.randomUUID();
- private static final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
- private static final ToscaConceptIdentifier participantType =
+ private static final UUID IDENTIFIER = UUID.randomUUID();
+ private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
new ToscaConceptIdentifier("ParticipantType", "1.0.0");
@Test
@@ -221,7 +220,7 @@ class SupervisionHandlerTest {
var automationCompositionAckMessage =
new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of());
- automationCompositionAckMessage.setAutomationCompositionId(identifier);
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
@@ -232,10 +231,10 @@ class SupervisionHandlerTest {
void testHandleAutomationCompositionUpdateAckMessage() {
var automationCompositionAckMessage =
new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE_ACK);
- automationCompositionAckMessage.setParticipantId(participantId);
- automationCompositionAckMessage.setParticipantType(participantType);
+ automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ automationCompositionAckMessage.setParticipantType(PARTICIPANT_TYPE);
automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of());
- automationCompositionAckMessage.setAutomationCompositionId(identifier);
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = createSupervisionHandler(automationCompositionProvider,
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
@@ -248,15 +247,10 @@ class SupervisionHandlerTest {
}
@Test
- void testParticipantUpdateAck() throws PfModelException {
- var participant = new Participant();
- participant.setName(participantId.getName());
- participant.setVersion(participantId.getVersion());
- participant.setParticipantType(participantType);
-
+ void testParticipantUpdateAck() {
var participantUpdateAckMessage = new ParticipantUpdateAck();
- participantUpdateAckMessage.setParticipantId(participantId);
- participantUpdateAckMessage.setParticipantType(participantType);
+ participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantUpdateAckMessage.setParticipantType(PARTICIPANT_TYPE);
participantUpdateAckMessage.setState(ParticipantState.ON_LINE);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
@@ -267,7 +261,7 @@ class SupervisionHandlerTest {
}
@Test
- void testHandleSendCommissionMessage() throws PfModelException {
+ void testHandleSendCommissionMessage() {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
@@ -286,9 +280,9 @@ class SupervisionHandlerTest {
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE,
AutomationCompositionState.UNINITIALISED);
- handler.handleSendDeCommissionMessage(identifier);
+ handler.handleSendDeCommissionMessage(IDENTIFIER);
- verify(participantUpdatePublisher).sendDecomisioning(identifier);
+ verify(participantUpdatePublisher).sendDecomisioning(IDENTIFIER);
}
private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider,
@@ -301,7 +295,7 @@ class SupervisionHandlerTest {
automationComposition.setOrderedState(orderedState);
automationComposition.setState(state);
- when(automationCompositionProvider.findAutomationComposition(identifier))
+ when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
index 05e356b55..9463d7977 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
@@ -31,7 +31,7 @@ import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
-import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
@@ -40,23 +40,20 @@ import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionParticipantHandlerTest {
- private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
new ToscaConceptIdentifier("ParticipantType", "1.0.0");
@Test
void testHandleParticipantDeregister() {
- var participant = new Participant();
- participant.setName(PARTICIPANT_ID.getName());
- participant.setVersion(PARTICIPANT_ID.getVersion());
- participant.setParticipantType(PARTICIPANT_TYPE);
+ var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId());
var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
+ when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
+ .thenReturn(Optional.of(participant));
var participantDeregisterMessage = new ParticipantDeregister();
participantDeregisterMessage.setMessageId(UUID.randomUUID());
- participantDeregisterMessage.setParticipantId(PARTICIPANT_ID);
+ participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE);
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider,
@@ -70,14 +67,9 @@ class SupervisionParticipantHandlerTest {
@Test
void testHandleParticipantRegister() {
- var participant = new Participant();
- participant.setName(PARTICIPANT_ID.getName());
- participant.setVersion(PARTICIPANT_ID.getVersion());
- participant.setParticipantType(PARTICIPANT_TYPE);
-
var participantRegisterMessage = new ParticipantRegister();
participantRegisterMessage.setMessageId(UUID.randomUUID());
- participantRegisterMessage.setParticipantId(PARTICIPANT_ID);
+ participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId());
participantRegisterMessage.setParticipantType(PARTICIPANT_TYPE);
var participantProvider = mock(ParticipantProvider.class);
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
@@ -88,14 +80,14 @@ class SupervisionParticipantHandlerTest {
handler.handleParticipantMessage(participantRegisterMessage);
verify(participantProvider).saveParticipant(any());
- verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID,
- PARTICIPANT_TYPE);
+ verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(),
+ CommonTestData.getParticipantId(), PARTICIPANT_TYPE);
}
@Test
void testHandleParticipantStatus() {
var participantStatusMessage = new ParticipantStatus();
- participantStatusMessage.setParticipantId(PARTICIPANT_ID);
+ participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
participantStatusMessage.setParticipantType(PARTICIPANT_TYPE);
participantStatusMessage.setState(ParticipantState.ON_LINE);
participantStatusMessage.setParticipantSupportedElementType(new ArrayList<>());
@@ -103,8 +95,9 @@ class SupervisionParticipantHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var handler = new SupervisionParticipantHandler(participantProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
- var participant = new Participant();
- when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
+ var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId());
+ when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
+ .thenReturn(Optional.of(participant));
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).updateParticipant(any());
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 92597b3c3..93f15f64d 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -41,7 +41,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
@@ -55,13 +54,10 @@ class SupervisionScannerTest {
private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class);
- private static final String PARTICIPANT_NAME = "Participant0";
- private static final String PARTICIPANT_VERSION = "1.0.0";
-
private static UUID compositionId;
private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", PARTICIPANT_VERSION);
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", "1.0.0");
@BeforeAll
public static void setUpBeforeAll() {
@@ -123,9 +119,7 @@ class SupervisionScannerTest {
.thenReturn(List.of(automationComposition));
var participantProvider = mock(ParticipantProvider.class);
- var participant = new Participant();
- participant.setName(PARTICIPANT_NAME);
- participant.setVersion(PARTICIPANT_VERSION);
+ var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId());
when(participantProvider.getParticipants()).thenReturn(List.of(participant));
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
@@ -186,12 +180,9 @@ class SupervisionScannerTest {
acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
- var participant = new Participant();
- participant.setName(PARTICIPANT_NAME);
- participant.setVersion(PARTICIPANT_VERSION);
+ var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId());
participant.setParticipantState(ParticipantState.OFF_LINE);
participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0"));
- participant.setParticipantType(PARTICIPANT_TYPE);
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.getParticipants()).thenReturn(List.of(participant));
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index b7d2d9303..d9c4ed67f 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
@@ -160,7 +161,7 @@ class SupervisionMessagesTest {
var publisher = new ParticipantStatusReqPublisher();
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
- publisher.send(getParticipantId());
+ publisher.send(CommonTestData.getParticipantId());
verify(topicSink).send(anyString());
}
@@ -169,14 +170,10 @@ class SupervisionMessagesTest {
var publisher = new ParticipantRegisterAckPublisher();
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
- publisher.send(UUID.randomUUID(), getParticipantId(), getParticipantType());
+ publisher.send(UUID.randomUUID(), CommonTestData.getParticipantId(), getParticipantType());
verify(topicSink).send(anyString());
}
- 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/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
index ad8243bed..195afdc5d 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
@@ -94,7 +94,7 @@ public class CommonTestData {
* @return a new Participant
*/
public static Participant createParticipant(ToscaConceptIdentifier participantType,
- ToscaConceptIdentifier participantId) {
+ ToscaConceptIdentifier participantId) {
var participant = new Participant();
participant.setDefinition(participantId);
participant.setParticipantType(participantType);
@@ -102,4 +102,8 @@ public class CommonTestData {
participant.setVersion(participantId.getVersion());
return participant;
}
+
+ public static ToscaConceptIdentifier getParticipantId() {
+ return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
+ }
}