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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.base;
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;
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfValidationResult.ValidationResult;
32 public class ValidationTest {
34 private static final String HELLO = "hello";
35 private static final String SOME_MESSAGE = "Some message";
39 PfValidationResult result = new PfValidationResult();
40 PfConceptKey pfKeyey = new PfConceptKey("PK", "0.0.1");
41 result = pfKeyey.validate(result);
43 assertNotNull(result);
44 assertTrue(result.isOk());
45 assertTrue(result.isValid());
46 assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
47 assertNotNull(result.getMessageList());
49 PfValidationMessage vmess0 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
50 ValidationResult.VALID, SOME_MESSAGE);
51 result.addValidationMessage(vmess0);
53 assertTrue(result.isOk());
54 assertTrue(result.isValid());
55 assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult());
56 assertNotNull(result.getMessageList());
57 assertNotNull(HELLO, result.toString());
59 PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
60 ValidationResult.OBSERVATION, SOME_MESSAGE);
61 result.addValidationMessage(vmess1);
63 assertTrue(result.isOk());
64 assertTrue(result.isValid());
65 assertEquals(PfValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
66 assertNotNull(result.getMessageList());
67 assertNotNull(HELLO, result.toString());
69 PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
70 ValidationResult.WARNING, SOME_MESSAGE);
71 result.addValidationMessage(vmess2);
73 assertFalse(result.isOk());
74 assertTrue(result.isValid());
75 assertEquals(PfValidationResult.ValidationResult.WARNING, result.getValidationResult());
76 assertNotNull(result.getMessageList());
77 assertNotNull(HELLO, result.toString());
79 PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class,
80 ValidationResult.INVALID, SOME_MESSAGE);
81 result.addValidationMessage(vmess3);
83 assertFalse(result.isOk());
84 assertFalse(result.isValid());
85 assertEquals(PfValidationResult.ValidationResult.INVALID, result.getValidationResult());
86 assertNotNull(result.getMessageList());
87 assertNotNull(HELLO, result.toString());
89 assertEquals(PfValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
90 assertEquals(SOME_MESSAGE, result.getMessageList().get(3).getMessage());
91 assertEquals(PfConceptKey.class.getCanonicalName(), result.getMessageList().get(3).getObservedClass());
92 assertEquals(PfConceptKey.getNullKey(), result.getMessageList().get(3).getObservedKey());