d80436ef3763b9b6b22d7dc1f6ea3939f30092d5
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.participant.http.handler;
22
23 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doNothing;
26
27 import java.util.Map;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Spy;
34 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
35 import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
36 import org.onap.policy.clamp.controlloop.participant.http.utils.CommonTestData;
37 import org.onap.policy.clamp.controlloop.participant.http.utils.ToscaUtils;
38 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
39 import org.onap.policy.common.utils.coder.CoderException;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
42 import org.springframework.test.context.junit.jupiter.SpringExtension;
43
44
45 @ExtendWith(SpringExtension.class)
46 class ClElementHandlerTest {
47
48     @InjectMocks
49     @Spy
50     private ControlLoopElementHandler controlLoopElementHandler = new ControlLoopElementHandler();
51
52     @Mock
53     private ParticipantIntermediaryApi participantIntermediaryApi;
54
55     private CommonTestData commonTestData = new CommonTestData();
56
57     private static ToscaServiceTemplate serviceTemplate;
58     private static final String HTTP_CONTROL_LOOP_ELEMENT =
59             "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement";
60
61     @BeforeAll
62     static void init() throws CoderException {
63         serviceTemplate = ToscaUtils.readControlLoopFromTosca();
64     }
65
66     @Test
67     void test_ControlLoopElementUpdate() {
68         doNothing().when(controlLoopElementHandler).invokeHttpClient(any());
69         ControlLoopElement element = commonTestData.getControlLoopElement();
70
71         Map<String, ToscaNodeTemplate> nodeTemplatesMap =
72             serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
73
74         assertDoesNotThrow(() -> controlLoopElementHandler
75             .controlLoopElementUpdate(commonTestData.getControlLoopId(), element,
76                 nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT)));
77     }
78 }