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.AxStateTaskOutputType;
37 import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
40 * Test state task references.
42 * @author Liam Fallon (liam.fallon@ericsson.com)
44 public class StateTaskReferenceTest {
47 public void testStateTaskReference() {
48 assertNotNull(new AxStateTaskReference());
49 assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
50 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED,
51 new AxReferenceKey()));
52 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
53 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
55 AxStateTaskReference stRef = new AxStateTaskReference();
57 AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
61 fail("test should throw an exception here");
62 } catch (Exception e) {
63 assertEquals("key may not be null", e.getMessage());
66 stRef.setKey(stRefKey);
67 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getId());
68 assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getId());
71 stRef.setStateTaskOutputType(null);
72 fail("test should throw an exception here");
73 } catch (Exception e) {
74 assertEquals("outputType may not be null", e.getMessage());
77 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
78 assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
79 stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
80 assertEquals(AxStateTaskOutputType.DIRECT, stRef.getStateTaskOutputType());
81 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
82 assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
85 stRef.setOutput(null);
86 fail("test should throw an exception here");
87 } catch (Exception e) {
88 assertEquals("output may not be null", e.getMessage());
91 AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
92 stRef.setOutput(soKey);
93 assertEquals(soKey, stRef.getOutput());
95 AxValidationResult result = new AxValidationResult();
96 result = stRef.validate(result);
97 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
99 stRef.setKey(AxReferenceKey.getNullKey());
100 result = new AxValidationResult();
101 result = stRef.validate(result);
102 assertEquals(ValidationResult.INVALID, result.getValidationResult());
104 stRef.setKey(stRefKey);
105 result = new AxValidationResult();
106 result = stRef.validate(result);
107 assertEquals(ValidationResult.VALID, result.getValidationResult());
109 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
110 result = new AxValidationResult();
111 result = stRef.validate(result);
112 assertEquals(ValidationResult.INVALID, result.getValidationResult());
114 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
115 result = new AxValidationResult();
116 result = stRef.validate(result);
117 assertEquals(ValidationResult.VALID, result.getValidationResult());
119 stRef.setOutput(AxReferenceKey.getNullKey());
120 result = new AxValidationResult();
121 result = stRef.validate(result);
122 assertEquals(ValidationResult.INVALID, result.getValidationResult());
124 stRef.setOutput(soKey);
125 result = new AxValidationResult();
126 result = stRef.validate(result);
127 assertEquals(ValidationResult.VALID, result.getValidationResult());
131 AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
132 assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
134 assertFalse(stRef.hashCode() == 0);
136 assertTrue(stRef.equals(stRef));
137 assertTrue(stRef.equals(clonedStRef));
138 assertFalse(stRef.equals(null));
139 assertFalse(stRef.equals((Object)"Hello"));
140 assertFalse(stRef.equals(
141 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
142 assertFalse(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
144 .equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
145 assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
147 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
148 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
150 assertEquals(0, stRef.compareTo(stRef));
151 assertEquals(0, stRef.compareTo(clonedStRef));
152 assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
153 assertNotEquals(0, stRef.compareTo(null));
154 assertNotEquals(0, stRef.compareTo(
155 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
156 assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
157 assertNotEquals(0, stRef.compareTo(
158 new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
159 assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
161 assertNotNull(stRef.getKeys());