summaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-28 17:31:45 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-30 10:44:45 +0000
commit92c372362b9c2dabc4bd0ff3eb6e65ad5659ffb4 (patch)
tree548c03b01ecdb78500d581c8da19b2923a02e468 /models/src/test
parentbff1cfc07634e2a28460deca196b5b877948684e (diff)
Save ToscaServiceTemplate as Json in ACM
Save ToscaServiceTemplate as Json using DocToscaServiceTemplate as model. Issue-ID: POLICY-4468 Change-Id: I4c6f49012d091b87f0da4db2edcd5f16af2f4d5c 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.java68
-rw-r--r--models/src/test/resources/META-INF/persistence.xml27
2 files changed, 32 insertions, 63 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
index 2c01e9887..a2d6d69c2 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
@@ -32,16 +32,16 @@ import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
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.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.springframework.data.domain.Example;
class AcDefinitionProviderTest {
@@ -57,72 +57,66 @@ class AcDefinitionProviderTest {
}
@Test
- void testCreateServiceTemplate() throws PfModelException {
- var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
-
- var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
- var acmDefinition = new AutomationCompositionDefinition();
- acmDefinition.setCompositionId(UUID.randomUUID());
- acmDefinition.setServiceTemplate(jpaServiceTemplate.toAuthorative());
+ void testCreateServiceTemplate() {
+ var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
+ var acmDefinition = getAcDefinition(docServiceTemplate);
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class)))
.thenReturn(new JpaAutomationCompositionDefinition(acmDefinition));
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
var result = acDefinitionProvider.createAutomationCompositionDefinition(inputServiceTemplate);
- assertThat(result.getServiceTemplate()).isEqualTo(jpaServiceTemplate.toAuthorative());
+ assertThat(result.getServiceTemplate()).isEqualTo(docServiceTemplate.toAuthorative());
}
@Test
- void testDeleteAcDefintion() throws PfModelException {
- var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new,
- "toscaServiceTemplate");
- var acmDefinition = new AutomationCompositionDefinition();
- acmDefinition.setCompositionId(UUID.randomUUID());
- acmDefinition.setServiceTemplate(jpaServiceTemplate.toAuthorative());
+ void testDeleteAcDefintion() {
+ var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
+ var acmDefinition = getAcDefinition(docServiceTemplate);
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString()))
.thenReturn(Optional.of(new JpaAutomationCompositionDefinition(acmDefinition)));
- var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
var result = acDefinitionProvider.deleteAcDefintion(acmDefinition.getCompositionId());
- assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative());
+ assertThat(result).isEqualTo(docServiceTemplate.toAuthorative());
}
@Test
- void testDeleteServiceTemplateEmpty() throws PfModelException {
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository.findAll()).thenReturn(List.of());
-
+ void testDeleteServiceTemplateEmpty() {
var compositionId = UUID.randomUUID();
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(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");
- var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class);
- when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(),
- inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate));
-
+ void testGetServiceTemplate() {
+ var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
+ var acmDefinition = getAcDefinition(docServiceTemplate);
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(serviceTemplateRepository, acmDefinitionRepository);
+ when(acmDefinitionRepository.findAll(Mockito.<Example<JpaAutomationCompositionDefinition>>any()))
+ .thenReturn(List.of(new JpaAutomationCompositionDefinition(acmDefinition)));
+
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
var result = acDefinitionProvider.getServiceTemplateList(inputServiceTemplate.getName(),
inputServiceTemplate.getVersion());
assertThat(result).hasSize(1);
- assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative());
+ assertThat(result.get(0)).isEqualTo(acmDefinition.getServiceTemplate());
+ }
+
+ private AutomationCompositionDefinition getAcDefinition(DocToscaServiceTemplate docServiceTemplate) {
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setServiceTemplate(docServiceTemplate.toAuthorative());
+ return acmDefinition;
}
/**
diff --git a/models/src/test/resources/META-INF/persistence.xml b/models/src/test/resources/META-INF/persistence.xml
index 6020f2413..1e1d89309 100644
--- a/models/src/test/resources/META-INF/persistence.xml
+++ b/models/src/test/resources/META-INF/persistence.xml
@@ -25,34 +25,9 @@
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaParameter</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRelationshipTypes</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirement</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaRequirements</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition</class>
+ <class>org.onap.policy.clamp.models.acm.persistence.concepts.StringToServiceTemplateConverter</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class>