360485efa4345d57079846924c301449ac3b63a2
[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.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.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;
37
38 class AutomationCompositionElementHandlerTest {
39
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);
45
46     @Test
47     void testSimulatorHandlerExceptions() throws PfModelException {
48         AutomationCompositionElementHandler handler = getTestingHandler();
49
50         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
51             automationCompositionElementId, AutomationCompositionState.UNINITIALISED,
52             AutomationCompositionOrderedState.PASSIVE));
53
54         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
55             automationCompositionElementId, AutomationCompositionState.RUNNING,
56             AutomationCompositionOrderedState.UNINITIALISED));
57
58         assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId,
59             automationCompositionElementId, AutomationCompositionState.PASSIVE,
60             AutomationCompositionOrderedState.RUNNING));
61         var element = getTestingAcElement();
62         var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
63
64         assertDoesNotThrow(
65             () -> handler.automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
66
67         assertDoesNotThrow(() -> handler.handleStatistics(automationCompositionElementId));
68     }
69
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);
76         return handler;
77     }
78
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);
89         return element;
90     }
91 }