summaryrefslogtreecommitdiffstats
path: root/models/src/test/java/org/onap
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-19 10:08:35 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2023-01-19 10:50:25 +0000
commit467f0dbfe26a864a607286aab6d22c96e075bd17 (patch)
tree8cb11f2019cfa7976c19414948af8f9b3f9b298c /models/src/test/java/org/onap
parent48df549e1fd90c2768a78c0c88e87dc3834b6222 (diff)
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 <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org/onap')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java65
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/StateDefinitionTest.java50
2 files changed, 115 insertions, 0 deletions
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<String>(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<String>(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");
+ }
+}