2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.policymodel.concepts;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
38 * @author Liam Fallon (liam.fallon@ericsson.com)
40 public class StateOutputTest {
43 public void testStateOutput() {
44 assertNotNull(new AxStateOutput());
45 assertNotNull(new AxStateOutput(new AxReferenceKey()));
46 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
47 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
49 final AxStateOutput so = new AxStateOutput();
51 final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
52 final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
53 final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
55 assertThatThrownBy(() -> so.setKey(null))
56 .hasMessage("key may not be null");
58 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
59 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
61 assertThatThrownBy(() -> so.setNextState(null))
62 .hasMessage("nextState may not be null");
63 so.setNextState(nsKey);
64 assertEquals(nsKey, so.getNextState());
66 assertThatThrownBy(() -> so.setOutgoingEvent(null))
67 .hasMessage("outgoingEvent may not be null");
68 so.setOutgoingEvent(eKey);
69 assertEquals(eKey, so.getOutgingEvent());
71 AxValidationResult result = new AxValidationResult();
72 result = so.validate(result);
73 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
75 so.setKey(AxReferenceKey.getNullKey());
76 result = new AxValidationResult();
77 result = so.validate(result);
78 assertEquals(ValidationResult.INVALID, result.getValidationResult());
81 result = new AxValidationResult();
82 result = so.validate(result);
83 assertEquals(ValidationResult.VALID, result.getValidationResult());
85 so.setOutgoingEvent(AxArtifactKey.getNullKey());
86 result = new AxValidationResult();
87 result = so.validate(result);
88 assertEquals(ValidationResult.INVALID, result.getValidationResult());
90 so.setOutgoingEvent(eKey);
91 result = new AxValidationResult();
92 result = so.validate(result);
93 assertEquals(ValidationResult.VALID, result.getValidationResult());
97 final AxStateOutput clonedPar = new AxStateOutput(so);
98 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
100 assertNotEquals(0, so.hashCode());
102 // disabling sonar because this code tests the equals() method
103 assertEquals(so, so); // NOSONAR
104 assertEquals(so, clonedPar);
106 assertNotEquals(so, "Hello");
107 assertNotEquals(so, new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey));
108 assertNotEquals(so, new AxStateOutput(soKey, new AxArtifactKey(), nsKey));
109 assertNotEquals(so, new AxStateOutput(soKey, eKey, new AxReferenceKey()));
110 assertEquals(so, new AxStateOutput(soKey, eKey, nsKey));
112 assertEquals(0, so.compareTo(so));
113 assertEquals(0, so.compareTo(clonedPar));
114 assertNotEquals(0, so.compareTo(new AxArtifactKey()));
115 assertNotEquals(0, so.compareTo(null));
116 assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
117 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
118 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
119 assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
121 assertNotNull(so.getKeys());