2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
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;
28 import org.junit.Test;
29 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
31 public class ValidationTest {
35 PfValidationResult result = new PfValidationResult();
36 PfConceptKey pfKeyey = new PfConceptKey("PK", "0.0.1");
37 result = pfKeyey.validate(result);
39 assertNotNull(result);
40 assertTrue(result.isOk());
41 assertTrue(result.isValid());
42 assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
43 assertNotNull(result.getMessageList());
45 PfValidationMessage vmess0 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
46 ValidationResult.VALID, "Some message");
47 result.addValidationMessage(vmess0);
49 assertTrue(result.isOk());
50 assertTrue(result.isValid());
51 assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
52 assertNotNull(result.getMessageList());
53 assertNotNull("hello", result.toString());
55 PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
56 ValidationResult.OBSERVATION, "Some message");
57 result.addValidationMessage(vmess1);
59 assertTrue(result.isOk());
60 assertTrue(result.isValid());
61 assertEquals(PfValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
62 assertNotNull(result.getMessageList());
63 assertNotNull("hello", result.toString());
65 PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
66 ValidationResult.WARNING, "Some message");
67 result.addValidationMessage(vmess2);
69 assertFalse(result.isOk());
70 assertTrue(result.isValid());
71 assertEquals(PfValidationResult.ValidationResult.WARNING, result.getValidationResult());
72 assertNotNull(result.getMessageList());
73 assertNotNull("hello", result.toString());
75 PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
76 ValidationResult.INVALID, "Some message");
77 result.addValidationMessage(vmess3);
79 assertFalse(result.isOk());
80 assertFalse(result.isValid());
81 assertEquals(PfValidationResult.ValidationResult.INVALID, result.getValidationResult());
82 assertNotNull(result.getMessageList());
83 assertNotNull("hello", result.toString());
85 assertEquals(PfValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
86 assertEquals("Some message", result.getMessageList().get(3).getMessage());
87 assertEquals(PfConceptKey.class.getCanonicalName(), result.getMessageList().get(3).getObservedClass());
88 assertEquals(PfConceptKey.getNullKey(), result.getMessageList().get(3).getObservedKey());