diff options
Diffstat (limited to 'models/src')
11 files changed, 117 insertions, 157 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java index 76496780d..c265e6458 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java @@ -29,6 +29,8 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaEntity; import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.models.base.Validated; @@ -37,6 +39,8 @@ import org.onap.policy.models.base.Validated; public final class ToscaServiceTemplateValidation { private static final String ROOT_KEY_NAME_SUFFIX = ".Root"; + private static final String AC_NODE_TYPE_NOT_PRESENT = + "NodeTemplate with type " + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " must exist!"; /** * validate a serviceTemplate. @@ -62,6 +66,8 @@ public final class ToscaServiceTemplateValidation { } } + validateToscaTopologyTemplate(result, serviceTemplate.getToscaTopologyTemplate()); + if (serviceTemplate.getToscaTopologyTemplate() != null) { validEntityTypeAncestors(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(), references.get(DocUtil.REF_NODE_TEMPLATES), result); @@ -85,6 +91,32 @@ public final class ToscaServiceTemplateValidation { } /** + * Validate ToscaTopologyTemplate. + * + * @param result + * + * @param topologyTemplate the ToscaServiceTemplate + */ + public static void validateToscaTopologyTemplate(BeanValidationResult result, + DocToscaTopologyTemplate topologyTemplate) { + if (topologyTemplate != null && topologyTemplate.getNodeTemplates() != null) { + var nodeTemplates = topologyTemplate.getNodeTemplates(); + var acNumber = nodeTemplates.values().stream().filter( + nodeTemplate -> AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType())) + .count(); + if (acNumber == 0) { + result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT); + } + if (acNumber > 1) { + result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type " + + AcmUtils.AUTOMATION_COMPOSITION_NODE_TYPE + " not allowed to be more than one!"); + } + } else { + result.addResult("TopologyTemplate", topologyTemplate, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT); + } + } + + /** * Validate that all data types referenced in policy types exist. * * @param result where the results are added @@ -199,8 +231,7 @@ public final class ToscaServiceTemplateValidation { continue; } if (!isTypePresent(parentEntityTypeKey, reference)) { - result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, - Validated.NOT_FOUND); + result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND); } } } @@ -222,8 +253,7 @@ public final class ToscaServiceTemplateValidation { continue; } if (!isTypePresent(parentEntityTypeKey, reference)) { - result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, - Validated.NOT_FOUND); + result.addResult("parent", parentEntityTypeKey, ValidationStatus.INVALID, Validated.NOT_FOUND); } } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java index 1bcbd6b0a..cdd1ab947 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java @@ -106,7 +106,8 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa var toscaProperty = new ToscaProperty(); toscaProperty.setName(name); - toscaProperty.setType(getTypeDocConceptKey().getId()); + toscaProperty.setType(type); + toscaProperty.setTypeVersion(typeVersion); toscaProperty.setDescription(description); toscaProperty.setRequired(required); toscaProperty.setStatus(status); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java index 89b3c42cd..f13ad6c41 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaSchemaDefinition.java @@ -70,7 +70,8 @@ public class DocToscaSchemaDefinition var toscaEntrySchema = new ToscaSchemaDefinition(); toscaEntrySchema.setName(name); - toscaEntrySchema.setType(getTypeDocConceptKey().getId()); + toscaEntrySchema.setType(type); + toscaEntrySchema.setTypeVersion(typeVersion); toscaEntrySchema.setDescription(description); if (constraints != null) { diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java index 377cecb28..025aafb07 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java @@ -66,8 +66,8 @@ public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjec public T toAuthorative() { var tosca = super.toAuthorative(); - tosca.setType(getTypeDocConceptKey().getId()); - tosca.setTypeVersion(""); + tosca.setType(type); + tosca.setTypeVersion(typeVersion); tosca.setProperties(PfUtils.mapMap(properties, x -> x)); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java index 247d8f28c..c46bdb96c 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java @@ -20,27 +20,25 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; -import com.google.gson.annotations.SerializedName; import java.util.UUID; -import javax.persistence.CascadeType; +import javax.persistence.Convert; import javax.persistence.Entity; -import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -import javax.persistence.OneToOne; +import javax.persistence.Lob; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; -import org.onap.policy.clamp.models.acm.utils.AcmUtils; +import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.Validated; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * Class to represent a automation composition definition in the database. @@ -57,10 +55,17 @@ public class JpaAutomationCompositionDefinition extends Validated @NotNull private String compositionId; - @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @SerializedName("serviceTemplate") + @NotNull + private String name; + + @NotNull + private String version; + + @Lob + @Convert(converter = StringToServiceTemplateConverter.class) + @NotNull @Valid - private JpaToscaServiceTemplate serviceTemplate; + private DocToscaServiceTemplate serviceTemplate; @Override public AutomationCompositionDefinition toAuthorative() { @@ -73,7 +78,9 @@ public class JpaAutomationCompositionDefinition extends Validated @Override public void fromAuthorative(final AutomationCompositionDefinition copyConcept) { compositionId = copyConcept.getCompositionId().toString(); - serviceTemplate = new JpaToscaServiceTemplate(copyConcept.getServiceTemplate()); + serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate()); + setName(serviceTemplate.getName()); + setVersion(serviceTemplate.getVersion()); } public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) { @@ -87,8 +94,7 @@ public class JpaAutomationCompositionDefinition extends Validated @Override public BeanValidationResult validate(@NonNull String fieldName) { var result = super.validate(fieldName); - - AcmUtils.validateToscaTopologyTemplate(result, serviceTemplate); + ToscaServiceTemplateValidation.validate(result, serviceTemplate); if (!result.isValid()) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java index dc1785e52..12a05946e 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java @@ -23,15 +23,16 @@ package org.onap.policy.clamp.models.acm.persistence.provider; import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; 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.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.springframework.data.domain.Example; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +41,6 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class AcDefinitionProvider { - private final ToscaServiceTemplateRepository serviceTemplateRepository; private final AutomationCompositionDefinitionRepository acmDefinitionRepository; /** @@ -68,9 +68,12 @@ public class AcDefinitionProvider { * @param serviceTemplate the service template to be created */ public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate) { - var jpaServiceTemplate = - ProviderUtils.getJpaAndValidate(serviceTemplate, JpaToscaServiceTemplate::new, "toscaServiceTemplate"); - serviceTemplateRepository.save(jpaServiceTemplate); + var acmDefinition = new AutomationCompositionDefinition(); + acmDefinition.setCompositionId(compositionId); + acmDefinition.setServiceTemplate(serviceTemplate); + var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new, + "AutomationCompositionDefinition"); + acmDefinitionRepository.save(jpaAcmDefinition); } /** @@ -88,7 +91,6 @@ public class AcDefinitionProvider { } var item = jpaDelete.get().getServiceTemplate(); - serviceTemplateRepository.deleteById(item.getKey()); acmDefinitionRepository.deleteById(compositionId.toString()); return item.toAuthorative(); } @@ -120,7 +122,7 @@ public class AcDefinitionProvider { public Optional<ToscaServiceTemplate> findAcDefinition(UUID compositionId) { var jpaGet = acmDefinitionRepository.findById(compositionId.toString()); return jpaGet.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate) - .map(JpaToscaServiceTemplate::toAuthorative).findFirst(); + .map(DocToscaServiceTemplate::toAuthorative).findFirst(); } /** @@ -143,7 +145,18 @@ public class AcDefinitionProvider { */ @Transactional(readOnly = true) public List<ToscaServiceTemplate> getServiceTemplateList(final String name, final String version) { - var jpaList = serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, name, version); - return ProviderUtils.asEntityList(jpaList); + List<JpaAutomationCompositionDefinition> jpaList = null; + if (name != null || version != null) { + var entity = new JpaAutomationCompositionDefinition(); + entity.setName(name); + entity.setVersion(version); + var example = Example.of(entity); + jpaList = acmDefinitionRepository.findAll(example); + } else { + jpaList = acmDefinitionRepository.findAll(); + } + + return jpaList.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate) + .map(DocToscaServiceTemplate::toAuthorative).collect(Collectors.toList()); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java index 64a0a0fb4..df4d7dffa 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java @@ -22,10 +22,11 @@ package org.onap.policy.clamp.models.acm.persistence.repository; import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.QueryByExampleExecutor; import org.springframework.stereotype.Repository; @Repository public interface AutomationCompositionDefinitionRepository - extends JpaRepository<JpaAutomationCompositionDefinition, String> { - + extends JpaRepository<JpaAutomationCompositionDefinition, String>, + QueryByExampleExecutor<JpaAutomationCompositionDefinition> { } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java deleted file mode 100644 index b9190d0a7..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.models.acm.persistence.repository; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ToscaServiceTemplateRepository - extends JpaRepository<JpaToscaServiceTemplate, PfConceptKey>, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index a8203484a..cdd3e1e54 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -48,7 +48,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * Utility functions used in acm-runtime and participants. @@ -57,9 +56,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AcmUtils { - private static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition"; - private static final String AC_NODE_TYPE_NOT_PRESENT = - "NodeTemplate with type " + AUTOMATION_COMPOSITION_NODE_TYPE + " must exist!"; + public static final String AUTOMATION_COMPOSITION_NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition"; public static final String ENTRY = "entry "; /** @@ -356,32 +353,4 @@ public final class AcmUtils { return getFinalNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap); } - - /** - * Validate ToscaTopologyTemplate. - * - * @param result - * - * @param serviceTemplate the ToscaServiceTemplate - */ - public static void validateToscaTopologyTemplate(BeanValidationResult result, - JpaToscaServiceTemplate serviceTemplate) { - if (serviceTemplate.getTopologyTemplate() != null - && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) { - var nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); - var acNumber = nodeTemplates.getConceptMap().values().stream() - .filter(nodeTemplate -> AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType().getName())) - .count(); - if (acNumber == 0) { - result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT); - } - if (acNumber > 1) { - result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type " - + AUTOMATION_COMPOSITION_NODE_TYPE + " not allowed to be more than one!"); - } - } else { - result.addResult("ServiceTemplate", serviceTemplate, ValidationStatus.INVALID, AC_NODE_TYPE_NOT_PRESENT); - } - } - } 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> |