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;
36 import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
41 * @author Liam Fallon (liam.fallon@ericsson.com)
43 public class StateOutputTest {
46 public void testStateOutput() {
47 assertNotNull(new AxStateOutput());
48 assertNotNull(new AxStateOutput(new AxReferenceKey()));
49 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
50 assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
52 final AxStateOutput so = new AxStateOutput();
54 final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
55 final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
56 final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
60 fail("test should throw an exception here");
61 } catch (final Exception e) {
62 assertEquals("key may not be null", e.getMessage());
66 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
67 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
70 so.setNextState(null);
71 fail("test should throw an exception here");
72 } catch (final Exception e) {
73 assertEquals("nextState may not be null", e.getMessage());
76 so.setNextState(nsKey);
77 assertEquals(nsKey, so.getNextState());
80 so.setOutgoingEvent(null);
81 fail("test should throw an exception here");
82 } catch (final Exception e) {
83 assertEquals("outgoingEvent may not be null", e.getMessage());
86 so.setOutgoingEvent(eKey);
87 assertEquals(eKey, so.getOutgingEvent());
89 AxValidationResult result = new AxValidationResult();
90 result = so.validate(result);
91 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
93 so.setKey(AxReferenceKey.getNullKey());
94 result = new AxValidationResult();
95 result = so.validate(result);
96 assertEquals(ValidationResult.INVALID, result.getValidationResult());
99 result = new AxValidationResult();
100 result = so.validate(result);
101 assertEquals(ValidationResult.VALID, result.getValidationResult());
103 so.setOutgoingEvent(AxArtifactKey.getNullKey());
104 result = new AxValidationResult();
105 result = so.validate(result);
106 assertEquals(ValidationResult.INVALID, result.getValidationResult());
108 so.setOutgoingEvent(eKey);
109 result = new AxValidationResult();
110 result = so.validate(result);
111 assertEquals(ValidationResult.VALID, result.getValidationResult());
115 final AxStateOutput clonedPar = new AxStateOutput(so);
116 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
118 assertFalse(so.hashCode() == 0);
120 assertTrue(so.equals(so));
121 assertTrue(so.equals(clonedPar));
122 assertFalse(so.equals(null));
123 assertFalse(so.equals((Object)"Hello"));
124 assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
125 assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
126 assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
127 assertTrue(so.equals(new AxStateOutput(soKey, eKey, nsKey)));
129 assertEquals(0, so.compareTo(so));
130 assertEquals(0, so.compareTo(clonedPar));
131 assertNotEquals(0, so.compareTo(new AxArtifactKey()));
132 assertNotEquals(0, so.compareTo(null));
133 assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
134 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
135 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
136 assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
138 assertNotNull(so.getKeys());