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.AxStateTaskOutputType;
36 import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
39 * @author Liam Fallon (liam.fallon@ericsson.com)
41 public class TestStateTaskReference {
44 public void testStateTaskReference() {
45 assertNotNull(new AxStateTaskReference());
46 assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
48 new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
49 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
50 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
52 AxStateTaskReference stRef = new AxStateTaskReference();
54 AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
55 AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
59 fail("test should throw an exception here");
60 } catch (Exception e) {
61 assertEquals("key may not be null", e.getMessage());
64 stRef.setKey(stRefKey);
65 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getId());
66 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getId());
69 stRef.setStateTaskOutputType(null);
70 fail("test should throw an exception here");
71 } catch (Exception e) {
72 assertEquals("outputType may not be null", e.getMessage());
75 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
76 assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
77 stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
78 assertEquals(AxStateTaskOutputType.DIRECT, stRef.getStateTaskOutputType());
79 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
80 assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
83 stRef.setOutput(null);
84 fail("test should throw an exception here");
85 } catch (Exception e) {
86 assertEquals("output may not be null", e.getMessage());
89 stRef.setOutput(soKey);
90 assertEquals(soKey, stRef.getOutput());
92 AxValidationResult result = new AxValidationResult();
93 result = stRef.validate(result);
94 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
96 stRef.setKey(AxReferenceKey.getNullKey());
97 result = new AxValidationResult();
98 result = stRef.validate(result);
99 assertEquals(ValidationResult.INVALID, result.getValidationResult());
101 stRef.setKey(stRefKey);
102 result = new AxValidationResult();
103 result = stRef.validate(result);
104 assertEquals(ValidationResult.VALID, result.getValidationResult());
106 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
107 result = new AxValidationResult();
108 result = stRef.validate(result);
109 assertEquals(ValidationResult.INVALID, result.getValidationResult());
111 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
112 result = new AxValidationResult();
113 result = stRef.validate(result);
114 assertEquals(ValidationResult.VALID, result.getValidationResult());
116 stRef.setOutput(AxReferenceKey.getNullKey());
117 result = new AxValidationResult();
118 result = stRef.validate(result);
119 assertEquals(ValidationResult.INVALID, result.getValidationResult());
121 stRef.setOutput(soKey);
122 result = new AxValidationResult();
123 result = stRef.validate(result);
124 assertEquals(ValidationResult.VALID, result.getValidationResult());
128 AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
129 assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
131 assertFalse(stRef.hashCode() == 0);
133 assertTrue(stRef.equals(stRef));
134 assertTrue(stRef.equals(clonedStRef));
135 assertFalse(stRef.equals(null));
136 assertFalse(stRef.equals("Hello"));
138 .equals(new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
139 assertFalse(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
141 stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
142 assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
144 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
145 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
147 assertEquals(0, stRef.compareTo(stRef));
148 assertEquals(0, stRef.compareTo(clonedStRef));
149 assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
150 assertNotEquals(0, stRef.compareTo(null));
151 assertNotEquals(0, stRef
152 .compareTo(new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
153 assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
155 stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
156 assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
158 assertNotNull(stRef.getKeys());