d536e406f9581f1c98a33b97f9b04d8ca6034ac8
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / ValidationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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.models.base;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
31
32 public class ValidationTest {
33
34     private static final String HELLO = "hello";
35     private static final String SOME_MESSAGE = "Some message";
36
37     @Test
38     public void test() {
39         PfValidationResult result = new PfValidationResult();
40         PfConceptKey pfKeyey = new PfConceptKey("PK", "0.0.1");
41         result = pfKeyey.validate(result);
42
43         assertNotNull(result);
44         assertTrue(result.isOk());
45         assertTrue(result.isValid());
46         assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
47         assertNotNull(result.getMessageList());
48
49         PfValidationMessage vmess0 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
50                         ValidationResult.VALID, SOME_MESSAGE);
51         result.addValidationMessage(vmess0);
52
53         assertTrue(result.isOk());
54         assertTrue(result.isValid());
55         assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
56         assertNotNull(result.getMessageList());
57         assertNotNull(HELLO, result.toString());
58
59         PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
60                         ValidationResult.OBSERVATION, SOME_MESSAGE);
61         result.addValidationMessage(vmess1);
62
63         assertTrue(result.isOk());
64         assertTrue(result.isValid());
65         assertEquals(PfValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
66         assertNotNull(result.getMessageList());
67         assertNotNull(HELLO, result.toString());
68
69         PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
70                         ValidationResult.WARNING, SOME_MESSAGE);
71         result.addValidationMessage(vmess2);
72
73         assertFalse(result.isOk());
74         assertTrue(result.isValid());
75         assertEquals(PfValidationResult.ValidationResult.WARNING, result.getValidationResult());
76         assertNotNull(result.getMessageList());
77         assertNotNull(HELLO, result.toString());
78
79         PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
80                         ValidationResult.INVALID, SOME_MESSAGE);
81         result.addValidationMessage(vmess3);
82
83         assertFalse(result.isOk());
84         assertFalse(result.isValid());
85         assertEquals(PfValidationResult.ValidationResult.INVALID, result.getValidationResult());
86         assertNotNull(result.getMessageList());
87         assertNotNull(HELLO, result.toString());
88
89         assertEquals(PfValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
90         assertEquals(SOME_MESSAGE, result.getMessageList().get(3).getMessage());
91         assertEquals(PfConceptKey.class.getName(), result.getMessageList().get(3).getObservedClass());
92         assertEquals(PfConceptKey.getNullKey(), result.getMessageList().get(3).getObservedKey());
93     }
94 }