Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / policy-model / src / test / java / org / onap / policy / apex / model / policymodel / concepts / StateOutputTest.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 outputs.
39  * 
40  * @author Liam Fallon (liam.fallon@ericsson.com)
41  */
42 public class StateOutputTest {
43
44     @Test
45     public void testStateOutput() {
46         assertNotNull(new AxStateOutput());
47         assertNotNull(new AxStateOutput(new AxReferenceKey()));
48         assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
49         assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
50
51         final AxStateOutput so = new AxStateOutput();
52
53         final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
54         final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
55         final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
56
57         try {
58             so.setKey(null);
59             fail("test should throw an exception here");
60         } catch (final Exception e) {
61             assertEquals("key may not be null", e.getMessage());
62         }
63
64         so.setKey(soKey);
65         assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId());
66         assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId());
67
68         try {
69             so.setNextState(null);
70             fail("test should throw an exception here");
71         } catch (final Exception e) {
72             assertEquals("nextState may not be null", e.getMessage());
73         }
74
75         so.setNextState(nsKey);
76         assertEquals(nsKey, so.getNextState());
77
78         try {
79             so.setOutgoingEvent(null);
80             fail("test should throw an exception here");
81         } catch (final Exception e) {
82             assertEquals("outgoingEvent may not be null", e.getMessage());
83         }
84
85         so.setOutgoingEvent(eKey);
86         assertEquals(eKey, so.getOutgingEvent());
87
88         AxValidationResult result = new AxValidationResult();
89         result = so.validate(result);
90         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
91
92         so.setKey(AxReferenceKey.getNullKey());
93         result = new AxValidationResult();
94         result = so.validate(result);
95         assertEquals(ValidationResult.INVALID, result.getValidationResult());
96
97         so.setKey(soKey);
98         result = new AxValidationResult();
99         result = so.validate(result);
100         assertEquals(ValidationResult.VALID, result.getValidationResult());
101
102         so.setOutgoingEvent(AxArtifactKey.getNullKey());
103         result = new AxValidationResult();
104         result = so.validate(result);
105         assertEquals(ValidationResult.INVALID, result.getValidationResult());
106
107         so.setOutgoingEvent(eKey);
108         result = new AxValidationResult();
109         result = so.validate(result);
110         assertEquals(ValidationResult.VALID, result.getValidationResult());
111
112         so.clean();
113
114         final AxStateOutput clonedPar = new AxStateOutput(so);
115         assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
116
117         assertFalse(so.hashCode() == 0);
118
119         assertTrue(so.equals(so));
120         assertTrue(so.equals(clonedPar));
121         assertFalse(so.equals(null));
122         assertFalse(so.equals((Object) "Hello"));
123         assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
124         assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
125         assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
126         assertTrue(so.equals(new AxStateOutput(soKey, eKey, nsKey)));
127
128         assertEquals(0, so.compareTo(so));
129         assertEquals(0, so.compareTo(clonedPar));
130         assertNotEquals(0, so.compareTo(new AxArtifactKey()));
131         assertNotEquals(0, so.compareTo(null));
132         assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
133         assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
134         assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
135         assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
136
137         assertNotNull(so.getKeys());
138     }
139 }