6b2ddf7e3f00ec162f26db899df731391d143e03
[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.policy.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.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;
38
39 class AutomationCompositionElementHandlerTest {
40
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);
46
47     @Test
48     void testHandlerDoesNotThrowExceptions() {
49         AutomationCompositionElementHandler handler = getTestingHandler();
50
51         assertDoesNotThrow(() -> handler
52             .automationCompositionElementStateChange(automationCompositionId,
53                 automationCompositionElementId,
54                 AutomationCompositionState.UNINITIALISED,
55                 AutomationCompositionOrderedState.PASSIVE));
56
57         assertDoesNotThrow(() -> handler
58             .automationCompositionElementStateChange(automationCompositionId,
59                 automationCompositionElementId,
60                 AutomationCompositionState.RUNNING,
61                 AutomationCompositionOrderedState.UNINITIALISED));
62
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);
70
71         assertDoesNotThrow(() -> handler
72             .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
73
74         assertDoesNotThrow(() -> handler
75             .handleStatistics(automationCompositionElementId));
76     }
77
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);
86         return handler;
87     }
88
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);
99         return element;
100     }
101 }