2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.participant.http.handler;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyMap;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.verify;
29 import java.io.IOException;
30 import java.util.HashMap;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler;
34 import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
35 import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
36 import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
37 import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils;
38 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
39 import org.onap.policy.clamp.models.acm.concepts.DeployState;
40 import org.onap.policy.clamp.models.acm.concepts.LockState;
42 class AcElementHandlerTest {
44 private final CommonTestData commonTestData = new CommonTestData();
45 private static final String HTTP_AUTOMATION_COMPOSITION_ELEMENT =
46 "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
49 void testUndeploy() throws IOException {
50 var instanceId = commonTestData.getAutomationCompositionId();
51 var element = commonTestData.getAutomationCompositionElement();
52 var acElementId = element.getId();
54 try (var automationCompositionElementHandler =
55 new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
56 var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
57 automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
58 automationCompositionElementHandler.undeploy(instanceId, acElementId);
59 verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
60 DeployState.UNDEPLOYED, LockState.NONE);
65 void testDeployError() throws IOException {
66 var instanceId = commonTestData.getAutomationCompositionId();
67 var element = commonTestData.getAutomationCompositionElement();
69 try (var automationCompositionElementHandler =
70 new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
71 automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
72 Map<String, Object> map = new HashMap<>();
73 assertThatThrownBy(() -> automationCompositionElementHandler.deploy(instanceId, element, map))
74 .hasMessage("Constraint violations in the config request");
79 void testDeploy() throws Exception {
80 var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
81 var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
82 var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
83 var element = commonTestData.getAutomationCompositionElement();
84 map.putAll(element.getProperties());
85 var instanceId = commonTestData.getAutomationCompositionId();
86 var acHttpClient = mock(AcHttpClient.class);
87 try (var automationCompositionElementHandler = new AutomationCompositionElementHandler(acHttpClient)) {
88 var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
89 automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
90 automationCompositionElementHandler.deploy(instanceId, element, map);
91 verify(acHttpClient).run(any(ConfigRequest.class), anyMap());
92 verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
93 DeployState.DEPLOYED, LockState.LOCKED);