87be88658375387f4d896767ef917c6aa0c7121c
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.simulator.main.handler;
22
23 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.mockito.Mockito.when;
25
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;
36
37 class AutomationCompositionElementHandlerTest {
38
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);
44
45     @Test
46     void testSimulatorHandlerExceptions() {
47         AutomationCompositionElementHandler handler = getTestingHandler();
48
49         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
50             automationCompositionElementId, AutomationCompositionState.UNINITIALISED,
51             AutomationCompositionOrderedState.PASSIVE));
52
53         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
54             automationCompositionElementId, AutomationCompositionState.RUNNING,
55             AutomationCompositionOrderedState.UNINITIALISED));
56
57         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
58             automationCompositionElementId, AutomationCompositionState.PASSIVE,
59             AutomationCompositionOrderedState.RUNNING));
60         var element = getTestingAcElement();
61         var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
62
63         assertDoesNotThrow(
64             () -> handler.automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
65
66         assertDoesNotThrow(() -> handler.handleStatistics(automationCompositionElementId));
67     }
68
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);
75         return handler;
76     }
77
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);
88         return element;
89     }
90 }