0d114db8df6a6ec9caf3d151740a339be9bdb129
[policy/clamp.git] /
1 /*-
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
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.base.PfModelException;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
39
40 class AutomationCompositionElementHandlerTest {
41
42     private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
43     private static final String ID_VERSION = "1.0.1";
44     private static final UUID automationCompositionElementId = UUID.randomUUID();
45     private static final ToscaConceptIdentifier automationCompositionId =
46         new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
47
48     @Test
49     void testHandlerExceptions() {
50         AutomationCompositionElementHandler handler = getTestingHandler();
51
52         assertDoesNotThrow(() -> handler
53             .automationCompositionElementStateChange(automationCompositionId,
54                 automationCompositionElementId,
55                 AutomationCompositionState.UNINITIALISED,
56                 AutomationCompositionOrderedState.PASSIVE));
57
58         assertDoesNotThrow(() -> handler
59             .automationCompositionElementStateChange(automationCompositionId,
60                 automationCompositionElementId,
61                 AutomationCompositionState.RUNNING,
62                 AutomationCompositionOrderedState.UNINITIALISED));
63
64         assertDoesNotThrow(() -> handler
65             .automationCompositionElementStateChange(automationCompositionId,
66                 automationCompositionElementId,
67                 AutomationCompositionState.PASSIVE,
68                 AutomationCompositionOrderedState.RUNNING));
69         var element = getTestingAcElement();
70         var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
71
72         assertDoesNotThrow(() -> handler
73             .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
74
75         assertDoesNotThrow(() -> handler
76             .handleStatistics(automationCompositionElementId));
77     }
78
79     AutomationCompositionElementHandler getTestingHandler() {
80         var api = Mockito.mock(PolicyApiHttpClient.class);
81         var pap = Mockito.mock(PolicyPapHttpClient.class);
82         var handler = new AutomationCompositionElementHandler(api, pap);
83         var intermediaryApi = Mockito.mock(ParticipantIntermediaryApi.class);
84         var element = getTestingAcElement();
85         when(intermediaryApi.getAutomationCompositionElement(automationCompositionElementId)).thenReturn(element);
86         handler.setIntermediaryApi(intermediaryApi);
87         return handler;
88     }
89
90     AutomationCompositionElement getTestingAcElement() {
91         var element = new AutomationCompositionElement();
92         element.setDefinition(automationCompositionId);
93         element.setDescription("Description");
94         element.setId(automationCompositionElementId);
95         element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
96         element.setParticipantId(automationCompositionId);
97         element.setState(AutomationCompositionState.UNINITIALISED);
98         var template = Mockito.mock(ToscaServiceTemplate.class);
99         element.setToscaServiceTemplateFragment(template);
100         return element;
101     }
102 }