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
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.controlloop.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;
29 import org.junit.jupiter.api.BeforeAll;
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.Spy;
36 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
37 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
38 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
39 import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
40 import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest;
41 import org.onap.policy.clamp.controlloop.participant.http.utils.CommonTestData;
42 import org.onap.policy.clamp.controlloop.participant.http.utils.ToscaUtils;
43 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
44 import org.onap.policy.common.utils.coder.CoderException;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
47 import org.springframework.test.context.junit.jupiter.SpringExtension;
50 @ExtendWith(SpringExtension.class)
51 class ClElementHandlerTest {
55 private ControlLoopElementHandler controlLoopElementHandler = new ControlLoopElementHandler();
58 private ParticipantIntermediaryApi participantIntermediaryApi;
60 private CommonTestData commonTestData = new CommonTestData();
62 private static ToscaServiceTemplate serviceTemplate;
63 private static final String HTTP_CONTROL_LOOP_ELEMENT =
64 "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement";
67 static void init() throws CoderException {
68 serviceTemplate = ToscaUtils.readControlLoopFromTosca();
72 void test_controlLoopElementeStateChange() throws IOException {
73 var controlLoopId = commonTestData.getControlLoopId();
74 var element = commonTestData.getControlLoopElement();
75 var controlLoopElementId = element.getId();
77 var config = Mockito.mock(ConfigRequest.class);
78 assertDoesNotThrow(() -> controlLoopElementHandler.invokeHttpClient(config));
80 assertDoesNotThrow(() -> controlLoopElementHandler
81 .controlLoopElementStateChange(controlLoopId,
82 controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.PASSIVE));
84 assertDoesNotThrow(() -> controlLoopElementHandler
85 .controlLoopElementStateChange(controlLoopId,
86 controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED));
88 assertDoesNotThrow(() -> controlLoopElementHandler
89 .controlLoopElementStateChange(controlLoopId,
90 controlLoopElementId, ControlLoopState.PASSIVE, ControlLoopOrderedState.RUNNING));
92 controlLoopElementHandler.close();
96 void test_ControlLoopElementUpdate() {
97 doNothing().when(controlLoopElementHandler).invokeHttpClient(any());
98 ControlLoopElement element = commonTestData.getControlLoopElement();
100 Map<String, ToscaNodeTemplate> nodeTemplatesMap =
101 serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
103 assertDoesNotThrow(() -> controlLoopElementHandler
104 .controlLoopElementUpdate(commonTestData.getControlLoopId(), element,
105 nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT)));