aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-15 17:03:34 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-18 08:57:36 +0000
commita2e99e7df02837d8270228c330bed4915043b996 (patch)
tree2864318cdd99e18fd1cbb2322318b3e89fe7454c /models/src/test
parent5f72a385593d3ca906c8f3a6c382db213fce206c (diff)
Link the existing CommissioningController with the generated code
Link the existing CommissioningController endpoint implementation code with the generated code in Acm. Issue-ID: POLICY-4454 Change-Id: Ie10296b6af8c8bfdbfa7f54714b22ca4804a2eef Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java (renamed from models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java)110
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java31
2 files changed, 65 insertions, 76 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
index 9e4133da5..2c01e9887 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
@@ -22,7 +22,6 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -30,18 +29,21 @@ import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-class ServiceTemplateProviderTest {
+class AcDefinitionProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
@@ -55,97 +57,69 @@ class ServiceTemplateProviderTest {
}
@Test
- void testGetCommonOrInstancePropertiesFromNodeTypes() throws PfModelException {
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
-
- var result = serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate);
- assertNotNull(result);
- assertThat(result).hasSize(6);
- }
-
- @Test
void testCreateServiceTemplate() throws PfModelException {
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
- when(serviceTemplateRepository.save(jpaServiceTemplate)).thenReturn(jpaServiceTemplate);
+ "toscaServiceTemplate");
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setServiceTemplate(jpaServiceTemplate.toAuthorative());
- var result = serviceTemplateProvider.createServiceTemplate(inputServiceTemplate);
+ when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class)))
+ .thenReturn(new JpaAutomationCompositionDefinition(acmDefinition));
- assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative());
- }
-
- @Test
- void testDeleteServiceTemplate() throws PfModelException {
- var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository
- .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion())))
- .thenReturn(Optional.of(jpaServiceTemplate));
-
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
- var result = serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion());
+ var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var result = acDefinitionProvider.createAutomationCompositionDefinition(inputServiceTemplate);
- assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative());
+ assertThat(result.getServiceTemplate()).isEqualTo(jpaServiceTemplate.toAuthorative());
}
@Test
- void testDeleteServiceTemplateEmpty() throws PfModelException {
+ void testDeleteAcDefintion() throws PfModelException {
var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository
- .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion())))
- .thenReturn(Optional.empty());
-
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
- assertThatThrownBy(() -> serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion()))
- .hasMessage("delete of serviceTemplate \"NULL:0.0.0\" failed, serviceTemplate does not exist");
- }
+ "toscaServiceTemplate");
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setServiceTemplate(jpaServiceTemplate.toAuthorative());
- @Test
- void testGetServiceTemplateListEmpty() {
var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository.findById(any())).thenReturn(Optional.empty());
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString()))
+ .thenReturn(Optional.of(new JpaAutomationCompositionDefinition(acmDefinition)));
+
+ var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var result = acDefinitionProvider.deleteAcDefintion(acmDefinition.getCompositionId());
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
- assertThatThrownBy(() -> serviceTemplateProvider.getToscaServiceTemplate("Name", "1.0.0"))
- .hasMessage("Automation composition definitions not found");
+ assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative());
}
@Test
- void testGetServiceTemplateList() throws PfModelException {
- var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
+ void testDeleteServiceTemplateEmpty() throws PfModelException {
var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository
- .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion())))
- .thenReturn(Optional.of(jpaServiceTemplate));
-
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
- var result = serviceTemplateProvider.getToscaServiceTemplate(inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion());
-
- assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative());
+ when(serviceTemplateRepository.findAll()).thenReturn(List.of());
+
+ var compositionId = UUID.randomUUID();
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ assertThatThrownBy(() -> acDefinitionProvider.deleteAcDefintion(compositionId))
+ .hasMessage("delete of Automation Composition Definition \"" + compositionId
+ + "\" failed, Automation Composition Definition does not exist");
}
@Test
void testGetServiceTemplate() throws PfModelException {
var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
+ "toscaServiceTemplate");
var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate));
+ inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate));
- var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository);
- var result = serviceTemplateProvider.getServiceTemplateList(inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion());
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var result = acDefinitionProvider.getServiceTemplateList(inputServiceTemplate.getName(),
+ inputServiceTemplate.getVersion());
assertThat(result).hasSize(1);
assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative());
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index 0e68593c2..ccb4b8360 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.models.acm.utils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.ArrayList;
@@ -34,6 +35,8 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -46,7 +49,9 @@ class AcmUtilsTest {
private final ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.0.0");
private final ToscaConceptIdentifier idNode =
- new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", "0.0.0");
+ new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", "0.0.0");
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
@Test
void testCommonUtilsParticipantUpdate() {
@@ -71,7 +76,7 @@ class AcmUtilsTest {
void testCommonUtilsServiceTemplate() {
var acElement = new AutomationCompositionElement();
var toscaServiceTemplate = getDummyToscaServiceTemplate();
- AcmUtils.setServiceTemplatePolicyInfo(acElement, toscaServiceTemplate);
+ AcmUtils.setAcPolicyInfo(acElement, toscaServiceTemplate);
assertEquals(getDummyToscaDataTypeMap(), acElement.getToscaServiceTemplateFragment().getDataTypes());
}
@@ -87,7 +92,7 @@ class AcmUtilsTest {
checkParticipantDefinitionUpdate(toscaServiceTemplate, participantDefinitionUpdates);
assertEquals(idNode, participantDefinitionUpdates.get(0).getAutomationCompositionElementDefinitionList().get(0)
- .getAcElementDefinitionId());
+ .getAcElementDefinitionId());
}
@Test
@@ -96,10 +101,20 @@ class AcmUtilsTest {
toscaServiceTemplate.setPolicyTypes(null);
toscaServiceTemplate.getToscaTopologyTemplate().setPolicies(null);
AutomationCompositionElement acElement = new AutomationCompositionElement();
- AcmUtils.setServiceTemplatePolicyInfo(new AutomationCompositionElement(), toscaServiceTemplate);
+ AcmUtils.setAcPolicyInfo(new AutomationCompositionElement(), toscaServiceTemplate);
assertNull(acElement.getToscaServiceTemplateFragment());
}
+ @Test
+ void testGetCommonOrInstancePropertiesFromNodeTypes() throws Exception {
+ var inputServiceTemplate = YAML_TRANSLATOR
+ .decode(ResourceUtils.getResourceAsStream(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+
+ var result = AcmUtils.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate);
+ assertNotNull(result);
+ assertThat(result).hasSize(6);
+ }
+
private ToscaServiceTemplate getDummyToscaServiceTemplate() {
var toscaServiceTemplate = new ToscaServiceTemplate();
var policyTypes = getDummyPolicyTypesMap();
@@ -146,14 +161,14 @@ class AcmUtilsTest {
}
private void checkParticipantDefinitionUpdate(ToscaServiceTemplate toscaServiceTemplate,
- List<ParticipantDefinition> participantDefinitionUpdates) {
+ List<ParticipantDefinition> participantDefinitionUpdates) {
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
- .getNodeTemplates().entrySet()) {
+ .getNodeTemplates().entrySet()) {
if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(),
- toscaServiceTemplate)) {
+ toscaServiceTemplate)) {
AcmUtils.prepareParticipantDefinitionUpdate(id, toscaInputEntry.getKey(), toscaInputEntry.getValue(),
- participantDefinitionUpdates, null);
+ participantDefinitionUpdates, null);
}
}
}