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.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doNothing;
27 import java.io.IOException;
28 import java.util.HashMap;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mockito;
35 import org.mockito.Spy;
36 import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler;
37 import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
38 import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
39 import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils;
40 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
42 import org.springframework.test.context.junit.jupiter.SpringExtension;
44 @ExtendWith(SpringExtension.class)
45 class AcElementHandlerTest {
49 private AutomationCompositionElementHandler automationCompositionElementHandler =
50 new AutomationCompositionElementHandler();
52 private final CommonTestData commonTestData = new CommonTestData();
54 private static ToscaServiceTemplate serviceTemplate;
55 private static final String HTTP_AUTOMATION_COMPOSITION_ELEMENT =
56 "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
60 serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
65 automationCompositionElementHandler.setIntermediaryApi(Mockito.mock(ParticipantIntermediaryApi.class));
69 void test_automationCompositionElementStateChange() throws IOException {
70 var automationCompositionId = commonTestData.getAutomationCompositionId();
71 var element = commonTestData.getAutomationCompositionElement();
72 var automationCompositionElementId = element.getId();
74 var config = Mockito.mock(ConfigRequest.class);
75 assertDoesNotThrow(() -> automationCompositionElementHandler.invokeHttpClient(config));
77 assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
78 automationCompositionId, automationCompositionElementId));
80 automationCompositionElementHandler.close();
84 void test_AutomationCompositionElementUpdate() throws Exception {
85 doNothing().when(automationCompositionElementHandler).invokeHttpClient(any());
86 var element = commonTestData.getAutomationCompositionElement();
88 var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
89 var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
90 map.putAll(element.getProperties());
92 assertDoesNotThrow(() -> automationCompositionElementHandler
93 .deploy(commonTestData.getAutomationCompositionId(), element, map));