Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / policy-model / src / test / java / org / onap / policy / apex / model / policymodel / concepts / StateTaskReferenceTest.java
1 /*-
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
9  * 
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  * 
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.
17  * 
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.policymodel.concepts;
23
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;
30
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
37 /**
38  * Test state task references.
39  * 
40  * @author Liam Fallon (liam.fallon@ericsson.com)
41  */
42 public class StateTaskReferenceTest {
43
44     @Test
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()));
52
53         AxStateTaskReference stRef = new AxStateTaskReference();
54
55         AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
56
57         try {
58             stRef.setKey(null);
59             fail("test should throw an exception here");
60         } catch (Exception e) {
61             assertEquals("key may not be null", e.getMessage());
62         }
63
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());
67
68         try {
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());
73         }
74
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());
81
82         try {
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());
87         }
88
89         AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
90         stRef.setOutput(soKey);
91         assertEquals(soKey, stRef.getOutput());
92
93         AxValidationResult result = new AxValidationResult();
94         result = stRef.validate(result);
95         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
96
97         stRef.setKey(AxReferenceKey.getNullKey());
98         result = new AxValidationResult();
99         result = stRef.validate(result);
100         assertEquals(ValidationResult.INVALID, result.getValidationResult());
101
102         stRef.setKey(stRefKey);
103         result = new AxValidationResult();
104         result = stRef.validate(result);
105         assertEquals(ValidationResult.VALID, result.getValidationResult());
106
107         stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
108         result = new AxValidationResult();
109         result = stRef.validate(result);
110         assertEquals(ValidationResult.INVALID, result.getValidationResult());
111
112         stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
113         result = new AxValidationResult();
114         result = stRef.validate(result);
115         assertEquals(ValidationResult.VALID, result.getValidationResult());
116
117         stRef.setOutput(AxReferenceKey.getNullKey());
118         result = new AxValidationResult();
119         result = stRef.validate(result);
120         assertEquals(ValidationResult.INVALID, result.getValidationResult());
121
122         stRef.setOutput(soKey);
123         result = new AxValidationResult();
124         result = stRef.validate(result);
125         assertEquals(ValidationResult.VALID, result.getValidationResult());
126
127         stRef.clean();
128
129         AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
130         assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
131
132         assertFalse(stRef.hashCode() == 0);
133
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)));
141         assertFalse(stRef
142                         .equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
143         assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
144
145         assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
146                         AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
147
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)));
158
159         assertNotNull(stRef.getKeys());
160     }
161 }