85f21930e4cf4ed6d295ece69a33e43c6f35f2d8
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2022 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.clamp.acm.runtime.commissioning;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
29
30 import java.util.List;
31 import java.util.UUID;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
35 import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
36 import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
37 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
40
41 class CommissioningProviderTest {
42
43     /**
44      * Test the fetching of automation composition definitions (ToscaServiceTemplates).
45      *
46      * @throws Exception .
47      */
48     @Test
49     void testGetAutomationCompositionDefinitions() throws Exception {
50         var acProvider = mock(AutomationCompositionProvider.class);
51         var participantProvider = mock(ParticipantProvider.class);
52         var acDefinitionProvider = mock(AcDefinitionProvider.class);
53
54         var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
55
56         var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
57         assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
58
59         when(acDefinitionProvider.getServiceTemplateList(null, null))
60                 .thenReturn(List.of(new ToscaServiceTemplate()));
61         serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
62         assertThat(serviceTemplates.getServiceTemplates()).hasSize(1);
63     }
64
65     /**
66      * Test the creation of automation composition definitions (ToscaServiceTemplates).
67      *
68      * @throws Exception .
69      */
70     @Test
71     void testCreateAutomationCompositionDefinitions() throws Exception {
72         var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
73         var acmDefinition = new AutomationCompositionDefinition();
74         acmDefinition.setCompositionId(UUID.randomUUID());
75         acmDefinition.setServiceTemplate(serviceTemplate);
76         var acDefinitionProvider = mock(AcDefinitionProvider.class);
77         when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
78
79         // Response should return the number of node templates present in the service template
80         var acProvider = mock(AutomationCompositionProvider.class);
81         var participantProvider = mock(ParticipantProvider.class);
82         var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
83         List<ToscaConceptIdentifier> affectedDefinitions = provider
84                 .createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions();
85         verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
86         assertThat(affectedDefinitions).hasSize(7);
87     }
88
89     /**
90      * Test the fetching of a full ToscaServiceTemplate object - as opposed to the reduced template that is being
91      * tested in the testGetToscaServiceTemplateReduced() test.
92      *
93      */
94     @Test
95     void testGetToscaServiceTemplateList() throws Exception {
96         var acDefinitionProvider = mock(AcDefinitionProvider.class);
97         var acProvider = mock(AutomationCompositionProvider.class);
98         var participantProvider = mock(ParticipantProvider.class);
99
100         var provider =
101                 new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
102         ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
103         when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
104
105         var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
106         assertThat(returnedServiceTemplate).isNotNull();
107         assertThat(returnedServiceTemplate.getServiceTemplates()).isNotEmpty();
108     }
109 }