aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java3
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java10
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java39
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java42
4 files changed, 45 insertions, 49 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
index a843c8279..1a7a419d6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
class ParticipantInformationTest {
@@ -33,8 +32,6 @@ class ParticipantInformationTest {
void testCopyConstructor() {
var participant = new Participant();
participant.setParticipantId(UUID.randomUUID());
- participant.setParticipantState(ParticipantState.ON_LINE);
- participant.setLastMsg(TimestampHelper.now());
participant.setParticipantSupportedElementTypes(new HashMap<>());
var participantInfo1 = new ParticipantInformation();
participantInfo1.setParticipant(participant);
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 7486d0d70..2c6c60edc 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.models.acm.concepts;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -46,7 +45,6 @@ class ParticipantTest {
var p1 = new Participant();
p1.setParticipantId(CommonTestData.getParticipantId());
- p1.setParticipantState(ParticipantState.ON_LINE);
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
@@ -56,11 +54,6 @@ class ParticipantTest {
assertNotEquals(p1, p0);
var p2 = new Participant();
-
- // @formatter:off
- assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
- // @formatter:on
-
assertEquals(p2, p0);
}
@@ -68,7 +61,6 @@ class ParticipantTest {
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");
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
index e0f2f55c1..d2d253e06 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
@@ -27,15 +27,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.sql.Timestamp;
-import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
/**
* Test the {@link JpaParticipant} class.
@@ -47,30 +43,23 @@ class JpaParticipantTest {
@Test
void testJpaParticipantConstructor() {
assertThatThrownBy(() -> new JpaParticipant((Participant) null))
- .hasMessageMatching("authorativeConcept is marked .*ull but is null");
+ .hasMessageMatching("authorativeConcept is marked .*ull but is null");
assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null))
.hasMessageMatching("copyConcept is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(null, ParticipantState.ON_LINE,
- new ArrayList<>(), new ArrayList<>()))
+ assertThatThrownBy(() -> new JpaParticipant(null, new ArrayList<>(), new ArrayList<>()))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null,
- new ArrayList<>(), new ArrayList<>()))
- .hasMessageMatching("participantState is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE,
- null, new ArrayList<>()))
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null, new ArrayList<>()))
.hasMessageMatching("supportedElements is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE,
- new ArrayList<>(), null))
- .hasMessageMatching("replicas is marked .*ull but is null");
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), new ArrayList<>(), null))
+ .hasMessageMatching("replicas is marked .*ull but is null");
assertDoesNotThrow(() -> new JpaParticipant());
assertDoesNotThrow(() -> new JpaParticipant(UUID.randomUUID().toString(),
- ParticipantState.ON_LINE, new ArrayList<>(), new ArrayList<>()));
+ new ArrayList<>(), new ArrayList<>()));
}
@Test
@@ -116,18 +105,6 @@ class JpaParticipantTest {
assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant));
assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild()));
- testJpaParticipant.setParticipantState(ParticipantState.OFF_LINE);
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setParticipantState(ParticipantState.ON_LINE);
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
-
- testJpaParticipant.setLastMsg(Timestamp.from(Instant.EPOCH));
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setLastMsg(otherJpaParticipant.getLastMsg());
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
-
var newJpaParticipant = new JpaParticipant(testJpaParticipant);
newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, newJpaParticipant);
@@ -143,8 +120,6 @@ class JpaParticipantTest {
var p1 = new JpaParticipant();
- p1.setParticipantState(ParticipantState.ON_LINE);
-
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
assertNotEquals(p1, p0);
@@ -154,14 +129,12 @@ class JpaParticipantTest {
var p2 = new JpaParticipant();
p2.setParticipantId(p0.getParticipantId());
- p2.setLastMsg(p0.getLastMsg());
assertEquals(p2, p0);
}
private Participant createParticipantInstance() {
var testParticipant = new Participant();
testParticipant.setParticipantId(UUID.randomUUID());
- testParticipant.setLastMsg(TimestampHelper.now());
testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>());
testParticipant.setReplicas(new LinkedHashMap<>());
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index a5c93e86a..024060f0a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -37,7 +37,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
@@ -45,6 +47,7 @@ import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplat
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -276,9 +279,7 @@ class AcmUtilsTest {
}
private Map<String, ToscaPolicyType> getDummyPolicyTypesMap() {
- Map<String, ToscaPolicyType> policyTypes = new HashMap<>();
- policyTypes.put("onap.policies.Match", new ToscaPolicyType());
- return policyTypes;
+ return Map.of("onap.policies.Match", new ToscaPolicyType());
}
private Map<String, ToscaDataType> getDummyToscaDataTypeMap() {
@@ -290,12 +291,45 @@ class AcmUtilsTest {
private Map<String, ToscaNodeTemplate> getDummyNodeTemplates() {
Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
var nodeTemplate = new ToscaNodeTemplate();
- nodeTemplate.setType("org.onap.policy.clamp.acm.AutomationCompositionElement");
+ nodeTemplate.setType(AUTOMATION_COMPOSITION_ELEMENT);
nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate);
return nodeTemplates;
}
@Test
+ void testcreateAcRestart() {
+ var automationComposition = getDummyAutomationComposition();
+ automationComposition.setInstanceId(UUID.randomUUID());
+ var toscaServiceTemplate = getDummyToscaServiceTemplate();
+ var participantId = automationComposition.getElements().values().iterator().next().getParticipantId();
+ var serviceTemplateFragment = AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate);
+ var result = AcmUtils.createAcRestart(automationComposition, participantId, serviceTemplateFragment);
+ assertEquals(result.getAutomationCompositionId(), automationComposition.getInstanceId());
+ assertThat(result.getAcElementList()).hasSize(1);
+ }
+
+ @Test
+ void testPrepareParticipantRestarting() {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setElementStateMap(Map.of());
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, AUTOMATION_COMPOSITION_ELEMENT);
+ acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
+ acmDefinition.getElementStateMap()
+ .values().forEach(element -> element.setParticipantId(UUID.randomUUID()));
+ var participantId = UUID.randomUUID();
+ var result = AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
+ AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(result).isEmpty();
+
+ participantId = acmDefinition.getElementStateMap().values().iterator().next().getParticipantId();
+ result = AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
+ AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(result).hasSize(1);
+ }
+
+ @Test
void testRecursiveMergeMap() {
var oldProperties = """
chart: