From 467f0dbfe26a864a607286aab6d22c96e075bd17 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Thu, 19 Jan 2023 10:08:35 +0000 Subject: Refactor AcInstanceState Update on ACM Create AcInstanceStateResolver that will be used to Handle Deployment, Undeployment, Locking and Unlocking. Issue-ID: POLICY-4526 Change-Id: I9a7beb57dba9e9ea334974d63c1063acde7c977d Signed-off-by: FrancescoFioraEst --- .../provider/AcInstanceStateResolverTest.java | 65 ++++++++++++++++++++++ .../models/acm/utils/StateDefinitionTest.java | 50 +++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/utils/StateDefinitionTest.java (limited to 'models/src/test/java/org/onap') diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java new file mode 100644 index 000000000..103bca2ec --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.provider; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; + +class AcInstanceStateResolverTest { + + @Test + void testResolve() { + var acTypeStateResolver = new AcInstanceStateResolver(); + var result = + acTypeStateResolver.resolve(DeployOrder.DEPLOY, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE); + assertThat(result).isEqualTo(AcInstanceStateResolver.DEPLOY); + result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYED, + LockState.LOCKED); + assertThat(result).isEqualTo(AcInstanceStateResolver.UNDEPLOY); + result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.DEPLOYED, + LockState.LOCKED); + assertThat(result).isEqualTo(AcInstanceStateResolver.UNLOCK); + result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.LOCK, DeployState.DEPLOYED, + LockState.UNLOCKED); + assertThat(result).isEqualTo(AcInstanceStateResolver.LOCK); + + result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE); + assertThat(result).isEqualTo(AcInstanceStateResolver.NONE); + result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.UNLOCK, DeployState.DEPLOYED, + LockState.LOCKED); + assertThat(result).isEqualTo(AcInstanceStateResolver.NONE); + result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.UNDEPLOYED, + LockState.NONE); + assertThat(result).isEqualTo(AcInstanceStateResolver.NONE); + result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYING, + LockState.NONE); + assertThat(result).isEqualTo(AcInstanceStateResolver.NONE); + + result = acTypeStateResolver.resolve(null, null, null, null); + assertThat(result).isEqualTo(AcInstanceStateResolver.NONE); + } + +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/StateDefinitionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/StateDefinitionTest.java new file mode 100644 index 000000000..c2cbf4bbc --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/StateDefinitionTest.java @@ -0,0 +1,50 @@ +/*- + * ============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.utils; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +class StateDefinitionTest { + + @Test + void testNonNull() { + var stateDefinition = new StateDefinition(2, null); + assertThatThrownBy(() -> stateDefinition.put(null, null)) + .hasMessageMatching("keys is marked .*ull but is null"); + assertThatThrownBy(() -> stateDefinition.put(new String[] {"", ""}, null)) + .hasMessageMatching("value is marked .*ull but is null"); + assertThatThrownBy(() -> stateDefinition.get(null)) + .hasMessageMatching("keys is marked .*ull but is null"); + } + + @Test + void testWrongKeys() { + var stateDefinition = new StateDefinition(2, "NONE", "@"); + assertThatThrownBy(() -> stateDefinition.get(new String[] {"key"})) + .hasMessageMatching("wrong number of keys"); + assertThatThrownBy(() -> stateDefinition.put(new String[] {"key", "@id"}, "value")) + .hasMessageMatching("wrong key @id"); + assertThatThrownBy(() -> stateDefinition.put(new String[] {"key", null}, "value")) + .hasMessageMatching("wrong key null"); + } +} -- cgit 1.2.3-korg