aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java
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/java
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/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java68
1 files changed, 31 insertions, 37 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;
}
/**