diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-09-26 14:31:58 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-09-26 13:34:28 +0000 |
commit | 54155ebf6232417d264159acf9fbfcdc08c11244 (patch) | |
tree | 60bbe3a27a5468a8d69b9ebe99f0534e05f66ff6 /models/src/test/java/org/onap | |
parent | 4407ea6948a060734a4f2836b11bd2d5c6ea6194 (diff) |
Add migration message support
Issue-ID: POLICY-4822
Change-Id: Ibde7c14424c63a96c64378d8897e8887935d6c79
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org/onap')
-rwxr-xr-x[-rw-r--r--] | models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java | 160 | ||||
-rwxr-xr-x[-rw-r--r--] | models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java | 17 |
2 files changed, 100 insertions, 77 deletions
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 04a874419..697b4e148 100644..100755 --- 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 @@ -62,28 +62,28 @@ class JpaAutomationCompositionTest { }).hasMessageMatching(NULL_INSTANCE_ID_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(), - DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(), DeployState.UNDEPLOYED, + LockState.LOCKED); }).hasMessageMatching("key" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null, - new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null, new ArrayList<>(), + DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - null, DeployState.UNDEPLOYED, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null, + DeployState.UNDEPLOYED, LockState.LOCKED); }).hasMessageMatching("elements" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - new ArrayList<>(), null, LockState.LOCKED); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), new ArrayList<>(), + null, LockState.LOCKED); }).hasMessageMatching("deployState" + NULL_TEXT_ERROR); assertThatThrownBy(() -> { - new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), - new ArrayList<>(), DeployState.UNDEPLOYED, null); + new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), new ArrayList<>(), + DeployState.UNDEPLOYED, null); }).hasMessageMatching("lockState" + NULL_TEXT_ERROR); assertNotNull(new JpaAutomationComposition()); @@ -93,29 +93,34 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationComposition() { - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + var jpaAutomationComposition = createJpaAutomationCompositionInstance(); + + var automationComposition = createAutomationCompositionInstance(); + assertEquals(automationComposition, jpaAutomationComposition.toAuthorative()); - var participant = createAutomationCompositionInstance(); - assertEquals(participant, testJpaAutomationComposition.toAuthorative()); + var target = UUID.randomUUID(); + jpaAutomationComposition.setCompositionTargetId(target.toString()); + automationComposition.setCompositionTargetId(target); + assertEquals(automationComposition, jpaAutomationComposition.toAuthorative()); assertThatThrownBy(() -> { - testJpaAutomationComposition.fromAuthorative(null); + jpaAutomationComposition.fromAuthorative(null); }).hasMessageMatching("automationComposition is marked .*ull but is null"); assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null)) .isInstanceOf(NullPointerException.class); - var testJpaAutomationCompositionFa = new JpaAutomationComposition(); - testJpaAutomationCompositionFa.setInstanceId(null); - testJpaAutomationCompositionFa.fromAuthorative(participant); - assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + var jpaAutomationCompositionFa = new JpaAutomationComposition(); + jpaAutomationCompositionFa.setInstanceId(null); + jpaAutomationCompositionFa.fromAuthorative(automationComposition); + assertEquals(jpaAutomationComposition, jpaAutomationCompositionFa); - assertEquals("automation-composition", testJpaAutomationComposition.getName()); + assertEquals("automation-composition", jpaAutomationComposition.getName()); assertEquals("automation-composition", new JpaAutomationComposition(createAutomationCompositionInstance()).getName()); - var testJpaAutomationComposition2 = new JpaAutomationComposition(testJpaAutomationComposition); - assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2); + var jpaAutomationComposition2 = new JpaAutomationComposition(jpaAutomationComposition); + assertEquals(jpaAutomationComposition, jpaAutomationComposition2); } @Test @@ -130,60 +135,65 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationCompositionCompareTo() { - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); - - var otherJpaAutomationComposition = new JpaAutomationComposition(testJpaAutomationComposition); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - assertEquals(-1, testJpaAutomationComposition.compareTo(null)); - assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition)); - assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); - - testJpaAutomationComposition.setInstanceId("BadValue"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setInstanceId(INSTANCE_ID); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setCompositionId(UUID.randomUUID().toString()); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setCompositionId(COMPOSITION_ID); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setName("BadValue"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setName("automation-composition"); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setVersion("0.0.0"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setVersion("0.0.1"); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setDeployState(DeployState.DEPLOYED); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setLockState(LockState.UNLOCKED); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setLockState(LockState.NONE); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setDescription("A description"); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setDescription(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setRestarting(true); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setRestarting(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - testJpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - testJpaAutomationComposition.setStateChangeResult(null); - assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); - - assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition)); + var jpaAutomationComposition = createJpaAutomationCompositionInstance(); + + var otherJpaAutomationComposition = new JpaAutomationComposition(jpaAutomationComposition); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + assertEquals(-1, jpaAutomationComposition.compareTo(null)); + assertEquals(0, jpaAutomationComposition.compareTo(jpaAutomationComposition)); + assertNotEquals(0, jpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); + + jpaAutomationComposition.setInstanceId("BadValue"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setInstanceId(INSTANCE_ID); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setCompositionId(UUID.randomUUID().toString()); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setCompositionId(COMPOSITION_ID); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setCompositionTargetId(UUID.randomUUID().toString()); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setCompositionTargetId(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setName("BadValue"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setName("automation-composition"); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setVersion("0.0.0"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setVersion("0.0.1"); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setDeployState(DeployState.DEPLOYED); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setLockState(LockState.UNLOCKED); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setLockState(LockState.NONE); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setDescription("A description"); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setDescription(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setRestarting(true); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setRestarting(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setStateChangeResult(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + assertEquals(jpaAutomationComposition, new JpaAutomationComposition(jpaAutomationComposition)); } @Test 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 a9bd25f81..e0e5a2edc 100644..100755 --- 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 @@ -68,6 +68,7 @@ class AcmUtilsTest { assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.UNLOCKING)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.DELETING, LockState.NONE)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.UPDATING, LockState.LOCKED)).isTrue(); + assertThat(AcmUtils.isInTransitionalState(DeployState.MIGRATING, LockState.LOCKED)).isTrue(); } @Test @@ -195,6 +196,18 @@ class AcmUtilsTest { } @Test + void testCreateAcElementDeployList() { + var automationComposition = getDummyAutomationComposition(); + var result = AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.DEPLOY); + assertThat(result).hasSameSizeAs(automationComposition.getElements().values()); + for (var participantDeploy : result) { + for (var element : participantDeploy.getAcElementList()) { + assertEquals(DeployOrder.DEPLOY, element.getOrderedState()); + } + } + } + + @Test void testCreateAcElementRestart() { var element = getDummyAutomationComposition().getElements().values().iterator().next(); var result = AcmUtils.createAcElementRestart(element); @@ -210,8 +223,8 @@ class AcmUtilsTest { Map<UUID, AutomationCompositionElement> map = new LinkedHashMap<>(); try { var element = new StandardCoder().decode( - new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), - AutomationCompositionElement.class); + new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), + AutomationCompositionElement.class); map.put(UUID.randomUUID(), element); } catch (Exception e) { fail("Cannot read or decode " + e.getMessage()); |