summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java16
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java54
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java10
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java40
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java103
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java22
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java47
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java41
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java23
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java15
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java102
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java22
13 files changed, 445 insertions, 56 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
index 9c65b1eff..a8c069723 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 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,11 +20,14 @@
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.HashMap;
+import java.util.Map;
import java.util.UUID;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@NoArgsConstructor
@@ -38,6 +41,13 @@ public class AutomationCompositionDefinition {
@NonNull
private ToscaServiceTemplate serviceTemplate;
+ @NonNull
+ private AcTypeState state;
+
+ @NonNull
+ // Map used to store prime state with key as NodeTemplate Name and value as NodeTemplateState
+ private Map<String, NodeTemplateState> elementStateMap = new HashMap<>();
+
/**
* Copy contructor, does a deep copy.
*
@@ -45,6 +55,8 @@ public class AutomationCompositionDefinition {
*/
public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) {
this.compositionId = otherAcmDefinition.compositionId;
- this.serviceTemplate = otherAcmDefinition.serviceTemplate;
+ this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate);
+ this.state = otherAcmDefinition.state;
+ this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
new file mode 100644
index 000000000..5d28cd736
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.concepts;
+
+import java.util.UUID;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+@NoArgsConstructor
+@Data
+@EqualsAndHashCode
+public class NodeTemplateState {
+
+ private UUID nodeTemplateStateId;
+
+ // participantId assigned to this element
+ private UUID participantId;
+
+ private ToscaConceptIdentifier nodeTemplateId;
+
+ private AcTypeState state;
+
+ /**
+ * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
+ *
+ * @param copyConstructor the NodeTemplateState to copy from
+ */
+ public NodeTemplateState(NodeTemplateState copyConstructor) {
+ this.nodeTemplateStateId = copyConstructor.nodeTemplateStateId;
+ this.participantId = copyConstructor.participantId;
+ this.nodeTemplateId = new ToscaConceptIdentifier(copyConstructor.nodeTemplateId);
+ this.state = copyConstructor.state;
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
index 4741bafca..8503516a1 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
@@ -20,12 +20,14 @@
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
@@ -46,7 +48,7 @@ public class Participant {
private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier();
@NonNull
- private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes;
+ private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>();
/**
* Copy constructor.
@@ -57,5 +59,7 @@ public class Participant {
this.participantState = otherParticipant.participantState;
this.participantType = otherParticipant.participantType;
this.participantId = otherParticipant.participantId;
+ this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(),
+ ParticipantSupportedElementType::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java
index 310577167..68d50010c 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantSupportedElementType.java
@@ -21,16 +21,14 @@
package org.onap.policy.clamp.models.acm.concepts;
import java.util.UUID;
-import lombok.Getter;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
-import lombok.Setter;
import org.onap.policy.common.parameters.annotations.NotNull;
-import org.springframework.validation.annotation.Validated;
@NoArgsConstructor
-@Getter
-@Setter
-@Validated
+@Data
+@EqualsAndHashCode
public class ParticipantSupportedElementType {
@NotNull
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 c46bdb96c..fcaa6e6db 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 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,17 +20,26 @@
package org.onap.policy.clamp.models.acm.persistence.concepts;
+import java.util.HashSet;
+import java.util.Set;
import java.util.UUID;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
import javax.persistence.Lob;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
@@ -55,12 +64,22 @@ public class JpaAutomationCompositionDefinition extends Validated
@NotNull
private String compositionId;
+ @Column
@NotNull
private String name;
+ @Column
@NotNull
private String version;
+ @Column
+ @NotNull
+ private AcTypeState state;
+
+ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+ @JoinColumn(name = "compositionId", foreignKey = @ForeignKey(name = "dt_element_fk"))
+ private Set<JpaNodeTemplateState> elements = new HashSet<>();
+
@Lob
@Convert(converter = StringToServiceTemplateConverter.class)
@NotNull
@@ -72,15 +91,26 @@ public class JpaAutomationCompositionDefinition extends Validated
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.fromString(compositionId));
acmDefinition.setServiceTemplate(serviceTemplate.toAuthorative());
+ for (var element : this.elements) {
+ var key = element.getNodeTemplateId().getName();
+ acmDefinition.getElementStateMap().put(key, element.toAuthorative());
+ }
return acmDefinition;
}
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
- compositionId = copyConcept.getCompositionId().toString();
- serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
- setName(serviceTemplate.getName());
- setVersion(serviceTemplate.getVersion());
+ this.compositionId = copyConcept.getCompositionId().toString();
+ this.state = copyConcept.getState();
+ this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
+ setName(this.serviceTemplate.getName());
+ setVersion(this.serviceTemplate.getVersion());
+ elements = new HashSet<>(copyConcept.getElementStateMap().size());
+ for (var element : copyConcept.getElementStateMap().values()) {
+ var nodeTemplateStateId = element.getNodeTemplateStateId().toString();
+ var jpaNodeTemplateState = new JpaNodeTemplateState(nodeTemplateStateId, this.compositionId);
+ jpaNodeTemplateState.fromAuthorative(element);
+ }
}
public JpaAutomationCompositionDefinition(final AutomationCompositionDefinition acmDefinition) {
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
new file mode 100644
index 000000000..a6d13a638
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.concepts;
+
+import java.util.UUID;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.base.PfAuthorative;
+import org.onap.policy.models.base.Validated;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+@Entity
+@Table(name = "NodeTemplateState")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class JpaNodeTemplateState extends Validated implements PfAuthorative<NodeTemplateState> {
+
+ @Id
+ @NotNull
+ private String nodeTemplateStateId;
+
+ @Column
+ @NotNull
+ private String compositionId;
+
+ @Column
+ private String participantId;
+
+ @Column
+ @NotNull
+ private ToscaConceptIdentifier nodeTemplateId;
+
+ @Column
+ @NotNull
+ private AcTypeState state;
+
+ /**
+ * The Default Constructor.
+ */
+ public JpaNodeTemplateState() {
+ this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param nodeTemplateStateId the nodeTemplateStateId
+ * @param compositionId the compositionId
+ */
+ public JpaNodeTemplateState(@NotNull String nodeTemplateStateId, @NotNull String compositionId) {
+ this.nodeTemplateStateId = nodeTemplateStateId;
+ this.compositionId = compositionId;
+ }
+
+ @Override
+ public void fromAuthorative(NodeTemplateState copyConcept) {
+ this.nodeTemplateStateId = copyConcept.getNodeTemplateStateId().toString();
+ if (copyConcept.getParticipantId() != null) {
+ this.participantId = copyConcept.getParticipantId().toString();
+ }
+ this.nodeTemplateId = copyConcept.getNodeTemplateId();
+ }
+
+ @Override
+ public NodeTemplateState toAuthorative() {
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateStateId(UUID.fromString(this.nodeTemplateStateId));
+ if (this.participantId != null) {
+ nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
+ }
+ nodeTemplateState.setNodeTemplateId(this.nodeTemplateId);
+ nodeTemplateState.setState(this.state);
+ return nodeTemplateState;
+ }
+}
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 054271512..3757f6c7b 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ 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.AcTypeState;
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;
@@ -55,6 +56,7 @@ public class AcDefinitionProvider {
var acmDefinition = new AutomationCompositionDefinition();
var compositionId = UUID.randomUUID();
acmDefinition.setCompositionId(compositionId);
+ acmDefinition.setState(AcTypeState.COMMISSIONED);
if (serviceTemplate.getMetadata() == null) {
serviceTemplate.setMetadata(new HashMap<>());
}
@@ -68,7 +70,7 @@ public class AcDefinitionProvider {
}
/**
- * Update the ServiceTemplate.
+ * Update a commissioned ServiceTemplate.
*
* @param compositionId The UUID of the automation composition definition to delete
* @param serviceTemplate the service template to be created
@@ -76,8 +78,18 @@ public class AcDefinitionProvider {
public void updateServiceTemplate(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(compositionId);
+ acmDefinition.setState(AcTypeState.COMMISSIONED);
acmDefinition.setServiceTemplate(serviceTemplate);
- var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
+ updateAcDefinition(acmDefinition);
+ }
+
+ /**
+ * Update the AutomationCompositionDefinition.
+ *
+ * @param acDefinition the AutomationCompositionDefinition to be updated
+ */
+ public void updateAcDefinition(AutomationCompositionDefinition acDefinition) {
+ var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acDefinition, JpaAutomationCompositionDefinition::new,
"AutomationCompositionDefinition");
acmDefinitionRepository.save(jpaAcmDefinition);
}
@@ -108,14 +120,14 @@ public class AcDefinitionProvider {
* @return the automation composition definition
*/
@Transactional(readOnly = true)
- public ToscaServiceTemplate getAcDefinition(UUID compositionId) {
+ public AutomationCompositionDefinition getAcDefinition(UUID compositionId) {
var jpaGet = acmDefinitionRepository.findById(compositionId.toString());
if (jpaGet.isEmpty()) {
String errorMessage =
"Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist";
throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage);
}
- return jpaGet.get().getServiceTemplate().toAuthorative();
+ return jpaGet.get().toAuthorative();
}
/**
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java
new file mode 100644
index 000000000..aa084b4f2
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.concepts;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class AutomationCompositionDefinitionTest {
+
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
+
+ @Test
+ void testCopyContructor() {
+ var acDefinition = new AutomationCompositionDefinition();
+ acDefinition.setCompositionId(UUID.randomUUID());
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier());
+ acDefinition.setElementStateMap(Map.of("key", nodeTemplateState));
+ acDefinition.setServiceTemplate(CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
+ acDefinition.setState(AcTypeState.COMMISSIONED);
+ var result = new AutomationCompositionDefinition(acDefinition);
+ assertEquals(result, acDefinition);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java
new file mode 100644
index 000000000..a850c88dc
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.concepts;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class NodeTemplateStateTest {
+
+ @Test
+ void testCopyContructor() {
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier());
+ nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
+ nodeTemplateState.setParticipantId(UUID.randomUUID());
+ nodeTemplateState.setState(AcTypeState.COMMISSIONED);
+ var result = new NodeTemplateState(nodeTemplateState);
+ assertEquals(result, nodeTemplateState);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
index 0ae1a90e2..c6af96742 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
@@ -26,6 +26,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import java.util.Map;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
@@ -34,7 +36,7 @@ class ParticipantTest {
@Test
void testParticipantLombok() {
assertNotNull(new Participant());
- Participant p0 = new Participant();
+ var p0 = new Participant();
assertThat(p0.toString()).contains("Participant(");
assertThat(p0.hashCode()).isNotZero();
@@ -42,7 +44,7 @@ class ParticipantTest {
assertNotEquals(null, p0);
- Participant p1 = new Participant();
+ var p1 = new Participant();
p1.setParticipantId(CommonTestData.getParticipantId());
p1.setParticipantState(ParticipantState.ON_LINE);
@@ -54,7 +56,7 @@ class ParticipantTest {
assertNotEquals(p1, p0);
- Participant p2 = new Participant();
+ var p2 = new Participant();
// @formatter:off
assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
@@ -62,4 +64,19 @@ class ParticipantTest {
assertEquals(p2, p0);
}
+
+ @Test
+ void testCopyConstructor() {
+ var p0 = new Participant();
+ p0.setParticipantId(UUID.randomUUID());
+ p0.setParticipantState(ParticipantState.ON_LINE);
+ var supportedElementType = new ParticipantSupportedElementType();
+ supportedElementType.setId(UUID.randomUUID());
+ supportedElementType.setTypeName("type");
+ supportedElementType.setTypeVersion("1.0.0");
+ p0.setParticipantSupportedElementTypes(Map.of(supportedElementType.getId(), supportedElementType));
+
+ var p2 = new Participant(p0);
+ assertEquals(p2, p0);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
index fac98043d..5a82466d6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
@@ -31,16 +31,15 @@ import org.junit.jupiter.api.Test;
public class ParticipantsSupportedElementTypesTest {
private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
- private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
@Test
void testParticipant() {
- ParticipantSupportedElementType p0 = new ParticipantSupportedElementType();
+ var p0 = new ParticipantSupportedElementType();
p0.setId(UUID.fromString(ID));
assertEquals(ID, p0.getId().toString());
- ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(p0);
+ var p1 = new ParticipantSupportedElementType(p0);
assertThat(p0).usingRecursiveComparison().isEqualTo(p1);
}
@@ -48,27 +47,27 @@ public class ParticipantsSupportedElementTypesTest {
@Test
void testParticipantLombok() {
assertNotNull(new ParticipantSupportedElementType());
- ParticipantSupportedElementType p0 = new ParticipantSupportedElementType();
+ var p0 = new ParticipantSupportedElementType();
- assertThat(p0.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType");
+ assertThat(p0.toString()).contains("ParticipantSupportedElementType");
assertThat(p0.hashCode()).isNotZero();
assertThat(p0).usingRecursiveComparison().isEqualTo(new ParticipantSupportedElementType(p0));
assertNotEquals(null, p0);
- ParticipantSupportedElementType p1 = new ParticipantSupportedElementType();
+ var p1 = new ParticipantSupportedElementType();
p1.setId(UUID.fromString(ID));
p1.setTypeName("name");
p1.setTypeVersion("1.0.0");
- assertThat(p1.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType");
+ assertThat(p1.toString()).contains("ParticipantSupportedElementType");
assertNotEquals(0, p1.hashCode());
assertNotEquals(p1, p0);
assertNotEquals(null, p1);
- ParticipantSupportedElementType p2 = new ParticipantSupportedElementType();
+ var p2 = new ParticipantSupportedElementType();
p2.setId(p0.getId());
assertThat(p0).usingRecursiveComparison().isEqualTo(p2);
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 59e3767d1..a27a74be4 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,24 +22,26 @@ 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.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
+import java.util.Map;
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.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
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.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardYamlCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.data.domain.Example;
@@ -49,19 +51,17 @@ class AcDefinitionProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP =
"clamp/acm/test/tosca-template-additional-properties.yaml";
- private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
-
private static ToscaServiceTemplate inputServiceTemplate;
@BeforeAll
static void loadServiceTemplate() {
- inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ inputServiceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
}
@Test
void testDocCopyCompare() {
- var inputServiceTemplateProperties = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
+ var inputServiceTemplateProperties = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties);
var docServiceTemplateCopy = new DocToscaServiceTemplate(docServiceTemplate);
@@ -71,8 +71,8 @@ class AcDefinitionProviderTest {
var acmDefinition = getAcDefinition(docServiceTemplate);
var acmDefinitionCopy = getAcDefinition(docServiceTemplateCopy);
- assertThat(acmDefinition.getServiceTemplate().getName()).isEqualTo(
- acmDefinitionCopy.getServiceTemplate().getName());
+ assertThat(acmDefinition.getServiceTemplate().getName())
+ .isEqualTo(acmDefinitionCopy.getServiceTemplate().getName());
}
@@ -92,6 +92,65 @@ class AcDefinitionProviderTest {
}
@Test
+ void testUpdateServiceTemplate() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ acDefinitionProvider.updateServiceTemplate(UUID.randomUUID(), inputServiceTemplate);
+ verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class));
+ }
+
+ @Test
+ void testUpdateAcDefinition() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate));
+ acDefinitionProvider.updateAcDefinition(acmDefinition);
+ verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class));
+ }
+
+ @Test
+ void testGetAcDefinition() {
+ var jpa = new JpaAutomationCompositionDefinition();
+ jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa));
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var result = acDefinitionProvider.getAcDefinition(UUID.fromString(jpa.getCompositionId()));
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ void testGetAcDefinitionNotFound() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var compositionId = UUID.randomUUID();
+ assertThatThrownBy(() -> acDefinitionProvider.getAcDefinition(compositionId))
+ .hasMessage("Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist");
+ }
+
+ @Test
+ void testFindAcDefinition() {
+ var jpa = new JpaAutomationCompositionDefinition();
+ jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa));
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var result = acDefinitionProvider.findAcDefinition(UUID.fromString(jpa.getCompositionId()));
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ void testGetAllAcDefinitions() {
+ var jpa = new JpaAutomationCompositionDefinition();
+ jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ when(acmDefinitionRepository.findAll()).thenReturn(List.of(jpa));
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var result = acDefinitionProvider.getAllAcDefinitions();
+ assertThat(result).hasSize(1);
+ }
+
+ @Test
void testDeleteAcDefintion() {
var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
var acmDefinition = getAcDefinition(docServiceTemplate);
@@ -135,22 +194,13 @@ class AcDefinitionProviderTest {
private AutomationCompositionDefinition getAcDefinition(DocToscaServiceTemplate docServiceTemplate) {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setState(AcTypeState.COMMISSIONED);
acmDefinition.setServiceTemplate(docServiceTemplate.toAuthorative());
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0"));
+ nodeTemplateState.setState(AcTypeState.COMMISSIONED);
+ acmDefinition.setElementStateMap(Map.of(nodeTemplateState.getNodeTemplateId().getName(), nodeTemplateState));
return acmDefinition;
}
-
- /**
- * Get ToscaServiceTemplate from resource.
- *
- * @param path path of the resource
- */
- public static ToscaServiceTemplate getToscaServiceTemplate(String path) {
-
- try {
- return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class);
- } catch (CoderException e) {
- fail("Cannot read or decode " + path);
- return null;
- }
- }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
index 88ace1706..21666e484 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
@@ -20,7 +20,13 @@
package org.onap.policy.clamp.models.acm.utils;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.UUID;
+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.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Class to hold/create all parameters for test cases.
@@ -29,6 +35,8 @@ import java.util.UUID;
public class CommonTestData {
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
+
/**
* Returns participantId for test cases.
@@ -56,4 +64,18 @@ public class CommonTestData {
public static UUID getRndParticipantId() {
return UUID.randomUUID();
}
+
+ /**
+ * Get ToscaServiceTemplate from resource.
+ *
+ * @param path path of the resource
+ */
+ public static ToscaServiceTemplate getToscaServiceTemplate(String path) {
+ try {
+ return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class);
+ } catch (CoderException e) {
+ fail("Cannot read or decode " + path);
+ return null;
+ }
+ }
}