f2f99a811cd2917f760f4c384a05011e64045f43
[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.AxArtifactKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
34
35 public class ValidationTest {
36
37     @Test
38     public void test() {
39         AxValidationResult result = new AxValidationResult();
40         AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN");
41         result = refKey.validate(result);
42
43         assertNotNull(result);
44         assertTrue(result.isOk());
45         assertTrue(result.isValid());
46         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
47         assertNotNull(result.getMessageList());
48
49         AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
50                         ValidationResult.VALID, "Some message");
51         result.addValidationMessage(vmess0);
52
53         assertTrue(result.isOk());
54         assertTrue(result.isValid());
55         assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
56         assertNotNull(result.getMessageList());
57         assertNotNull("hello", result.toString());
58
59         AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
60                         ValidationResult.OBSERVATION, "Some message");
61         result.addValidationMessage(vmess1);
62
63         assertTrue(result.isOk());
64         assertTrue(result.isValid());
65         assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
66         assertNotNull(result.getMessageList());
67         assertNotNull("hello", result.toString());
68
69         AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
70                         ValidationResult.WARNING, "Some message");
71         result.addValidationMessage(vmess2);
72
73         assertFalse(result.isOk());
74         assertTrue(result.isValid());
75         assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
76         assertNotNull(result.getMessageList());
77         assertNotNull("hello", result.toString());
78
79         AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
80                         ValidationResult.INVALID, "Some message");
81         result.addValidationMessage(vmess3);
82
83         assertFalse(result.isOk());
84         assertFalse(result.isValid());
85         assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
86         assertNotNull(result.getMessageList());
87         assertNotNull("hello", result.toString());
88
89         assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
90         assertEquals("Some message", result.getMessageList().get(3).getMessage());
91         assertEquals(AxArtifactKey.class.getName(), result.getMessageList().get(3).getObservedClass());
92         assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey());
93     }
94 }