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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.acm.runtime.commissioning;
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;
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;
41 class CommissioningProviderTest {
44 * Test the fetching of automation composition definitions (ToscaServiceTemplates).
49 void testGetAutomationCompositionDefinitions() throws Exception {
50 var acProvider = mock(AutomationCompositionProvider.class);
51 var participantProvider = mock(ParticipantProvider.class);
52 var acDefinitionProvider = mock(AcDefinitionProvider.class);
54 var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
56 var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
57 assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
59 when(acDefinitionProvider.getServiceTemplateList(null, null))
60 .thenReturn(List.of(new ToscaServiceTemplate()));
61 serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
62 assertThat(serviceTemplates.getServiceTemplates()).hasSize(1);
66 * Test the creation of automation composition definitions (ToscaServiceTemplates).
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);
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);
90 * Test the fetching of a full ToscaServiceTemplate object - as opposed to the reduced template that is being
91 * tested in the testGetToscaServiceTemplateReduced() test.
95 void testGetToscaServiceTemplateList() throws Exception {
96 var acDefinitionProvider = mock(AcDefinitionProvider.class);
97 var acProvider = mock(AutomationCompositionProvider.class);
98 var participantProvider = mock(ParticipantProvider.class);
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));
105 var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
106 assertThat(returnedServiceTemplate).isNotNull();
107 assertThat(returnedServiceTemplate.getServiceTemplates()).isNotEmpty();