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.simulator.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.models.base.PfModelException;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 class ControlLoopElementHandlerTest {
40 private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
41 private static final String ID_VERSION = "1.0.1";
42 private static final UUID controlLoopElementId = UUID.randomUUID();
43 private static final ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
46 void testSimulatorHandlerExceptions() throws PfModelException {
47 ControlLoopElementHandler handler = getTestingHandler();
49 assertDoesNotThrow(() -> handler
50 .controlLoopElementStateChange(controlLoopId,
52 ControlLoopState.UNINITIALISED,
53 ControlLoopOrderedState.PASSIVE));
55 assertDoesNotThrow(() -> handler
56 .controlLoopElementStateChange(controlLoopId,
58 ControlLoopState.RUNNING,
59 ControlLoopOrderedState.UNINITIALISED));
61 assertDoesNotThrow(() -> handler
62 .controlLoopElementStateChange(controlLoopId,
64 ControlLoopState.PASSIVE,
65 ControlLoopOrderedState.RUNNING));
66 var element = getTestingClElement();
67 var clElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
69 assertDoesNotThrow(() -> handler
70 .controlLoopElementUpdate(controlLoopId, element, clElementDefinition));
72 assertDoesNotThrow(() -> handler
73 .handleStatistics(controlLoopElementId));
76 ControlLoopElementHandler getTestingHandler() {
77 var handler = new ControlLoopElementHandler();
78 var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
79 var element = getTestingClElement();
80 when(intermediaryApi.getControlLoopElement(controlLoopElementId)).thenReturn(element);
81 handler.setIntermediaryApi(intermediaryApi);
85 ControlLoopElement getTestingClElement() {
86 var element = new ControlLoopElement();
87 element.setDefinition(controlLoopId);
88 element.setDescription("Description");
89 element.setId(controlLoopElementId);
90 element.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
91 element.setParticipantId(controlLoopId);
92 element.setState(ControlLoopState.UNINITIALISED);
93 var template = Mockito.mock(ToscaServiceTemplate.class);
94 element.setToscaServiceTemplateFragment(template);