Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / concepts / ValidationTest.java
1 /*
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.basicmodel.concepts;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
30
31 public class ValidationTest {
32
33     @Test
34     public void test() {
35         AxValidationResult result = new AxValidationResult();
36         AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN");
37         result = refKey.validate(result);
38
39         assertNotNull(result);
40         assertTrue(result.isOk());
41         assertTrue(result.isValid());
42         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
43         assertNotNull(result.getMessageList());
44
45         AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
46                         ValidationResult.VALID, "Some message");
47         result.addValidationMessage(vmess0);
48
49         assertTrue(result.isOk());
50         assertTrue(result.isValid());
51         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
52         assertNotNull(result.getMessageList());
53         assertNotNull("hello", result.toString());
54
55         AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
56                         ValidationResult.OBSERVATION, "Some message");
57         result.addValidationMessage(vmess1);
58
59         assertTrue(result.isOk());
60         assertTrue(result.isValid());
61         assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
62         assertNotNull(result.getMessageList());
63         assertNotNull("hello", result.toString());
64
65         AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
66                         ValidationResult.WARNING, "Some message");
67         result.addValidationMessage(vmess2);
68
69         assertFalse(result.isOk());
70         assertTrue(result.isValid());
71         assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
72         assertNotNull(result.getMessageList());
73         assertNotNull("hello", result.toString());
74
75         AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
76                         ValidationResult.INVALID, "Some message");
77         result.addValidationMessage(vmess3);
78
79         assertFalse(result.isOk());
80         assertFalse(result.isValid());
81         assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
82         assertNotNull(result.getMessageList());
83         assertNotNull("hello", result.toString());
84
85         assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
86         assertEquals("Some message", result.getMessageList().get(3).getMessage());
87         assertEquals(AxArtifactKey.class.getName(), result.getMessageList().get(3).getObservedClass());
88         assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey());
89     }
90 }