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 * Test state task references.
41 * @author Liam Fallon (liam.fallon@ericsson.com)
43 public class StateTaskReferenceTest {
46 public void testStateTaskReference() {
47 assertNotNull(new AxStateTaskReference());
48 assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
49 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED,
50 new AxReferenceKey()));
51 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
52 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
54 AxStateTaskReference stRef = new AxStateTaskReference();
56 AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
60 fail("test should throw an exception here");
61 } catch (Exception e) {
62 assertEquals("key may not be null", e.getMessage());
65 stRef.setKey(stRefKey);
66 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getId());
67 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getId());
70 stRef.setStateTaskOutputType(null);
71 fail("test should throw an exception here");
72 } catch (Exception e) {
73 assertEquals("outputType may not be null", e.getMessage());
76 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
77 assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
78 stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
79 assertEquals(AxStateTaskOutputType.DIRECT, stRef.getStateTaskOutputType());
80 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
81 assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
84 stRef.setOutput(null);
85 fail("test should throw an exception here");
86 } catch (Exception e) {
87 assertEquals("output may not be null", e.getMessage());
90 AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
91 stRef.setOutput(soKey);
92 assertEquals(soKey, stRef.getOutput());
94 AxValidationResult result = new AxValidationResult();
95 result = stRef.validate(result);
96 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
98 stRef.setKey(AxReferenceKey.getNullKey());
99 result = new AxValidationResult();
100 result = stRef.validate(result);
101 assertEquals(ValidationResult.INVALID, result.getValidationResult());
103 stRef.setKey(stRefKey);
104 result = new AxValidationResult();
105 result = stRef.validate(result);
106 assertEquals(ValidationResult.VALID, result.getValidationResult());
108 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
109 result = new AxValidationResult();
110 result = stRef.validate(result);
111 assertEquals(ValidationResult.INVALID, result.getValidationResult());
113 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
114 result = new AxValidationResult();
115 result = stRef.validate(result);
116 assertEquals(ValidationResult.VALID, result.getValidationResult());
118 stRef.setOutput(AxReferenceKey.getNullKey());
119 result = new AxValidationResult();
120 result = stRef.validate(result);
121 assertEquals(ValidationResult.INVALID, result.getValidationResult());
123 stRef.setOutput(soKey);
124 result = new AxValidationResult();
125 result = stRef.validate(result);
126 assertEquals(ValidationResult.VALID, result.getValidationResult());
130 AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
131 assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
133 assertFalse(stRef.hashCode() == 0);
135 assertTrue(stRef.equals(stRef));
136 assertTrue(stRef.equals(clonedStRef));
137 assertFalse(stRef.equals(null));
138 assertFalse(stRef.equals("Hello"));
139 assertFalse(stRef.equals(
140 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
141 assertFalse(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
143 .equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
144 assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
146 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
147 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
149 assertEquals(0, stRef.compareTo(stRef));
150 assertEquals(0, stRef.compareTo(clonedStRef));
151 assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
152 assertNotEquals(0, stRef.compareTo(null));
153 assertNotEquals(0, stRef.compareTo(
154 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
155 assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
156 assertNotEquals(0, stRef.compareTo(
157 new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
158 assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
160 assertNotNull(stRef.getKeys());