aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-07-31 13:16:30 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-08-02 09:20:11 +0100
commite1589aa82ddfb58b0d4bcabe1c63cdda29939e6a (patch)
treeb0af11b028c1517720c946455134df0f621336d2 /participant/participant-impl
parent0c43d421586d24312dd6932e9a99e71fa8243b6b (diff)
Allow migration to be performed in stages in ACM participant
Issue-ID: POLICY-5092 Change-Id: I47efc0fd6abf62c3a1cc6c12f0971b4460468733 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java2
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java18
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java156
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java27
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java31
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java160
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java288
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java352
8 files changed, 781 insertions, 253 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
index ef8db0e99..534b01b32 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
@@ -99,6 +99,6 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
Map<String, Object> properties) {
LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
instanceId, element, compositionTargetId, properties);
- simulatorService.migrate(instanceId, element.getId());
+ simulatorService.migrate(instanceId, element.getId(), 0, Map.of());
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
index 7eff849a1..a7f72ecb4 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
@@ -25,7 +25,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElement
import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
-import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@@ -34,7 +33,7 @@ import org.springframework.stereotype.Component;
/**
* This class handles implementation of automationCompositionElement updates.
*/
-@ConditionalOnExpression("'${element.handler:AcElementHandlerV2}' == 'AcElementHandlerV2'")
+@ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV2'")
@Component
public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
@@ -112,21 +111,22 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
@Override
public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
- InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
- throws PfModelException {
+ InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) {
LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+ " instanceElementMigrate: {}",
compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
- if (instanceElement.newElement()) {
- simulatorService.migrate(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId());
- } else if (instanceElementMigrate.removedElement()) {
+ if (instanceElementMigrate.newElement()) {
+ LOGGER.debug("new element scenario");
+
+ }
+ if (instanceElementMigrate.removedElement()) {
simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
} else {
- simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId());
+ simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(),
+ 0, compositionElementTarget.inProperties());
}
-
}
@Override
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java
new file mode 100644
index 000000000..66f4c30b9
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.sim.main.handler;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV3;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class handles implementation of automationCompositionElement updates.
+ */
+@Getter
+@Setter
+@ConditionalOnExpression("'${element.handler:AcElementHandlerV3}' == 'AcElementHandlerV3'")
+@Component
+public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV3.class);
+
+ private final SimulatorService simulatorService;
+
+ public AutomationCompositionElementHandlerV3(ParticipantIntermediaryApi intermediaryApi,
+ SimulatorService simulatorService) {
+ super(intermediaryApi);
+ this.simulatorService = simulatorService;
+ }
+
+ /**
+ * Handle a deploy on a automation composition element.
+ *
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
+ */
+ @Override
+ public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ /**
+ * Handle a automation composition element state change.
+ *
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
+ */
+ @Override
+ public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.lock(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("unlock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.unlock(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
+ InstanceElementDto instanceElementUpdated) {
+ LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}",
+ compositionElement, instanceElement, instanceElementUpdated);
+ simulatorService.update(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void prime(CompositionDto composition) {
+ LOGGER.debug("prime call composition: {}", composition);
+ simulatorService.prime(composition.compositionId());
+ }
+
+ @Override
+ public void deprime(CompositionDto composition) {
+ LOGGER.debug("deprime call composition: {}", composition);
+ simulatorService.deprime(composition.compositionId());
+ }
+
+ @Override
+ public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
+ InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate, int stage) {
+ LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+ + " instanceElementMigrate: {}, stage: {}",
+ compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate, stage);
+
+ if (instanceElementMigrate.newElement()) {
+ LOGGER.debug("new element scenario");
+ }
+ if (instanceElementMigrate.removedElement()) {
+ simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
+ simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+ } else {
+ simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(), stage,
+ compositionElementTarget.inProperties());
+ }
+ }
+
+ @Override
+ public void migratePrecheck(CompositionElementDto compositionElement,
+ CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
+ InstanceElementDto instanceElementMigrate) {
+ LOGGER.debug("migrate precheck call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+ + " instanceElementMigrate: {}",
+ compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
+ simulatorService.migratePrecheck(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("prepare call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.prepare(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("review call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.review(instanceElement.instanceId(), instanceElement.elementId());
+ }
+}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
index e1e3ad49f..b0006f711 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
@@ -35,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.slf4j.Logger;
@@ -327,18 +328,34 @@ public class SimulatorService {
*
* @param instanceId the instanceId
* @param elementId the elementId
+ * @param stage the stage
*/
- public void migrate(UUID instanceId, UUID elementId) {
+ public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Object> compositionInProperties) {
if (!execution(getConfig().getMigrateTimerMs(),
"Current Thread migrate is Interrupted during execution {}", elementId)) {
return;
}
- if (getConfig().isMigrateSuccess()) {
- intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+ if (config.isMigrateSuccess()) {
+ var stageSet = ParticipantUtils.findStageSet(compositionInProperties);
+ var nextStage = 1000;
+ for (var s : stageSet) {
+ if (s > stage) {
+ nextStage = Math.min(s, nextStage);
+ }
+ }
+ if (nextStage == 1000) {
+ intermediaryApi.updateAutomationCompositionElementState(
+ instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementStage(
+ instanceId, elementId,
+ StateChangeResult.NO_ERROR, nextStage, "stage " + stage + " Migrated");
+ }
} else {
- intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ intermediaryApi.updateAutomationCompositionElementState(
+ instanceId, elementId,
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java
index 5499931a2..f73f75970 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/comm/CommonTestData.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
+import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
import org.onap.policy.clamp.acm.participant.sim.parameters.ParticipantSimParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
@@ -102,7 +103,7 @@ public class CommonTestData {
* @return topic parameters
*/
private static TopicParameters getSinkTopicParams() {
- final TopicParameters topicParams = new TopicParameters();
+ final var topicParams = new TopicParameters();
topicParams.setTopic("policy-acruntime-participant");
topicParams.setTopicCommInfrastructure("NOOP");
topicParams.setServers(List.of("localhost"));
@@ -115,7 +116,7 @@ public class CommonTestData {
* @return topic parameters
*/
private static TopicParameters getSyncTopicParams() {
- final TopicParameters topicParams = new TopicParameters();
+ final var topicParams = new TopicParameters();
topicParams.setTopic("acm-ppnt-sync");
topicParams.setTopicCommInfrastructure("NOOP");
topicParams.setServers(List.of("localhost"));
@@ -135,8 +136,6 @@ public class CommonTestData {
* Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
*
* @return automationCompositionMap
- *
- * @throws CoderException if there is an error with .json file.
*/
public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
var automationComposition = getTestAutomationComposition();
@@ -147,8 +146,6 @@ public class CommonTestData {
* Returns List of AutomationComposition for test cases.
*
* @return AutomationCompositions
- *
- * @throws CoderException if there is an error with .json file.
*/
public static AutomationComposition getTestAutomationComposition() {
var automationComposition = new AutomationComposition();
@@ -158,4 +155,26 @@ public class CommonTestData {
automationComposition.setElements(Map.of(element.getId(), element));
return automationComposition;
}
+
+ /**
+ * Create a new SimConfig.
+ *
+ * @return a new SimConfig
+ */
+ public static SimConfig createSimConfig() {
+ var config = new SimConfig();
+ config.setPrepareTimerMs(1);
+ config.setDeployTimerMs(1);
+ config.setReviewTimerMs(1);
+ config.setUndeployTimerMs(1);
+ config.setLockTimerMs(1);
+ config.setUnlockTimerMs(1);
+ config.setUpdateTimerMs(1);
+ config.setDeleteTimerMs(1);
+ config.setPrimeTimerMs(1);
+ config.setDeprimeTimerMs(1);
+ config.setMigrateTimerMs(1);
+ config.setMigratePrecheckTimerMs(1);
+ return config;
+ }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
index 300caa52c..d78b851d4 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
@@ -28,194 +28,178 @@ import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.models.base.PfModelException;
class AutomationCompositionElementHandlerV1Test {
+ private static final UUID COMPOSITION_ID = UUID.randomUUID();
+ private static final UUID INSTANCE_ID = UUID.randomUUID();
+ private static final UUID ELEMENT_ID = UUID.randomUUID();
+
+ private AcElementDeploy createAcElementDeploy() {
+ var element = new AcElementDeploy();
+ element.setId(ELEMENT_ID);
+ return element;
+ }
+
@Test
- void testDeploy() throws PfModelException {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
+ void testDeploy() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- acElementHandler.deploy(instanceId, element, Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ var element = createAcElementDeploy();
+ acElementHandler.deploy(INSTANCE_ID, element, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
config.setDeploySuccess(false);
- acElementHandler.deploy(instanceId, element, Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.deploy(INSTANCE_ID, element, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!");
}
@Test
- void testUndeploy() throws PfModelException {
- var config = new SimConfig();
- config.setUndeployTimerMs(1);
+ void testUndeploy() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- acElementHandler.undeploy(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED,
null, StateChangeResult.NO_ERROR, "Undeployed");
config.setUndeploySuccess(false);
- acElementHandler.undeploy(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DEPLOYED,
null, StateChangeResult.FAILED, "Undeploy failed!");
}
@Test
- void testLock() throws PfModelException {
- var config = new SimConfig();
- config.setLockTimerMs(1);
+ void testLock() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- acElementHandler.lock(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
- StateChangeResult.NO_ERROR, "Locked");
+ acElementHandler.lock(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+ null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
config.setLockSuccess(false);
- acElementHandler.lock(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
- StateChangeResult.FAILED, "Lock failed!");
+ acElementHandler.lock(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+ null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!");
}
@Test
- void testUnlock() throws PfModelException {
- var config = new SimConfig();
- config.setUnlockTimerMs(1);
+ void testUnlock() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- acElementHandler.unlock(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
- StateChangeResult.NO_ERROR, "Unlocked");
+ acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+ null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
config.setUnlockSuccess(false);
- acElementHandler.unlock(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
- StateChangeResult.FAILED, "Unlock failed!");
+ acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID,
+ null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!");
}
@Test
- void testUpdate() throws PfModelException {
- var config = new SimConfig();
- config.setUpdateTimerMs(1);
+ void testUpdate() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- acElementHandler.update(instanceId, element, Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ var element = createAcElementDeploy();
+ acElementHandler.update(INSTANCE_ID, element, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
config.setUpdateSuccess(false);
- acElementHandler.update(instanceId, element, Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.update(INSTANCE_ID, element, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
}
@Test
- void testDelete() throws PfModelException {
- var config = new SimConfig();
- config.setDeleteTimerMs(1);
+ void testDelete() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- acElementHandler.delete(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED,
+ acElementHandler.delete(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DELETED,
null, StateChangeResult.NO_ERROR, "Deleted");
config.setDeleteSuccess(false);
- acElementHandler.delete(instanceId, elementId);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.delete(INSTANCE_ID, ELEMENT_ID);
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED,
null, StateChangeResult.FAILED, "Delete failed!");
}
@Test
- void testPrime() throws PfModelException {
- var config = new SimConfig();
- config.setPrimeTimerMs(1);
+ void testPrime() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- acElementHandler.prime(compositionId, List.of());
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
+ acElementHandler.prime(COMPOSITION_ID, List.of());
+ verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
"Primed");
config.setPrimeSuccess(false);
- acElementHandler.prime(compositionId, List.of());
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ acElementHandler.prime(COMPOSITION_ID, List.of());
+ verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED,
StateChangeResult.FAILED, "Prime failed!");
}
@Test
- void testDeprime() throws PfModelException {
- var config = new SimConfig();
- config.setDeprimeTimerMs(1);
+ void testDeprime() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- acElementHandler.deprime(compositionId);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ acElementHandler.deprime(COMPOSITION_ID);
+ verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED,
StateChangeResult.NO_ERROR, "Deprimed");
config.setDeprimeSuccess(false);
- acElementHandler.deprime(compositionId);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED,
+ acElementHandler.deprime(COMPOSITION_ID);
+ verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.FAILED,
"Deprime failed!");
}
@Test
- void testMigrate() throws PfModelException {
- var config = new SimConfig();
- config.setUpdateTimerMs(1);
+ void testMigrate() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ var element = createAcElementDeploy();
+ acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
config.setMigrateSuccess(false);
- acElementHandler.migrate(instanceId, element, UUID.randomUUID(), Map.of());
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
index 1e2ec2c33..e8e9b766c 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
@@ -30,303 +30,303 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionElementHandlerV2Test {
+ private static final CompositionElementDto COMPOSITION_ELEMENT =
+ new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
+ private static final InstanceElementDto INSTANCE_ELEMENT =
+ new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+ private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
+
@Test
void testDeploy() {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.deploy(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
null, StateChangeResult.NO_ERROR, "Deployed");
config.setDeploySuccess(false);
- acElementHandler.deploy(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
null, StateChangeResult.FAILED, "Deploy failed!");
}
@Test
void testUndeploy() {
- var config = new SimConfig();
- config.setUndeployTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.undeploy(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
null, StateChangeResult.NO_ERROR, "Undeployed");
config.setUndeploySuccess(false);
- acElementHandler.undeploy(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
null, StateChangeResult.FAILED, "Undeploy failed!");
}
@Test
void testLock() {
- var config = new SimConfig();
- config.setLockTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.lock(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
StateChangeResult.NO_ERROR, "Locked");
config.setLockSuccess(false);
- acElementHandler.lock(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
StateChangeResult.FAILED, "Lock failed!");
}
@Test
void testUnlock() {
- var config = new SimConfig();
- config.setUnlockTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.unlock(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
StateChangeResult.NO_ERROR, "Unlocked");
config.setUnlockSuccess(false);
- acElementHandler.unlock(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
StateChangeResult.FAILED, "Unlock failed!");
}
@Test
void testUpdate() {
- var config = new SimConfig();
- config.setUpdateTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
- var instanceElementUpdated = new InstanceElementDto(instanceId, element.getId(), null,
+ var instanceElementUpdated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
Map.of("key", "value"), Map.of());
- acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
config.setUpdateSuccess(false);
- acElementHandler.update(compositionElement, instanceElement, instanceElementUpdated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
}
@Test
void testDelete() {
- var config = new SimConfig();
- config.setDeleteTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.delete(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED,
+ acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED,
null, StateChangeResult.NO_ERROR, "Deleted");
config.setDeleteSuccess(false);
- acElementHandler.delete(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
null, StateChangeResult.FAILED, "Delete failed!");
}
@Test
void testPrime() {
- var config = new SimConfig();
- config.setPrimeTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- var composition = new CompositionDto(compositionId, Map.of(), Map.of());
- acElementHandler.prime(composition);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Primed");
+ acElementHandler.prime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
config.setPrimeSuccess(false);
- acElementHandler.prime(composition);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.FAILED, "Prime failed!");
+ acElementHandler.prime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!");
}
@Test
void testDeprime() {
- var config = new SimConfig();
- config.setDeprimeTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- var composition = new CompositionDto(compositionId, Map.of(), Map.of());
- acElementHandler.deprime(composition);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.NO_ERROR, "Deprimed");
+ acElementHandler.deprime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
config.setDeprimeSuccess(false);
- acElementHandler.deprime(composition);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED,
- "Deprime failed!");
+ acElementHandler.deprime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!");
}
@Test
- void testMigrate() throws PfModelException {
- var config = new SimConfig();
- config.setUpdateTimerMs(1);
+ void testMigrate() {
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
- var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(),
+ var instanceElementMigrated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
null, Map.of("key", "value"), Map.of());
acElementHandler
- .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
config.setMigrateSuccess(false);
acElementHandler
- .migrate(compositionElement, compositionElementTraget, instanceElement, instanceElementMigrated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
}
@Test
+ void testMigrateAdd() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compoElTargetAdd = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of(), true, false);
+ var inElMigratedAdd = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of(), true, false);
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compoElTargetAdd, INSTANCE_ELEMENT, inElMigratedAdd);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+ }
+
+ @Test
+ void testMigrateRemove() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+
+ var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of(), false, true);
+ var inElMigratedRemove = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of(), false, true);
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Test
void testMigratePrecheck() {
- var config = new SimConfig();
- config.setUpdateTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
Map.of(), Map.of());
- var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
- var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(),
+ var instanceElementMigrated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
null, Map.of("key", "value"), Map.of());
- acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
- instanceElement, instanceElementMigrated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+ INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null,
StateChangeResult.NO_ERROR, "Migration precheck completed");
config.setMigratePrecheck(false);
- acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
- instanceElement, instanceElementMigrated);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+ INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
DeployState.DEPLOYED, null,
StateChangeResult.FAILED, "Migration precheck failed");
}
@Test
void testPrepare() {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.prepare(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
null, StateChangeResult.NO_ERROR, "Prepare completed");
config.setPrepare(false);
- acElementHandler.prepare(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
null, StateChangeResult.FAILED, "Prepare failed");
}
@Test
void testReview() {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
+ var config = CommonTestData.createSimConfig();
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var simulatorService = new SimulatorService(intermediaryApi);
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- acElementHandler.review(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
null, StateChangeResult.NO_ERROR, "Review completed");
config.setReview(false);
- acElementHandler.review(compositionElement, instanceElement);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
null, StateChangeResult.FAILED, "Review failed");
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
new file mode 100644
index 000000000..3a7af2456
--- /dev/null
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
@@ -0,0 +1,352 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.sim.main.handler;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class AutomationCompositionElementHandlerV3Test {
+
+ private static final CompositionElementDto COMPOSITION_ELEMENT =
+ new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
+ private static final InstanceElementDto INSTANCE_ELEMENT =
+ new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+ private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
+
+ @Test
+ void testDeploy() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Deployed");
+
+ config.setDeploySuccess(false);
+ acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+ null, StateChangeResult.FAILED, "Deploy failed!");
+ }
+
+ @Test
+ void testUndeploy() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Undeployed");
+
+ config.setUndeploySuccess(false);
+ acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+ null, StateChangeResult.FAILED, "Undeploy failed!");
+ }
+
+ @Test
+ void testLock() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+
+ config.setLockSuccess(false);
+ acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
+ StateChangeResult.FAILED, "Lock failed!");
+ }
+
+ @Test
+ void testUnlock() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+
+ config.setUnlockSuccess(false);
+ acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
+ StateChangeResult.FAILED, "Unlock failed!");
+ }
+
+ @Test
+ void testUpdate() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var instanceElementUpdated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
+ Map.of("key", "value"), Map.of());
+ acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
+
+ config.setUpdateSuccess(false);
+ acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
+ }
+
+ @Test
+ void testDelete() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED,
+ null, StateChangeResult.NO_ERROR, "Deleted");
+
+ config.setDeleteSuccess(false);
+ acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+ null, StateChangeResult.FAILED, "Delete failed!");
+ }
+
+ @Test
+ void testPrime() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.prime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+
+ config.setPrimeSuccess(false);
+ acElementHandler.prime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!");
+ }
+
+ @Test
+ void testDeprime() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.deprime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
+
+ config.setDeprimeSuccess(false);
+ acElementHandler.deprime(COMPOSITION);
+ verify(intermediaryApi).updateCompositionState(
+ COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!");
+ }
+
+ @Test
+ void testMigrate() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var instanceElementMigrated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of());
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+
+ config.setMigrateSuccess(false);
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
+ }
+
+ @Test
+ void testMigrateStage() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of("stage", List.of(1, 2)), Map.of());
+ var instanceElementMigrated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of(), Map.of());
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 1);
+ verify(intermediaryApi).updateAutomationCompositionElementStage(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ StateChangeResult.NO_ERROR, 2, "stage 1 Migrated");
+ }
+
+ @Test
+ void testMigrateAdd() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compoElTargetAdd = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of(), true, false);
+ var inElMigratedAdd = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of(), true, false);
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compoElTargetAdd, INSTANCE_ELEMENT, inElMigratedAdd, 0);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+ }
+
+ @Test
+ void testMigrateRemove() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+
+ var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of(), false, true);
+ var inElMigratedRemove = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of(), false, true);
+ acElementHandler
+ .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Test
+ void testMigratePrecheck() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var instanceElementMigrated = new InstanceElementDto(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ null, Map.of("key", "value"), Map.of());
+ acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+ INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Migration precheck completed");
+
+ config.setMigratePrecheck(false);
+ acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
+ INSTANCE_ELEMENT, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
+ DeployState.DEPLOYED, null,
+ StateChangeResult.FAILED, "Migration precheck failed");
+ }
+
+ @Test
+ void testPrepare() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Prepare completed");
+
+ config.setPrepare(false);
+ acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
+ null, StateChangeResult.FAILED, "Prepare failed");
+ }
+
+ @Test
+ void testReview() {
+ var config = CommonTestData.createSimConfig();
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Review completed");
+
+ config.setReview(false);
+ acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
+ verify(intermediaryApi).updateAutomationCompositionElementState(
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
+ null, StateChangeResult.FAILED, "Review failed");
+ }
+}