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.policy.main.handler;
23 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.mockito.Mockito.when;
26 import java.util.UUID;
27 import org.junit.jupiter.api.Test;
28 import org.mockito.Mockito;
29 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
30 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
31 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
32 import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
33 import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyApiHttpClient;
34 import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyPapHttpClient;
35 import org.onap.policy.models.base.PfModelException;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
40 class ControlLoopElementHandlerTest {
42 private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
43 private static final String ID_VERSION = "1.0.1";
44 private static final UUID controlLoopElementId = UUID.randomUUID();
45 private static final ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
48 void testHandlerExceptions() throws PfModelException {
49 ControlLoopElementHandler handler = getTestingHandler();
51 assertDoesNotThrow(() -> handler
52 .controlLoopElementStateChange(controlLoopId,
54 ControlLoopState.UNINITIALISED,
55 ControlLoopOrderedState.PASSIVE));
57 assertDoesNotThrow(() -> handler
58 .controlLoopElementStateChange(controlLoopId,
60 ControlLoopState.RUNNING,
61 ControlLoopOrderedState.UNINITIALISED));
63 assertDoesNotThrow(() -> handler
64 .controlLoopElementStateChange(controlLoopId,
66 ControlLoopState.PASSIVE,
67 ControlLoopOrderedState.RUNNING));
68 var element = getTestingClElement();
69 var clElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
71 assertDoesNotThrow(() -> handler
72 .controlLoopElementUpdate(controlLoopId, element, clElementDefinition));
74 assertDoesNotThrow(() -> handler
75 .handleStatistics(controlLoopElementId));
78 ControlLoopElementHandler getTestingHandler() {
79 var api = Mockito.mock(PolicyApiHttpClient.class);
80 var pap = Mockito.mock(PolicyPapHttpClient.class);
81 var handler = new ControlLoopElementHandler(api, pap);
82 var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
83 var element = getTestingClElement();
84 when(intermediaryApi.getControlLoopElement(controlLoopElementId)).thenReturn(element);
85 handler.setIntermediaryApi(intermediaryApi);
89 ControlLoopElement getTestingClElement() {
90 var element = new ControlLoopElement();
91 element.setDefinition(controlLoopId);
92 element.setDescription("Description");
93 element.setId(controlLoopElementId);
94 element.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
95 element.setParticipantId(controlLoopId);
96 element.setState(ControlLoopState.UNINITIALISED);
97 var template = Mockito.mock(ToscaServiceTemplate.class);
98 element.setToscaServiceTemplateFragment(template);