summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-24 10:41:40 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2022-11-24 14:52:18 +0000
commit933f1325044e6233ca0da1eecf223bc5bbb06b36 (patch)
tree77ab10ee6fa109b53294e328ead2df12aee78a73 /models
parenta2e99e7df02837d8270228c330bed4915043b996 (diff)
Link the AutomationComposition with AutomationCompositionDefinition
In AutomationComposition replace the link to ToscaNodeTemplate whit a link to AutomationCompositionDefinition using compositionId. Issue-ID: POLICY-4464 Change-Id: I66878f04ef93fb0754d0066e78bd074ce082f891 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java16
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java43
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java24
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java27
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java80
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java46
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java23
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java34
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java106
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java122
-rw-r--r--models/src/test/resources/json/AutomationCompositionNoOrderedState.json5
-rw-r--r--models/src/test/resources/providers/TestAutomationCompositions.json10
15 files changed, 234 insertions, 343 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
index 4736d3190..c3245d27c 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
@@ -27,9 +27,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.collections4.MapUtils;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
/**
@@ -40,7 +38,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
@EqualsAndHashCode(callSuper = true)
public class AutomationComposition extends ToscaEntity implements Comparable<AutomationComposition> {
@NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private UUID compositionId;
@NonNull
private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED;
@@ -53,16 +51,6 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
@NonNull
private Boolean primed = false;
- @Override
- public String getType() {
- return definition.getName();
- }
-
- @Override
- public String getTypeVersion() {
- return definition.getVersion();
- }
-
/**
* Copy contructor, does a deep copy.
*
@@ -70,7 +58,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
*/
public AutomationComposition(final AutomationComposition otherAutomationComposition) {
super(otherAutomationComposition);
- this.definition = new ToscaConceptIdentifier(otherAutomationComposition.definition);
+ this.compositionId = otherAutomationComposition.compositionId;
this.state = otherAutomationComposition.state;
this.orderedState = otherAutomationComposition.orderedState;
this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
index e5c44d0a2..8268e9066 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
-import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
+import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
@@ -52,7 +52,6 @@ import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.base.validation.annotations.VerifyKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent a automation composition in the database.
@@ -60,7 +59,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
* @author Liam Fallon (liam.fallon@est.tech)
*/
@Entity
-@Table(name = "AutomationComposition")
+@Table(name = "AutomationComposition", indexes = {@Index(name = "ac_compositionId", columnList = "compositionId")})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
@@ -72,13 +71,8 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
@NotNull
private PfConceptKey key;
- // @formatter:off
- @VerifyKey
@NotNull
- @AttributeOverride(name = "name", column = @Column(name = "definition_name"))
- @AttributeOverride(name = "version", column = @Column(name = "definition_version"))
- private PfConceptKey definition;
- // @formatter:on
+ private String compositionId;
@Column
@NotNull
@@ -112,22 +106,22 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
* @param key the key
*/
public JpaAutomationComposition(@NonNull final PfConceptKey key) {
- this(key, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
+ this(key, UUID.randomUUID().toString(), AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
}
/**
* The Key Constructor creates a {@link JpaAutomationComposition} object with all mandatory fields.
*
* @param key the key
- * @param definition the TOSCA definition of the automation composition
+ * @param compositionId the TOSCA compositionId of the automation composition definition
* @param state the state of the automation composition
* @param elements the elements of the automation composition in participants
*/
- public JpaAutomationComposition(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition,
- @NonNull final AutomationCompositionState state,
- @NonNull final Map<UUID, JpaAutomationCompositionElement> elements) {
+ public JpaAutomationComposition(@NonNull final PfConceptKey key, @NonNull final String compositionId,
+ @NonNull final AutomationCompositionState state,
+ @NonNull final Map<UUID, JpaAutomationCompositionElement> elements) {
this.key = key;
- this.definition = definition;
+ this.compositionId = compositionId;
this.state = state;
this.elements = elements;
}
@@ -140,12 +134,12 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
public JpaAutomationComposition(@NonNull final JpaAutomationComposition copyConcept) {
super(copyConcept);
this.key = new PfConceptKey(copyConcept.key);
- this.definition = new PfConceptKey(copyConcept.definition);
+ this.compositionId = copyConcept.compositionId;
this.state = copyConcept.state;
this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
this.elements =
- PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0));
+ PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0));
this.primed = copyConcept.primed;
}
@@ -164,12 +158,12 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
automationComposition.setName(getKey().getName());
automationComposition.setVersion(getKey().getVersion());
- automationComposition.setDefinition(new ToscaConceptIdentifier(definition));
+ automationComposition.setCompositionId(UUID.fromString(compositionId));
automationComposition.setState(state);
automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
automationComposition.setDescription(description);
automationComposition.setElements(
- PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0)));
+ PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0)));
automationComposition.setPrimed(primed);
return automationComposition;
@@ -181,7 +175,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
this.setKey(new PfConceptKey(automationComposition.getName(), automationComposition.getVersion()));
}
- this.definition = automationComposition.getDefinition().asConceptKey();
+ this.compositionId = automationComposition.getCompositionId().toString();
this.state = automationComposition.getState();
this.orderedState = automationComposition.getOrderedState();
this.description = automationComposition.getDescription();
@@ -191,7 +185,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
for (Entry<UUID, AutomationCompositionElement> elementEntry : automationComposition.getElements().entrySet()) {
var jpaAutomationCompositionElement = new JpaAutomationCompositionElement();
jpaAutomationCompositionElement
- .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString()));
+ .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString()));
jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue());
this.elements.put(elementEntry.getKey(), jpaAutomationCompositionElement);
}
@@ -201,8 +195,6 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
public List<PfKey> getKeys() {
List<PfKey> keyList = getKey().getKeys();
- keyList.add(definition);
-
for (JpaAutomationCompositionElement element : elements.values()) {
keyList.addAll(element.getKeys());
}
@@ -213,7 +205,6 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
@Override
public void clean() {
key.clean();
- definition.clean();
description = (description == null ? null : description.trim());
for (JpaAutomationCompositionElement element : elements.values()) {
@@ -239,7 +230,7 @@ public class JpaAutomationComposition extends PfConcept implements PfAuthorative
return result;
}
- result = definition.compareTo(other.definition);
+ result = ObjectUtils.compare(compositionId, other.compositionId);
if (result != 0) {
return result;
}
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 46c09d388..247d8f28c 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
@@ -32,11 +32,14 @@ import javax.persistence.OneToOne;
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.persistence.provider.ProviderUtils;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+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;
/**
@@ -47,7 +50,8 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationCompositionDefinition implements PfAuthorative<AutomationCompositionDefinition> {
+public class JpaAutomationCompositionDefinition extends Validated
+ implements PfAuthorative<AutomationCompositionDefinition> {
@Id
@NotNull
@@ -69,9 +73,7 @@ public class JpaAutomationCompositionDefinition implements PfAuthorative<Automat
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
compositionId = copyConcept.getCompositionId().toString();
- serviceTemplate = ProviderUtils.getJpaAndValidate(copyConcept.getServiceTemplate(),
- JpaToscaServiceTemplate::new, "toscaServiceTemplate");
-
+ serviceTemplate = new JpaToscaServiceTemplate(copyConcept.getServiceTemplate());
}
public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) {
@@ -82,4 +84,16 @@ public class JpaAutomationCompositionDefinition implements PfAuthorative<Automat
super();
}
+ @Override
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ var result = super.validate(fieldName);
+
+ AcmUtils.validateToscaTopologyTemplate(result, serviceTemplate);
+
+ if (!result.isValid()) {
+ return result;
+ }
+
+ 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 5740207c7..dc1785e52 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
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
import java.util.List;
+import java.util.Optional;
import java.util.UUID;
import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
@@ -53,7 +54,10 @@ public class AcDefinitionProvider {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
acmDefinition.setServiceTemplate(serviceTemplate);
- var result = acmDefinitionRepository.save(new JpaAutomationCompositionDefinition(acmDefinition));
+ var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
+ "AutomationCompositionDefinition");
+ var result = acmDefinitionRepository.save(jpaAcmDefinition);
+
return result.toAuthorative();
}
@@ -107,13 +111,26 @@ public class AcDefinitionProvider {
}
/**
- * Get service templates.
+ * Get the requested automation composition definition.
*
- * @return the topology templates found
+ * @param compositionId The UUID of the automation composition definition to delete
+ * @return the automation composition definition
+ */
+ @Transactional(readOnly = true)
+ public Optional<ToscaServiceTemplate> findAcDefinition(UUID compositionId) {
+ var jpaGet = acmDefinitionRepository.findById(compositionId.toString());
+ return jpaGet.stream().map(JpaAutomationCompositionDefinition::getServiceTemplate)
+ .map(JpaToscaServiceTemplate::toAuthorative).findFirst();
+ }
+
+ /**
+ * Get Automation Composition Definitions.
+ *
+ * @return the Automation Composition Definitions found
*/
@Transactional(readOnly = true)
- public List<ToscaServiceTemplate> getAllServiceTemplates() {
- var jpaList = serviceTemplateRepository.findAll();
+ public List<AutomationCompositionDefinition> getAllAcDefinitions() {
+ var jpaList = acmDefinitionRepository.findAll();
return ProviderUtils.asEntityList(jpaList);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index c4f8b91e7..272ea422b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import java.util.List;
import java.util.Optional;
+import java.util.UUID;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -32,13 +33,9 @@ import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -51,7 +48,6 @@ import org.springframework.transaction.annotation.Transactional;
public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
- private final ToscaNodeTemplateRepository toscaNodeTemplateRepository;
/**
* Get automation composition.
@@ -62,7 +58,7 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public AutomationComposition getAutomationComposition(final ToscaConceptIdentifier automationCompositionId)
- throws PfModelException {
+ throws PfModelException {
try {
return automationCompositionRepository.getById(automationCompositionId.asConceptKey()).toAuthorative();
} catch (EntityNotFoundException e) {
@@ -80,7 +76,7 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(@NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
return findAutomationComposition(new PfConceptKey(name, version));
}
@@ -93,12 +89,12 @@ public class AutomationCompositionProvider {
*/
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(
- final ToscaConceptIdentifier automationCompositionId) throws PfModelException {
+ final ToscaConceptIdentifier automationCompositionId) throws PfModelException {
return findAutomationComposition(automationCompositionId.asConceptKey());
}
private Optional<AutomationComposition> findAutomationComposition(@NonNull final PfConceptKey key)
- throws PfModelException {
+ throws PfModelException {
try {
return automationCompositionRepository.findById(key).map(JpaAutomationComposition::toAuthorative);
} catch (IllegalArgumentException e) {
@@ -114,10 +110,10 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors updating the automation composition
*/
public AutomationComposition saveAutomationComposition(final AutomationComposition automationComposition)
- throws PfModelException {
+ throws PfModelException {
try {
var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition,
- JpaAutomationComposition::new, "automation composition"));
+ JpaAutomationComposition::new, "automation composition"));
// Return the saved participant
return result.toAuthorative();
@@ -127,14 +123,15 @@ public class AutomationCompositionProvider {
}
/**
- * Get all automation compositions.
+ * Get all automation compositions by compositionId.
*
+ * @param compositionId the compositionId of the automation composition definition
* @return all automation compositions found
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions() {
-
- return ProviderUtils.asEntityList(automationCompositionRepository.findAll());
+ public List<AutomationComposition> getAcInstancesByCompositionId(UUID compositionId) {
+ return ProviderUtils
+ .asEntityList(automationCompositionRepository.findByCompositionId(compositionId.toString()));
}
/**
@@ -147,8 +144,8 @@ public class AutomationCompositionProvider {
@Transactional(readOnly = true)
public List<AutomationComposition> getAutomationCompositions(final String name, final String version) {
- return ProviderUtils
- .asEntityList(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
+ return ProviderUtils.asEntityList(
+ automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
}
/**
@@ -159,11 +156,11 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors creating automation compositions
*/
public List<AutomationComposition> saveAutomationCompositions(
- @NonNull final List<AutomationComposition> automationCompositions) throws PfModelException {
+ @NonNull final List<AutomationComposition> automationCompositions) throws PfModelException {
try {
var result =
- automationCompositionRepository.saveAll(ProviderUtils.getJpaAndValidateList(automationCompositions,
- JpaAutomationComposition::new, "automation compositions"));
+ automationCompositionRepository.saveAll(ProviderUtils.getJpaAndValidateList(automationCompositions,
+ JpaAutomationComposition::new, "automation compositions"));
// Return the saved participant
return ProviderUtils.asEntityList(result);
@@ -181,14 +178,14 @@ public class AutomationCompositionProvider {
* @throws PfModelException on errors deleting the automation composition
*/
public AutomationComposition deleteAutomationComposition(@NonNull final String name, @NonNull final String version)
- throws PfModelException {
+ throws PfModelException {
var automationCompositionKey = new PfConceptKey(name, version);
var jpaDeleteAutomationComposition = automationCompositionRepository.findById(automationCompositionKey);
if (jpaDeleteAutomationComposition.isEmpty()) {
String errorMessage = "delete of automation composition \"" + automationCompositionKey.getId()
- + "\" failed, automation composition does not exist";
+ + "\" failed, automation composition does not exist";
throw new PfModelException(Response.Status.NOT_FOUND, errorMessage);
}
@@ -196,43 +193,4 @@ public class AutomationCompositionProvider {
return jpaDeleteAutomationComposition.get().toAuthorative();
}
-
- /**
- * Get All Node Templates.
- *
- * @return the list of node templates found
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getAllNodeTemplates() {
- return ProviderUtils.asEntityList(toscaNodeTemplateRepository.findAll());
- }
-
- /**
- * Get Node Templates.
- *
- * @param name the name of the node template to get, null to get all node templates
- * @param version the version of the node template to get, null to get all node templates
- * @return the node templates found
- * @throws PfModelException on errors getting node templates
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getNodeTemplates(final String name, final String version) {
- return ProviderUtils
- .asEntityList(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version));
- }
-
- /**
- * Get filtered node templates.
- *
- * @param filter the filter for the node templates to get
- * @return the node templates found
- * @throws PfModelException on errors getting node templates
- */
- @Transactional(readOnly = true)
- public List<ToscaNodeTemplate> getFilteredNodeTemplates(
- @NonNull final ToscaTypedEntityFilter<ToscaNodeTemplate> filter) {
-
- return filter.filter(ProviderUtils.asEntityList(toscaNodeTemplateRepository
- .getFiltered(JpaToscaNodeTemplate.class, filter.getName(), filter.getVersion())));
- }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
index 7d751fa36..9dc07ae72 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
@@ -31,7 +31,7 @@ import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
+import org.onap.policy.models.base.Validated;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProviderUtils {
@@ -72,7 +72,7 @@ public final class ProviderUtils {
* @param conceptDescription the description used for validation result
* @return the Jpa object
*/
- public static <A, J extends PfConcept & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
+ public static <A, J extends Validated & PfAuthorative<A>> J getJpaAndValidate(A authorativeConcept,
Supplier<J> jpaSupplier, String conceptDescription) {
var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept);
@@ -95,7 +95,7 @@ public final class ProviderUtils {
* @param jpaEntityList the list to convert
* @return the authorative list
*/
- public static <T extends ToscaEntity, J extends PfAuthorative<T>> List<T> asEntityList(List<J> jpaEntityList) {
+ public static <T, J extends PfAuthorative<T>> List<T> asEntityList(List<J> jpaEntityList) {
return jpaEntityList.stream().map(J::toAuthorative).collect(Collectors.toList());
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
index 8eeb77e0d..273b99a63 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.List;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.models.base.PfConceptKey;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -28,4 +29,6 @@ import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionRepository
extends JpaRepository<JpaAutomationComposition, PfConceptKey>, FilterRepository {
+
+ List<JpaAutomationComposition> findByCompositionId(String compositionId);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java
deleted file mode 100644
index 20d0f0f7e..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.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.JpaToscaNodeTemplate;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-public interface ToscaNodeTemplateRepository
- extends JpaRepository<JpaToscaNodeTemplate, 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 283edd49e..a8203484a 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,6 +48,7 @@ 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,6 +58,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
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 ENTRY = "entry ";
/**
@@ -175,20 +178,19 @@ public final class AcmUtils {
*/
public static BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition,
ToscaServiceTemplate serviceTemplate) {
- var result = new BeanValidationResult(ENTRY + automationComposition.getDefinition().getName(),
- automationComposition);
+ var result = new BeanValidationResult(ENTRY + automationComposition.getName(), automationComposition);
var map = getMapToscaNodeTemplates(serviceTemplate);
- var toscaNodeTemplate = map.get(new ToscaConceptIdentifier(automationComposition.getDefinition().getName(),
- automationComposition.getDefinition().getVersion()));
+ var nodeTemplateGet = map.values().stream()
+ .filter(nodeTemplate -> AUTOMATION_COMPOSITION_NODE_TYPE.equals(nodeTemplate.getType())).findFirst();
- if (toscaNodeTemplate == null || !AUTOMATION_COMPOSITION_NODE_TYPE.equals(toscaNodeTemplate.getType())) {
- result.addResult(
- new ObjectValidationResult("AutomationComposition", automationComposition.getDefinition().getName(),
- ValidationStatus.INVALID, "Commissioned automation composition definition not found"));
+ if (nodeTemplateGet.isEmpty()) {
+ result.addResult(new ObjectValidationResult("ToscaServiceTemplate", serviceTemplate.getName(),
+ ValidationStatus.INVALID, "Commissioned automation composition definition not consistent"));
} else {
+ var toscaNodeTemplate = nodeTemplateGet.get();
var acElementDefinitions = getAutomationCompositionElementDefinitions(map, toscaNodeTemplate);
// @formatter:off
@@ -354,4 +356,32 @@ 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/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
index aaa8368d7..e32735f07 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
@@ -30,16 +30,12 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionTest {
@Test
void testAutomationComposition() {
var ac0 = new AutomationComposition();
- ac0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3"));
- assertEquals("dfName", ac0.getType());
- assertEquals("1.2.3", ac0.getTypeVersion());
+ ac0.setCompositionId(UUID.randomUUID());
var ac1 = new AutomationComposition(ac0);
assertEquals(ac0, ac1);
@@ -60,7 +56,7 @@ class AutomationCompositionTest {
var ac1 = new AutomationComposition();
- ac1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
+ ac1.setCompositionId(UUID.randomUUID());
ac1.setDescription("Description");
ac1.setElements(new LinkedHashMap<>());
ac1.setName("Name");
@@ -79,7 +75,7 @@ class AutomationCompositionTest {
ac2.setElements(new LinkedHashMap<>());
// @formatter:off
- assertThatThrownBy(() -> ac2.setDefinition(null)). isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> ac2.setCompositionId(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class);
// @formatter:on
@@ -97,18 +93,5 @@ class AutomationCompositionTest {
assertNull(ac0.getElements().get(UUID.randomUUID()));
assertNull(ac1.getElements().get(UUID.randomUUID()));
-
- assertEquals(PfKey.NULL_KEY_NAME, ac0.getDefinition().getName());
-
- }
-
- private AutomationCompositionElement getAutomationCompositionElementTest(UUID uuid, ToscaConceptIdentifier id) {
- var acElement = new AutomationCompositionElement();
- acElement.setId(uuid);
- acElement.setParticipantId(id);
- acElement.setDefinition(id);
- acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
-
- return acElement;
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
index 20030e91e..7103f7f7a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
@@ -136,10 +136,10 @@ class JpaAutomationCompositionElementTest {
@Test
void testJpaAutomationCompositionElement() {
- JpaAutomationCompositionElement testJpaAutomationCompositionElement =
+ var testJpaAutomationCompositionElement =
createJpaAutomationCompositionElementInstance();
- AutomationCompositionElement ace = createAutomationCompositionElementInstance();
+ var ace = createAutomationCompositionElementInstance();
assertEquals(ace, testJpaAutomationCompositionElement.toAuthorative());
assertThatThrownBy(() -> {
@@ -149,7 +149,7 @@ class JpaAutomationCompositionElementTest {
assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null))
.isInstanceOf(NullPointerException.class);
- JpaAutomationCompositionElement testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement();
+ var testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement();
testJpaAutomationCompositionElementFa.setKey(null);
testJpaAutomationCompositionElementFa.fromAuthorative(ace);
assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
@@ -177,26 +177,26 @@ class JpaAutomationCompositionElementTest {
testJpaAutomationCompositionElement.clean();
assertEquals("A Message", testJpaAutomationCompositionElement.getDescription());
- JpaAutomationCompositionElement testJpaAutomationCompositionElement2 =
+ var testJpaAutomationCompositionElement2 =
new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElement2);
}
@Test
void testJpaAutomationCompositionElementOrderedState() throws CoderException {
- AutomationCompositionElement testAutomationCompositionElement = createAutomationCompositionElementInstance();
- JpaAutomationCompositionElement testJpaAutomationCompositionElement =
+ var testAutomationCompositionElement = createAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement =
createJpaAutomationCompositionElementInstance();
testJpaAutomationCompositionElement.setOrderedState(null);
assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative());
testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- AutomationCompositionElement noOrderedStateAce = new StandardCoder().decode(
+ var noOrderedStateAce = new StandardCoder().decode(
new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
AutomationCompositionElement.class);
- JpaAutomationCompositionElement noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
+ var noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
assertNull(noOrderedStateJpaAce.getOrderedState());
noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
@@ -205,7 +205,7 @@ class JpaAutomationCompositionElementTest {
@Test
void testJpaAutomationCompositionElementValidation() {
- JpaAutomationCompositionElement testJpaAutomationCompositionElement =
+ var testJpaAutomationCompositionElement =
createJpaAutomationCompositionElementInstance();
assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null))
@@ -216,10 +216,10 @@ class JpaAutomationCompositionElementTest {
@Test
void testJpaAutomationCompositionElementCompareTo() {
- JpaAutomationCompositionElement testJpaAutomationCompositionElement =
+ var testJpaAutomationCompositionElement =
createJpaAutomationCompositionElementInstance();
- JpaAutomationCompositionElement otherJpaAutomationCompositionElement =
+ var otherJpaAutomationCompositionElement =
new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
@@ -266,14 +266,14 @@ class JpaAutomationCompositionElementTest {
@Test
void testJpaAutomationCompositionElementLombok() {
assertNotNull(new Participant());
- JpaAutomationCompositionElement ace0 = new JpaAutomationCompositionElement();
+ var ace0 = new JpaAutomationCompositionElement();
assertThat(ace0.toString()).contains("JpaAutomationCompositionElement(");
assertThat(ace0.hashCode()).isNotZero();
assertEquals(ace0, ace0);
assertNotEquals(null, ace0);
- JpaAutomationCompositionElement ace1 = new JpaAutomationCompositionElement();
+ var ace1 = new JpaAutomationCompositionElement();
ace1.setDefinition(new PfConceptKey("defName", "0.0.1"));
ace1.setDescription("Description");
@@ -288,13 +288,13 @@ class JpaAutomationCompositionElementTest {
assertNotEquals(ace1, ace0);
- JpaAutomationCompositionElement ace2 = new JpaAutomationCompositionElement();
+ var ace2 = new JpaAutomationCompositionElement();
assertEquals(ace2, ace0);
}
private JpaAutomationCompositionElement createJpaAutomationCompositionElementInstance() {
- AutomationCompositionElement testAce = createAutomationCompositionElementInstance();
- JpaAutomationCompositionElement testJpaAutomationCompositionElement = new JpaAutomationCompositionElement();
+ var testAce = createAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = new JpaAutomationCompositionElement();
testJpaAutomationCompositionElement.setKey(null);
testJpaAutomationCompositionElement.fromAuthorative(testAce);
testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey());
@@ -304,7 +304,7 @@ class JpaAutomationCompositionElementTest {
}
private AutomationCompositionElement createAutomationCompositionElementInstance() {
- AutomationCompositionElement automationCompositionElement = new AutomationCompositionElement();
+ var automationCompositionElement = new AutomationCompositionElement();
automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
index 4dea5bd13..733ba3807 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -32,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.util.LinkedHashMap;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
@@ -40,7 +40,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Test the {@link JpaAutomationCompositionTest} class.
@@ -48,6 +47,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class JpaAutomationCompositionTest {
private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";
@Test
void testJpaAutomationCompositionConstructor() {
@@ -76,63 +76,61 @@ class JpaAutomationCompositionTest {
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, new PfConceptKey(), null, null);
+ new JpaAutomationComposition(null, "key", null, null);
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, new PfConceptKey(), null, new LinkedHashMap<>());
+ new JpaAutomationComposition(null, "key", null, new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, null);
+ new JpaAutomationComposition(null, "key", AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
+ new JpaAutomationComposition(null, "key", AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
}).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(new PfConceptKey(), null, null, null);
- }).hasMessageMatching("definition is marked .*ull but is null");
+ }).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaAutomationComposition(new PfConceptKey(), null, null, new LinkedHashMap<>());
- }).hasMessageMatching("definition is marked .*ull but is null");
+ }).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching("definition is marked .*ull but is null");
+ }).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
- }).hasMessageMatching("definition is marked .*ull but is null");
+ new LinkedHashMap<>());
+ }).hasMessageMatching("compositionId is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, null);
+ new JpaAutomationComposition(new PfConceptKey(), "key", null, null);
}).hasMessageMatching("state is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>());
+ new JpaAutomationComposition(new PfConceptKey(), "key", null, new LinkedHashMap<>());
}).hasMessageMatching("state is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(),
- AutomationCompositionState.UNINITIALISED, null);
+ new JpaAutomationComposition(new PfConceptKey(), "key", AutomationCompositionState.UNINITIALISED, null);
}).hasMessageMatching("elements is marked .*ull but is null");
assertNotNull(new JpaAutomationComposition());
assertNotNull(new JpaAutomationComposition((new PfConceptKey())));
- assertNotNull(new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(),
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()));
+ assertNotNull(new JpaAutomationComposition(new PfConceptKey(), "key", AutomationCompositionState.UNINITIALISED,
+ new LinkedHashMap<>()));
}
@Test
void testJpaAutomationComposition() {
- JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance();
+ var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
- AutomationComposition participant = createAutomationCompositionInstance();
+ var participant = createAutomationCompositionInstance();
assertEquals(participant, testJpaAutomationComposition.toAuthorative());
assertThatThrownBy(() -> {
@@ -140,9 +138,9 @@ class JpaAutomationCompositionTest {
}).hasMessageMatching("automationComposition is marked .*ull but is null");
assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
- JpaAutomationComposition testJpaAutomationCompositionFa = new JpaAutomationComposition();
+ var testJpaAutomationCompositionFa = new JpaAutomationComposition();
testJpaAutomationCompositionFa.setKey(null);
testJpaAutomationCompositionFa.fromAuthorative(participant);
assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
@@ -155,10 +153,10 @@ class JpaAutomationCompositionTest {
assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
assertEquals("automation-composition",
- new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName());
+ new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName());
assertEquals("automation-composition",
- ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0))
- .getName());
+ ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0))
+ .getName());
testJpaAutomationComposition.clean();
assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
@@ -167,58 +165,57 @@ class JpaAutomationCompositionTest {
testJpaAutomationComposition.clean();
assertEquals("A Message", testJpaAutomationComposition.getDescription());
- JpaAutomationComposition testJpaAutomationComposition2 =
- new JpaAutomationComposition(testJpaAutomationComposition);
+ var testJpaAutomationComposition2 = new JpaAutomationComposition(testJpaAutomationComposition);
assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2);
}
@Test
void testJpaAutomationCompositionElementOrderedState() throws CoderException {
- AutomationComposition testAutomationComposition = createAutomationCompositionInstance();
- JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance();
+ var testAutomationComposition = createAutomationCompositionInstance();
+ var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
testJpaAutomationComposition.setOrderedState(null);
assertEquals(testAutomationComposition, testJpaAutomationComposition.toAuthorative());
testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- AutomationComposition noOrderedStateAc = new StandardCoder().decode(
- new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"), AutomationComposition.class);
+ var noOrderedStateAc =
+ new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"),
+ AutomationComposition.class);
- JpaAutomationComposition noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
+ var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertNull(noOrderedStateJpaAc.getOrderedState());
noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc);
- AutomationCompositions automationCompositionsWithElements = new StandardCoder().decode(
- new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
+ var automationCompositionsWithElements = new StandardCoder().decode(
+ new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
- JpaAutomationComposition jpaAutomationCompositionWithElements =
- new JpaAutomationComposition(automationCompositionsWithElements.getAutomationCompositionList().get(0));
+ var jpaAutomationCompositionWithElements =
+ new JpaAutomationComposition(automationCompositionsWithElements.getAutomationCompositionList().get(0));
assertEquals(4, jpaAutomationCompositionWithElements.getElements().size());
- assertEquals(18, jpaAutomationCompositionWithElements.getKeys().size());
+ assertEquals(17, jpaAutomationCompositionWithElements.getKeys().size());
assertThatCode(jpaAutomationCompositionWithElements::clean).doesNotThrowAnyException();
assertEquals(automationCompositionsWithElements.getAutomationCompositionList().get(0),
- jpaAutomationCompositionWithElements.toAuthorative());
+ jpaAutomationCompositionWithElements.toAuthorative());
}
@Test
void testJpaAutomationCompositionValidation() {
- JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance();
+ var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
assertThatThrownBy(() -> testJpaAutomationComposition.validate(null))
- .hasMessageMatching("fieldName is marked .*ull but is null");
+ .hasMessageMatching("fieldName is marked .*ull but is null");
assertTrue(testJpaAutomationComposition.validate("").isValid());
}
@Test
void testJpaAutomationCompositionCompareTo() {
- JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance();
+ var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
- JpaAutomationComposition otherJpaAutomationComposition =
- new JpaAutomationComposition(testJpaAutomationComposition);
+ var otherJpaAutomationComposition = new JpaAutomationComposition(testJpaAutomationComposition);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
assertEquals(-1, testJpaAutomationComposition.compareTo(null));
assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition));
@@ -229,9 +226,9 @@ class JpaAutomationCompositionTest {
testJpaAutomationComposition.setKey(new PfConceptKey("automation-composition", "0.0.1"));
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ testJpaAutomationComposition.setCompositionId(UUID.randomUUID().toString());
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setDefinition(new PfConceptKey("automationCompositionDefinitionName", "0.0.1"));
+ testJpaAutomationComposition.setCompositionId(COMPOSITION_ID);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE);
@@ -260,16 +257,17 @@ class JpaAutomationCompositionTest {
@Test
void testJpaAutomationCompositionLombok() {
assertNotNull(new AutomationComposition());
- JpaAutomationComposition ac0 = new JpaAutomationComposition();
+ var ac0 = new JpaAutomationComposition();
+ ac0.setCompositionId(COMPOSITION_ID);
assertThat(ac0.toString()).contains("JpaAutomationComposition(");
assertThat(ac0.hashCode()).isNotZero();
assertEquals(ac0, ac0);
assertNotEquals(null, ac0);
- JpaAutomationComposition ac1 = new JpaAutomationComposition();
+ var ac1 = new JpaAutomationComposition();
- ac1.setDefinition(new PfConceptKey("defName", "0.0.1"));
+ ac1.setCompositionId(UUID.randomUUID().toString());
ac1.setDescription("Description");
ac1.setElements(new LinkedHashMap<>());
ac1.setKey(new PfConceptKey("participant", "0.0.1"));
@@ -282,13 +280,14 @@ class JpaAutomationCompositionTest {
assertNotEquals(ac1, ac0);
- JpaAutomationComposition ac2 = new JpaAutomationComposition();
+ var ac2 = new JpaAutomationComposition();
+ ac2.setCompositionId(COMPOSITION_ID);
assertEquals(ac2, ac0);
}
private JpaAutomationComposition createJpaAutomationCompositionInstance() {
- AutomationComposition testAutomationComposition = createAutomationCompositionInstance();
- JpaAutomationComposition testJpaAutomationComposition = new JpaAutomationComposition();
+ var testAutomationComposition = createAutomationCompositionInstance();
+ var testJpaAutomationComposition = new JpaAutomationComposition();
testJpaAutomationComposition.setKey(null);
testJpaAutomationComposition.fromAuthorative(testAutomationComposition);
testJpaAutomationComposition.setKey(PfConceptKey.getNullKey());
@@ -298,11 +297,10 @@ class JpaAutomationCompositionTest {
}
private AutomationComposition createAutomationCompositionInstance() {
- AutomationComposition testAutomationComposition = new AutomationComposition();
+ var testAutomationComposition = new AutomationComposition();
testAutomationComposition.setName("automation-composition");
testAutomationComposition.setVersion("0.0.1");
- testAutomationComposition
- .setDefinition(new ToscaConceptIdentifier("automationCompositionDefinitionName", "0.0.1"));
+ testAutomationComposition.setCompositionId(UUID.fromString(COMPOSITION_ID));
testAutomationComposition.setElements(new LinkedHashMap<>());
return testAutomationComposition;
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
index e381693ee..5be603d0d 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
@@ -23,7 +23,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.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -38,15 +37,11 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
-import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
class AutomationCompositionProviderTest {
@@ -60,7 +55,7 @@ class AutomationCompositionProviderTest {
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
- "src/test/resources/providers/TestAutomationCompositions.json";
+ "src/test/resources/providers/TestAutomationCompositions.json";
private AutomationCompositions inputAutomationCompositions;
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
@@ -70,71 +65,64 @@ class AutomationCompositionProviderTest {
void beforeSetupDao() throws Exception {
inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class);
inputAutomationCompositionsJpa =
- ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
- JpaAutomationComposition::new, "automation compositions");
+ ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
+ JpaAutomationComposition::new, "automation compositions");
}
@Test
void testAutomationCompositionsSave() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class));
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
assertThatThrownBy(() -> automationCompositionProvider.saveAutomationCompositions(null))
- .hasMessageMatching(LIST_IS_NULL);
+ .hasMessageMatching(LIST_IS_NULL);
when(automationCompositionRepository.saveAll(inputAutomationCompositionsJpa))
- .thenReturn(inputAutomationCompositionsJpa);
+ .thenReturn(inputAutomationCompositionsJpa);
var createdAutomationCompositions = new AutomationCompositions();
createdAutomationCompositions.setAutomationCompositionList(automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()));
+ .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()));
assertEquals(inputAutomationCompositions, createdAutomationCompositions);
when(automationCompositionRepository.saveAll(any())).thenThrow(IllegalArgumentException.class);
assertThatThrownBy(() -> automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()))
- .hasMessageMatching("Error in save AutomationCompositions");
+ .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()))
+ .hasMessageMatching("Error in save AutomationCompositions");
}
@Test
void testAutomationCompositionSave() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class));
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
assertThatThrownBy(() -> automationCompositionProvider.saveAutomationComposition(null))
- .hasMessageMatching(OBJECT_IS_NULL);
+ .hasMessageMatching(OBJECT_IS_NULL);
when(automationCompositionRepository.save(inputAutomationCompositionsJpa.get(0)))
- .thenReturn(inputAutomationCompositionsJpa.get(0));
+ .thenReturn(inputAutomationCompositionsJpa.get(0));
var createdAutomationComposition = automationCompositionProvider
- .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0));
+ .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0));
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition);
when(automationCompositionRepository.save(any())).thenThrow(IllegalArgumentException.class);
assertThatThrownBy(() -> automationCompositionProvider
- .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)))
- .hasMessageMatching("Error in save automationComposition");
+ .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)))
+ .hasMessageMatching("Error in save automationComposition");
}
@Test
void testGetAutomationCompositions() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class));
-
- // Return empty list when no data present in db
- List<AutomationComposition> getResponse = automationCompositionProvider.getAutomationCompositions();
- assertThat(getResponse).isEmpty();
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList());
+ .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList());
var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1);
var name = automationComposition0.getName();
@@ -142,22 +130,22 @@ class AutomationCompositionProviderTest {
var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1);
when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any()))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0),
- new JpaAutomationComposition(automationComposition1)));
+ .thenReturn(List.of(new JpaAutomationComposition(automationComposition0),
+ new JpaAutomationComposition(automationComposition1)));
when(automationCompositionRepository.findById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0)));
+ .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0)));
when(automationCompositionRepository.getById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(new JpaAutomationComposition(automationComposition0));
+ .thenReturn(new JpaAutomationComposition(automationComposition0));
when(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0)));
+ .thenReturn(List.of(new JpaAutomationComposition(automationComposition0)));
when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1)));
+ .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1)));
assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size());
var ac = automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION))
- .orElse(new AutomationComposition());
+ .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION))
+ .orElse(new AutomationComposition());
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
ac = automationCompositionProvider.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION));
@@ -166,79 +154,39 @@ class AutomationCompositionProviderTest {
when(automationCompositionRepository.getById(any())).thenThrow(EntityNotFoundException.class);
assertThatThrownBy(() -> automationCompositionProvider
- .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)))
- .hasMessageMatching("AutomationComposition not found");
+ .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)))
+ .hasMessageMatching("AutomationComposition not found");
ac = automationCompositionProvider.findAutomationComposition(ID_NAME, ID_VERSION)
- .orElse(new AutomationComposition());
+ .orElse(new AutomationComposition());
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
assertThat(automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
+ .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
when(automationCompositionRepository.findById(any())).thenThrow(IllegalArgumentException.class);
assertThatThrownBy(() -> automationCompositionProvider.findAutomationComposition(ID_NAME_NOT_VALID, ID_VERSION))
- .hasMessageMatching("Not valid parameter");
+ .hasMessageMatching("Not valid parameter");
}
@Test
void testDeleteAutomationComposition() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
- mock(ToscaNodeTemplateRepository.class));
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertThatThrownBy(() -> automationCompositionProvider
- .deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION))
- .hasMessageMatching(".*.failed, automation composition does not exist");
+ assertThatThrownBy(
+ () -> automationCompositionProvider.deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION))
+ .hasMessageMatching(".*.failed, automation composition does not exist");
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
var name = automationComposition.getName();
var version = automationComposition.getVersion();
when(automationCompositionRepository.findById(new PfConceptKey(name, version)))
- .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
AutomationComposition deletedAc = automationCompositionProvider.deleteAutomationComposition(name, version);
assertEquals(automationComposition, deletedAc);
}
-
- @Test
- void testGetNodeTemplates() {
- var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class);
- var automationCompositionProvider =
- new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository);
-
- var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION));
- var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION));
-
- when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, null, null))
- .thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1));
- when(toscaNodeTemplateRepository.findAll()).thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1));
- when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, ID_NAME, ID_VERSION))
- .thenReturn(List.of(toscaNodeTemplate0));
-
- // Getting all nodes
- var listNodes = automationCompositionProvider.getAllNodeTemplates();
- assertNotNull(listNodes);
- assertThat(listNodes).hasSize(2);
-
- listNodes = automationCompositionProvider.getNodeTemplates(ID_NAME, ID_VERSION);
- assertNotNull(listNodes);
- assertThat(listNodes).hasSize(1);
-
- listNodes = automationCompositionProvider.getAllNodeTemplates();
- assertNotNull(listNodes);
- assertThat(listNodes).hasSize(2);
-
- var nodeTemplateFilter =
- ToscaTypedEntityFilter.<ToscaNodeTemplate>builder().name(ID_NAME).version(ID_VERSION).build();
-
- listNodes = automationCompositionProvider.getFilteredNodeTemplates(nodeTemplateFilter);
- assertNotNull(listNodes);
- assertThat(listNodes).hasSize(1);
-
- assertThatThrownBy(() -> automationCompositionProvider.getFilteredNodeTemplates(null))
- .hasMessageMatching("filter is marked non-null but is null");
- }
}
diff --git a/models/src/test/resources/json/AutomationCompositionNoOrderedState.json b/models/src/test/resources/json/AutomationCompositionNoOrderedState.json
index d61a61117..e19c86c3d 100644
--- a/models/src/test/resources/json/AutomationCompositionNoOrderedState.json
+++ b/models/src/test/resources/json/AutomationCompositionNoOrderedState.json
@@ -1,8 +1,5 @@
{
- "definition": {
- "name": "automationCompositionDefinitionName",
- "version": "0.0.1"
- },
+ "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c41",
"state": "UNINITIALISED",
"orderedState": null,
"elements": [
diff --git a/models/src/test/resources/providers/TestAutomationCompositions.json b/models/src/test/resources/providers/TestAutomationCompositions.json
index 906785244..171ce07f6 100644
--- a/models/src/test/resources/providers/TestAutomationCompositions.json
+++ b/models/src/test/resources/providers/TestAutomationCompositions.json
@@ -1,10 +1,7 @@
{
"automationCompositionList": [
{
- "definition": {
- "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition",
- "version": "1.0.0"
- },
+ "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40",
"state": "UNINITIALISED",
"orderedState": "UNINITIALISED",
"elements": {
@@ -70,10 +67,7 @@
"description": "PMSH automation composition instance 0"
},
{
- "definition": {
- "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition",
- "version": "1.0.0"
- },
+ "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40",
"state": "UNINITIALISED",
"orderedState": "UNINITIALISED",
"elements": {