diff options
Diffstat (limited to 'models/src/test/java/org/onap')
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"); + } +} |