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.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.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 AutomationCompositionElementHandlerTest {
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 automationCompositionElementId = UUID.randomUUID();
43 private static final ToscaConceptIdentifier automationCompositionId =
44 new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
47 void testSimulatorHandlerExceptions() throws PfModelException {
48 AutomationCompositionElementHandler handler = getTestingHandler();
50 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
51 automationCompositionElementId, AutomationCompositionState.UNINITIALISED,
52 AutomationCompositionOrderedState.PASSIVE));
54 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
55 automationCompositionElementId, AutomationCompositionState.RUNNING,
56 AutomationCompositionOrderedState.UNINITIALISED));
58 assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
59 automationCompositionElementId, AutomationCompositionState.PASSIVE,
60 AutomationCompositionOrderedState.RUNNING));
61 var element = getTestingAcElement();
62 var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
65 () -> handler.automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
67 assertDoesNotThrow(() -> handler.handleStatistics(automationCompositionElementId));
70 AutomationCompositionElementHandler getTestingHandler() {
71 var handler = new AutomationCompositionElementHandler();
72 var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
73 var element = getTestingAcElement();
74 when(intermediaryApi.getAutomationCompositionElement(automationCompositionElementId)).thenReturn(element);
75 handler.setIntermediaryApi(intermediaryApi);
79 AutomationCompositionElement getTestingAcElement() {
80 var element = new AutomationCompositionElement();
81 element.setDefinition(automationCompositionId);
82 element.setDescription("Description");
83 element.setId(automationCompositionElementId);
84 element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
85 element.setParticipantId(automationCompositionId);
86 element.setState(AutomationCompositionState.UNINITIALISED);
87 var template = Mockito.mock(ToscaServiceTemplate.class);
88 element.setToscaServiceTemplateFragment(template);