2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 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.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
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");
59 fail("test should throw an exception here");
60 } catch (final Exception e) {
61 assertEquals("key may not be null", e.getMessage());
65 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
66 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
69 so.setNextState(null);
70 fail("test should throw an exception here");
71 } catch (final Exception e) {
72 assertEquals("nextState may not be null", e.getMessage());
75 so.setNextState(nsKey);
76 assertEquals(nsKey, so.getNextState());
79 so.setOutgoingEvent(null);
80 fail("test should throw an exception here");
81 } catch (final Exception e) {
82 assertEquals("outgoingEvent may not be null", e.getMessage());
85 so.setOutgoingEvent(eKey);
86 assertEquals(eKey, so.getOutgingEvent());
88 AxValidationResult result = new AxValidationResult();
89 result = so.validate(result);
90 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
92 so.setKey(AxReferenceKey.getNullKey());
93 result = new AxValidationResult();
94 result = so.validate(result);
95 assertEquals(ValidationResult.INVALID, result.getValidationResult());
98 result = new AxValidationResult();
99 result = so.validate(result);
100 assertEquals(ValidationResult.VALID, result.getValidationResult());
102 so.setOutgoingEvent(AxArtifactKey.getNullKey());
103 result = new AxValidationResult();
104 result = so.validate(result);
105 assertEquals(ValidationResult.INVALID, result.getValidationResult());
107 so.setOutgoingEvent(eKey);
108 result = new AxValidationResult();
109 result = so.validate(result);
110 assertEquals(ValidationResult.VALID, result.getValidationResult());
114 final AxStateOutput clonedPar = new AxStateOutput(so);
115 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
117 assertFalse(so.hashCode() == 0);
119 assertTrue(so.equals(so));
120 assertTrue(so.equals(clonedPar));
121 assertFalse(so.equals(null));
122 assertFalse(so.equals((Object) "Hello"));
123 assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
124 assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
125 assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
126 assertTrue(so.equals(new AxStateOutput(soKey, eKey, nsKey)));
128 assertEquals(0, so.compareTo(so));
129 assertEquals(0, so.compareTo(clonedPar));
130 assertNotEquals(0, so.compareTo(new AxArtifactKey()));
131 assertNotEquals(0, so.compareTo(null));
132 assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
133 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
134 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
135 assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
137 assertNotNull(so.getKeys());