summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2023-01-23 09:31:50 +0000
committerGerrit Code Review <gerrit@onap.org>2023-01-23 09:31:50 +0000
commitdaf695ffed19108dad7fb228bab879d19c2ffbfa (patch)
tree2f48ae8116e484fab247fe4099c85089c409d809 /models
parent46964ab900060a560b9b41f7d34ab0e26ac7fd61 (diff)
parent467f0dbfe26a864a607286aab6d22c96e075bd17 (diff)
Merge "Refactor AcInstanceState Update on ACM"
Diffstat (limited to 'models')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java28
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java29
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java43
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java27
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java38
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java39
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java27
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java82
-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
11 files changed, 308 insertions, 132 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java
new file mode 100644
index 000000000..659b312d4
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java
@@ -0,0 +1,28 @@
+/*-
+ * ============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.concepts;
+
+public enum DeployState {
+ DEPLOYED,
+ DEPLOYING,
+ UNDEPLOYED,
+ UNDEPLOYING
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java
new file mode 100644
index 000000000..a619cc2f7
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java
@@ -0,0 +1,29 @@
+/*-
+ * ============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.concepts;
+
+public enum LockState {
+ LOCKED,
+ LOCKING,
+ UNLOCKED,
+ UNLOCKING,
+ NONE
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
index ed83a494a..e47947a02 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
@@ -24,18 +24,6 @@ import lombok.Data;
@Data
public class AcInstanceStateUpdate {
- private enum DeployOrder {
- NONE,
- UNDEPLOY,
- DEPLOYED
- }
-
- private enum LockOrder {
- NONE,
- UNLOCK,
- LOCK
- }
-
private DeployOrder deployOrder;
private LockOrder lockOrder;
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java
deleted file mode 100644
index a87433d4c..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.messages.rest.instantiation;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.messages.rest.GenericNameVersion;
-import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse;
-
-
-/**
- * Response to Commissioning requests that affect a change.
- */
-@Getter
-@Setter
-@ToString(callSuper = true)
-public class AutomationCompositionOrderStateResponse extends SimpleResponse {
-
- private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED;
-
- private List<GenericNameVersion> automationCompositionIdentifierList = new ArrayList<>();
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java
new file mode 100644
index 000000000..6c1572d19
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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.messages.rest.instantiation;
+
+public enum DeployOrder {
+ NONE,
+ UNDEPLOY,
+ DEPLOY
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java
deleted file mode 100644
index 0341d5dae..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.messages.rest.instantiation;
-
-import java.util.ArrayList;
-import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
-/**
- * Response to Instance Properties requests that affect a change.
- */
-@Getter
-@Setter
-@ToString(callSuper = true)
-public class InstancePropertiesResponse extends SimpleResponse {
- private List<ToscaConceptIdentifier> affectedInstanceProperties = new ArrayList<>();
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java
deleted file mode 100644
index e6bdaee9d..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
- * ================================================================================
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.messages.rest.instantiation;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse;
-
-/**
- * Response to instantiation OrderState.
- */
-@Getter
-@Setter
-@ToString(callSuper = true)
-public class InstantiationOrderStateResponse extends SimpleResponse {
-
- private AutomationCompositionOrderedState orderedState;
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java
new file mode 100644
index 000000000..6b0a208eb
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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.messages.rest.instantiation;
+
+public enum LockOrder {
+ NONE,
+ UNLOCK,
+ LOCK
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
new file mode 100644
index 000000000..dba64f585
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
@@ -0,0 +1,82 @@
+/*-
+ * ============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 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;
+import org.onap.policy.clamp.models.acm.utils.StateDefinition;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AcInstanceStateResolver {
+ private final StateDefinition<String> graph;
+
+ private static final String DEPLOYED = DeployState.DEPLOYED.name();
+ private static final String UNDEPLOYED = DeployState.UNDEPLOYED.name();
+
+ private static final String LOCKED = LockState.LOCKED.name();
+ private static final String UNLOCKED = LockState.UNLOCKED.name();
+ private static final String STATE_LOCKED_NONE = LockState.NONE.name();
+
+ private static final String DEPLOY_NONE = DeployOrder.NONE.name();
+ private static final String LOCK_NONE = LockOrder.NONE.name();
+
+ // list of results
+ public static final String DEPLOY = DeployOrder.DEPLOY.name();
+ public static final String UNDEPLOY = DeployOrder.UNDEPLOY.name();
+ public static final String LOCK = LockOrder.LOCK.name();
+ public static final String UNLOCK = LockOrder.UNLOCK.name();
+ public static final String NONE = "NONE";
+
+ /**
+ * Construct.
+ */
+ public AcInstanceStateResolver() {
+ this.graph = new StateDefinition<>(4, NONE);
+
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE}, DEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED}, UNDEPLOY);
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED}, UNLOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED}, LOCK);
+ }
+
+ /**
+ * Check if Deploy Order and Lock Order are consistent with current DeployState and LockState.
+ *
+ * @param acDeployOrder the Deploy Ordered
+ * @param acLockOrder the Lock Ordered
+ * @param acDeployState then current Deploy State
+ * @param acLockState the current Lock State
+ * @return the order (DEPLOY/UNDEPLOY/LOCK/UNLOCK) to send to participant or NONE if order is not consistent
+ */
+ public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, DeployState acDeployState,
+ LockState acLockState) {
+ var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE;
+ var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.NONE;
+
+ var deployState = acDeployState != null ? acDeployState : DeployState.UNDEPLOYED;
+ var lockState = acLockState != null ? acLockState : LockState.NONE;
+ return this.graph
+ .get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name()});
+ }
+}
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");
+ }
+}