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.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.acm.participant.intermediary.api.ParticipantIntermediaryApi;
30 import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
31 import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
39 class AutomationCompositionElementHandlerTest {
41 private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
42 private static final String ID_VERSION = "1.0.1";
43 private static final UUID automationCompositionElementId = UUID.randomUUID();
44 private static final ToscaConceptIdentifier automationCompositionId =
45 new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
48 void testHandlerDoesNotThrowExceptions() {
49 AutomationCompositionElementHandler handler = getTestingHandler();
51 assertDoesNotThrow(() -> handler
52 .automationCompositionElementStateChange(automationCompositionId,
53 automationCompositionElementId,
54 AutomationCompositionState.UNINITIALISED,
55 AutomationCompositionOrderedState.PASSIVE));
57 assertDoesNotThrow(() -> handler
58 .automationCompositionElementStateChange(automationCompositionId,
59 automationCompositionElementId,
60 AutomationCompositionState.RUNNING,
61 AutomationCompositionOrderedState.UNINITIALISED));
63 assertDoesNotThrow(() -> handler
64 .automationCompositionElementStateChange(automationCompositionId,
65 automationCompositionElementId,
66 AutomationCompositionState.PASSIVE,
67 AutomationCompositionOrderedState.RUNNING));
68 var element = getTestingAcElement();
69 var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
71 assertDoesNotThrow(() -> handler
72 .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
74 assertDoesNotThrow(() -> handler
75 .handleStatistics(automationCompositionElementId));
78 private AutomationCompositionElementHandler getTestingHandler() {
79 var api = Mockito.mock(PolicyApiHttpClient.class);
80 var pap = Mockito.mock(PolicyPapHttpClient.class);
81 var handler = new AutomationCompositionElementHandler(api, pap);
82 var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
83 var element = getTestingAcElement();
84 when(intermediaryApi.getAutomationCompositionElement(automationCompositionElementId)).thenReturn(element);
85 handler.setIntermediaryApi(intermediaryApi);
89 private AutomationCompositionElement getTestingAcElement() {
90 var element = new AutomationCompositionElement();
91 element.setDefinition(automationCompositionId);
92 element.setDescription("Description");
93 element.setId(automationCompositionElementId);
94 element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
95 element.setParticipantId(automationCompositionId);
96 element.setState(AutomationCompositionState.UNINITIALISED);
97 var template = Mockito.mock(ToscaServiceTemplate.class);
98 element.setToscaServiceTemplateFragment(template);