2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.policymodel.concepts;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
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;
35 import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
38 * @author Liam Fallon (liam.fallon@ericsson.com)
40 public class TestStateOutput {
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");
57 fail("test should throw an exception here");
58 } catch (final Exception e) {
59 assertEquals("key may not be null", e.getMessage());
63 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
64 assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
67 so.setNextState(null);
68 fail("test should throw an exception here");
69 } catch (final Exception e) {
70 assertEquals("nextState may not be null", e.getMessage());
73 so.setNextState(nsKey);
74 assertEquals(nsKey, so.getNextState());
77 so.setOutgoingEvent(null);
78 fail("test should throw an exception here");
79 } catch (final Exception e) {
80 assertEquals("outgoingEvent may not be null", e.getMessage());
83 so.setOutgoingEvent(eKey);
84 assertEquals(eKey, so.getOutgingEvent());
86 AxValidationResult result = new AxValidationResult();
87 result = so.validate(result);
88 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
90 so.setKey(AxReferenceKey.getNullKey());
91 result = new AxValidationResult();
92 result = so.validate(result);
93 assertEquals(ValidationResult.INVALID, result.getValidationResult());
96 result = new AxValidationResult();
97 result = so.validate(result);
98 assertEquals(ValidationResult.VALID, result.getValidationResult());
100 so.setOutgoingEvent(AxArtifactKey.getNullKey());
101 result = new AxValidationResult();
102 result = so.validate(result);
103 assertEquals(ValidationResult.INVALID, result.getValidationResult());
105 so.setOutgoingEvent(eKey);
106 result = new AxValidationResult();
107 result = so.validate(result);
108 assertEquals(ValidationResult.VALID, result.getValidationResult());
112 final AxStateOutput clonedPar = new AxStateOutput(so);
113 assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
115 assertFalse(so.hashCode() == 0);
117 assertTrue(so.equals(so));
118 assertTrue(so.equals(clonedPar));
119 assertFalse(so.equals(null));
120 assertFalse(so.equals("Hello"));
121 assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
122 assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
123 assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
124 assertTrue(so.equals(new AxStateOutput(soKey, eKey, nsKey)));
126 assertEquals(0, so.compareTo(so));
127 assertEquals(0, so.compareTo(clonedPar));
128 assertNotEquals(0, so.compareTo(new AxArtifactKey()));
129 assertNotEquals(0, so.compareTo(null));
130 assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
131 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
132 assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
133 assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
135 assertNotNull(so.getKeys());