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.assertFalse;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
31 import org.junit.Test;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
40 * @author Liam Fallon (liam.fallon@ericsson.com)
42 public class StateOutputTest {
45 public void testStateOutput() {
46 assertNotNull(new AxStateOutput());
47 assertNotNull(new AxStateOutput(new AxReferenceKey()));
48 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
49 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
51 final AxStateOutput so = new AxStateOutput();
53 final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
54 final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
55 final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
57 assertThatThrownBy(() -> so.setKey(null))
58 .hasMessage("key may not be null");
60 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
61 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
63 assertThatThrownBy(() -> so.setNextState(null))
64 .hasMessage("nextState may not be null");
65 so.setNextState(nsKey);
66 assertEquals(nsKey, so.getNextState());
68 assertThatThrownBy(() -> so.setOutgoingEvent(null))
69 .hasMessage("outgoingEvent may not be null");
70 so.setOutgoingEvent(eKey);
71 assertEquals(eKey, so.getOutgingEvent());
73 AxValidationResult result = new AxValidationResult();
74 result = so.validate(result);
75 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
77 so.setKey(AxReferenceKey.getNullKey());
78 result = new AxValidationResult();
79 result = so.validate(result);
80 assertEquals(ValidationResult.INVALID, result.getValidationResult());
83 result = new AxValidationResult();
84 result = so.validate(result);
85 assertEquals(ValidationResult.VALID, result.getValidationResult());
87 so.setOutgoingEvent(AxArtifactKey.getNullKey());
88 result = new AxValidationResult();
89 result = so.validate(result);
90 assertEquals(ValidationResult.INVALID, result.getValidationResult());
92 so.setOutgoingEvent(eKey);
93 result = new AxValidationResult();
94 result = so.validate(result);
95 assertEquals(ValidationResult.VALID, result.getValidationResult());
99 final AxStateOutput clonedPar = new AxStateOutput(so);
100 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
102 assertFalse(so.hashCode() == 0);
104 assertTrue(so.equals(so));
105 assertTrue(so.equals(clonedPar));
106 assertFalse(so.equals(null));
107 assertFalse(so.equals((Object) "Hello"));
108 assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
109 assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
110 assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
111 assertTrue(so.equals(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());