diff options
author | Ramesh Murugan Iyer <ramesh.murugan.iyer@est.tech> | 2023-01-23 09:31:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-01-23 09:31:50 +0000 |
commit | daf695ffed19108dad7fb228bab879d19c2ffbfa (patch) | |
tree | 2f48ae8116e484fab247fe4099c85089c409d809 /models/src/test | |
parent | 46964ab900060a560b9b41f7d34ab0e26ac7fd61 (diff) | |
parent | 467f0dbfe26a864a607286aab6d22c96e075bd17 (diff) |
Merge "Refactor AcInstanceState Update on ACM"
Diffstat (limited to 'models/src/test')
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"); + } +} |