2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.model.policymodel.concepts;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class StateOutputTest {
44 public void testStateOutput() {
45 assertNotNull(new AxStateOutput());
46 assertNotNull(new AxStateOutput(new AxReferenceKey()));
47 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
48 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
50 final AxStateOutput so = new AxStateOutput();
52 final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
53 final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
54 final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
56 assertThatThrownBy(() -> so.setKey(null))
57 .hasMessage("key is marked non-null but is null");
59 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
60 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
62 assertThatThrownBy(() -> so.setNextState(null))
63 .hasMessage("nextState is marked non-null but is null");
64 so.setNextState(nsKey);
65 assertEquals(nsKey, so.getNextState());
67 assertThatThrownBy(() -> so.setOutgoingEvent(null))
68 .hasMessage("outgoingEvent is marked non-null but is null");
69 so.setOutgoingEvent(eKey);
70 assertEquals(eKey, so.getOutgoingEvent());
72 AxValidationResult result = new AxValidationResult();
73 result = so.validate(result);
74 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
76 so.setKey(AxReferenceKey.getNullKey());
77 result = new AxValidationResult();
78 result = so.validate(result);
79 assertEquals(ValidationResult.INVALID, result.getValidationResult());
82 result = new AxValidationResult();
83 result = so.validate(result);
84 assertEquals(ValidationResult.VALID, result.getValidationResult());
86 so.setOutgoingEvent(AxArtifactKey.getNullKey());
87 result = new AxValidationResult();
88 result = so.validate(result);
89 assertEquals(ValidationResult.INVALID, result.getValidationResult());
91 so.setOutgoingEvent(eKey);
92 result = new AxValidationResult();
93 result = so.validate(result);
94 assertEquals(ValidationResult.VALID, result.getValidationResult());
98 final AxStateOutput clonedPar = new AxStateOutput(so);
99 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
101 assertNotEquals(0, so.hashCode());
103 // disabling sonar because this code tests the equals() method
104 assertEquals(so, so); // NOSONAR
105 assertEquals(so, clonedPar);
107 assertNotEquals(so, (Object) "Hello");
108 assertNotEquals(so, new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey));
109 assertNotEquals(so, new AxStateOutput(soKey, new AxArtifactKey(), nsKey));
110 assertNotEquals(so, new AxStateOutput(soKey, eKey, new AxReferenceKey()));
111 assertEquals(so, new AxStateOutput(soKey, eKey, nsKey));
113 assertEquals(0, so.compareTo(so));
114 assertEquals(0, so.compareTo(clonedPar));
115 assertNotEquals(0, so.compareTo(new AxArtifactKey()));
116 assertNotEquals(0, so.compareTo(null));
117 assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
118 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
119 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
120 assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
122 assertNotNull(so.getKeys());