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;
41 class AcElementHandlerTest {
43 private final CommonTestData commonTestData = new CommonTestData();
44 private static final String HTTP_AUTOMATION_COMPOSITION_ELEMENT =
45 "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
48 void testUndeploy() throws IOException {
49 var instanceId = commonTestData.getAutomationCompositionId();
50 var element = commonTestData.getAutomationCompositionElement();
51 var acElementId = element.getId();
53 try (var automationCompositionElementHandler =
54 new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
55 var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
56 automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
57 automationCompositionElementHandler.undeploy(instanceId, acElementId);
58 verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
59 DeployState.UNDEPLOYED, null, "");
64 void testDeployError() throws IOException {
65 var instanceId = commonTestData.getAutomationCompositionId();
66 var element = commonTestData.getAutomationCompositionElement();
68 try (var automationCompositionElementHandler =
69 new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
70 automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
71 Map<String, Object> map = new HashMap<>();
72 assertThatThrownBy(() -> automationCompositionElementHandler.deploy(instanceId, element, map))
73 .hasMessage("Constraint violations in the config request");
78 void testDeploy() throws Exception {
79 var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
80 var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
81 var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
82 var element = commonTestData.getAutomationCompositionElement();
83 map.putAll(element.getProperties());
84 var instanceId = commonTestData.getAutomationCompositionId();
85 var acHttpClient = mock(AcHttpClient.class);
86 try (var automationCompositionElementHandler = new AutomationCompositionElementHandler(acHttpClient)) {
87 var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
88 automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
89 automationCompositionElementHandler.deploy(instanceId, element, map);
90 verify(acHttpClient).run(any(ConfigRequest.class), anyMap());
91 verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
92 DeployState.DEPLOYED, null, "Deployed");