2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 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.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.acm.participant.intermediary.api.ParticipantIntermediaryApi;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
37 class AutomationCompositionElementHandlerTest {
39 private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
40 private static final String ID_VERSION = "1.0.1";
41 private static final UUID automationCompositionElementId = UUID.randomUUID();
42 private static final ToscaConceptIdentifier automationCompositionId =
43 new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
46 void testSimulatorHandlerExceptions() {
47 AutomationCompositionElementHandler handler = getTestingHandler();
49 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
50 automationCompositionElementId, AutomationCompositionState.UNINITIALISED,
51 AutomationCompositionOrderedState.PASSIVE));
53 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
54 automationCompositionElementId, AutomationCompositionState.RUNNING,
55 AutomationCompositionOrderedState.UNINITIALISED));
57 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
58 automationCompositionElementId, AutomationCompositionState.PASSIVE,
59 AutomationCompositionOrderedState.RUNNING));
60 var element = getTestingAcElement();
61 var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
64 () -> handler.automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
66 assertDoesNotThrow(() -> handler.handleStatistics(automationCompositionElementId));
69 AutomationCompositionElementHandler getTestingHandler() {
70 var handler = new AutomationCompositionElementHandler();
71 var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
72 var element = getTestingAcElement();
73 when(intermediaryApi.getAutomationCompositionElement(automationCompositionElementId)).thenReturn(element);
74 handler.setIntermediaryApi(intermediaryApi);
78 AutomationCompositionElement getTestingAcElement() {
79 var element = new AutomationCompositionElement();
80 element.setDefinition(automationCompositionId);
81 element.setDescription("Description");
82 element.setId(automationCompositionElementId);
83 element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
84 element.setParticipantId(automationCompositionId);
85 element.setState(AutomationCompositionState.UNINITIALISED);
86 var template = Mockito.mock(ToscaServiceTemplate.class);
87 element.setToscaServiceTemplateFragment(template);