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;
38 * Test state task references.
40 * @author Liam Fallon (liam.fallon@ericsson.com)
42 public class StateTaskReferenceTest {
45 public void testStateTaskReference() {
46 assertNotNull(new AxStateTaskReference());
47 assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
48 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED,
49 new AxReferenceKey()));
50 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
51 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
53 AxStateTaskReference stRef = new AxStateTaskReference();
55 AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
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 AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
90 stRef.setOutput(soKey);
91 assertEquals(soKey, stRef.getOutput());
93 AxValidationResult result = new AxValidationResult();
94 result = stRef.validate(result);
95 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
97 stRef.setKey(AxReferenceKey.getNullKey());
98 result = new AxValidationResult();
99 result = stRef.validate(result);
100 assertEquals(ValidationResult.INVALID, result.getValidationResult());
102 stRef.setKey(stRefKey);
103 result = new AxValidationResult();
104 result = stRef.validate(result);
105 assertEquals(ValidationResult.VALID, result.getValidationResult());
107 stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
108 result = new AxValidationResult();
109 result = stRef.validate(result);
110 assertEquals(ValidationResult.INVALID, result.getValidationResult());
112 stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
113 result = new AxValidationResult();
114 result = stRef.validate(result);
115 assertEquals(ValidationResult.VALID, result.getValidationResult());
117 stRef.setOutput(AxReferenceKey.getNullKey());
118 result = new AxValidationResult();
119 result = stRef.validate(result);
120 assertEquals(ValidationResult.INVALID, result.getValidationResult());
122 stRef.setOutput(soKey);
123 result = new AxValidationResult();
124 result = stRef.validate(result);
125 assertEquals(ValidationResult.VALID, result.getValidationResult());
129 AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
130 assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
132 assertFalse(stRef.hashCode() == 0);
134 assertTrue(stRef.equals(stRef));
135 assertTrue(stRef.equals(clonedStRef));
136 assertFalse(stRef.equals(null));
137 assertFalse(stRef.equals((Object) "Hello"));
138 assertFalse(stRef.equals(
139 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
140 assertFalse(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
142 .equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
143 assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
145 assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
146 AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
148 assertEquals(0, stRef.compareTo(stRef));
149 assertEquals(0, stRef.compareTo(clonedStRef));
150 assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
151 assertNotEquals(0, stRef.compareTo(null));
152 assertNotEquals(0, stRef.compareTo(
153 new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
154 assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
155 assertNotEquals(0, stRef.compareTo(
156 new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
157 assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
159 assertNotNull(stRef.getKeys());