diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-04-05 16:32:38 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-04-11 10:06:21 +0100 |
commit | 9f1fdf9f419c1724a9cf75a20fdd24df191766bd (patch) | |
tree | 16db3d01d45ae45a4fc776d9d23596ec2c6bcc58 /models/src/test/java/org | |
parent | 2ca7552978f5389ef5ed2e5d4be3cb43e446f7c6 (diff) |
Add UseState and OperationalState support in ACM
Issue-ID: POLICY-4639
Change-Id: Iac5249c054bf41d830463826a8f61f477c48235b
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org')
4 files changed, 88 insertions, 56 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java index 8c50b01b6..95a169960 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java @@ -50,7 +50,7 @@ class AutomationCompositionDeployAckTest { // verify with all values orig.setAutomationCompositionId(UUID.randomUUID()); orig.setParticipantId(CommonTestData.getParticipantId()); - var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, + var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", true, "AutomationCompositionElement result"); final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult); orig.setAutomationCompositionResultMap(automationCompositionResultMap); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java index 711af2f81..894d67daf 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -54,6 +55,7 @@ class ParticipantStatusTest { // verify with all values var automationCompositionId = UUID.randomUUID(); + var acElementId = UUID.randomUUID(); orig.setAutomationCompositionId(automationCompositionId); var participantId = CommonTestData.getParticipantId(); orig.setParticipantId(participantId); @@ -61,7 +63,7 @@ class ParticipantStatusTest { orig.setState(ParticipantState.ON_LINE); orig.setTimestamp(Instant.ofEpochMilli(3000)); - var acInfo = getAutomationCompositionInfo(automationCompositionId); + var acInfo = getAutomationCompositionInfo(automationCompositionId, acElementId); orig.setAutomationCompositionInfoList(List.of(acInfo)); var participantDefinitionUpdate = new ParticipantDefinition(); @@ -76,12 +78,19 @@ class ParticipantStatusTest { assertSerializable(orig, ParticipantStatus.class); } - private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) { + private AutomationCompositionInfo getAutomationCompositionInfo(UUID id, UUID acElementId) { var acInfo = new AutomationCompositionInfo(); acInfo.setDeployState(DeployState.DEPLOYED); acInfo.setLockState(LockState.LOCKED); acInfo.setAutomationCompositionId(id); + var acInfoElement = new AutomationCompositionElementInfo(); + acInfoElement.setAutomationCompositionElementId(acElementId); + acInfoElement.setDeployState(DeployState.DEPLOYED); + acInfoElement.setLockState(LockState.LOCKED); + acInfoElement.setOperationalState("DEFAULT"); + acInfoElement.setUseState("IDLE"); + acInfo.getElements().add(acInfoElement); return acInfo; } 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 e9df9b7e5..2a79aee08 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 @@ -122,8 +122,13 @@ class JpaAutomationCompositionElementTest { assertEquals(ELEMENT_ID, testJpaAcElement.getElementId()); - var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement); - assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2); + var testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement); + assertEquals(testJpaAcElement, testJpaAcElement2); + + testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement.toAuthorative()); + testJpaAcElement2.setElementId(ELEMENT_ID); + testJpaAcElement2.setInstanceId(INSTANCE_ID); + assertEquals(testJpaAcElement, testJpaAcElement2); } @Test @@ -138,52 +143,60 @@ class JpaAutomationCompositionElementTest { @Test void testJpaAutomationCompositionElementCompareTo() { - var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance(); + var testJpaAcElement = createJpaAutomationCompositionElementInstance(); - var otherJpaAutomationCompositionElement = - new JpaAutomationCompositionElement(testJpaAutomationCompositionElement); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null)); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement)); + var otherJpaAcElement = + new JpaAutomationCompositionElement(testJpaAcElement); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + assertEquals(-1, testJpaAcElement.compareTo(null)); + assertEquals(0, testJpaAcElement.compareTo(testJpaAcElement)); assertNotEquals(0, - testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild())); - - testJpaAutomationCompositionElement.setElementId("BadValue"); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setElementId(ELEMENT_ID); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setInstanceId("BadValue"); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1")); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setDescription("Description"); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setDescription(null); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - testJpaAutomationCompositionElement.setLockState(LockState.UNLOCKED); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setLockState(LockState.LOCKED); - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - testJpaAutomationCompositionElement.setParticipantId(UUID.randomUUID().toString()); - assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); - - assertEquals(testJpaAutomationCompositionElement, - new JpaAutomationCompositionElement(testJpaAutomationCompositionElement)); + testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild())); + + testJpaAcElement.setElementId("BadValue"); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setElementId(ELEMENT_ID); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setInstanceId("BadValue"); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setInstanceId(INSTANCE_ID); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setDefinition(new PfConceptKey("aceDef", "0.0.1")); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setDescription("Description"); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setDescription(null); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setDeployState(DeployState.DEPLOYED); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setDeployState(DeployState.UNDEPLOYED); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setLockState(LockState.UNLOCKED); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setLockState(LockState.LOCKED); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setUseState("BadValue"); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setUseState("IDLE"); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setOperationalState("BadValue"); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + testJpaAcElement.setOperationalState("DEFAULT"); + assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + testJpaAcElement.setParticipantId(UUID.randomUUID().toString()); + assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); + + assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement)); } @Test @@ -229,6 +242,8 @@ class JpaAutomationCompositionElementTest { automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1")); automationCompositionElement.setParticipantId(CommonTestData.getParticipantId()); automationCompositionElement.setProperties(Map.of("key", "{}")); + automationCompositionElement.setUseState("IDLE"); + automationCompositionElement.setOperationalState("DEFAULT"); return automationCompositionElement; } 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 ba1e33c27..0991c1bd0 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 @@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; 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.AutomationCompositionElementRepository; import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -64,7 +65,8 @@ class AutomationCompositionProviderTest { @Test void testAutomationCompositionCreate() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); when(automationCompositionRepository.save(any(JpaAutomationComposition.class))) .thenReturn(inputAutomationCompositionsJpa.get(0)); @@ -78,7 +80,8 @@ class AutomationCompositionProviderTest { @Test void testAutomationCompositionUpdate() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); assertThatThrownBy(() -> automationCompositionProvider.updateAutomationComposition(null)) .hasMessageMatching(OBJECT_IS_NULL); @@ -95,7 +98,8 @@ class AutomationCompositionProviderTest { @Test void testGetAutomationCompositions() throws Exception { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(), @@ -112,7 +116,8 @@ class AutomationCompositionProviderTest { @Test void testGetAutomationComposition() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); assertThatThrownBy( @@ -128,7 +133,8 @@ class AutomationCompositionProviderTest { @Test void testFindAutomationComposition() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId()); @@ -151,7 +157,8 @@ class AutomationCompositionProviderTest { @Test void testGetAcInstancesByCompositionId() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); when(automationCompositionRepository.findByCompositionId(automationComposition.getCompositionId().toString())) @@ -164,7 +171,8 @@ class AutomationCompositionProviderTest { @Test void testDeleteAutomationComposition() { var automationCompositionRepository = mock(AutomationCompositionRepository.class); - var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(AutomationCompositionElementRepository.class)); assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationComposition(UUID.randomUUID())) .hasMessageMatching(".*.failed, automation composition does not exist"); |