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
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.apex.model.basicmodel.concepts;
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.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;
35 public class ValidationTest {
39 AxValidationResult result = new AxValidationResult();
40 AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN");
41 result = refKey.validate(result);
43 assertNotNull(result);
44 assertTrue(result.isOk());
45 assertTrue(result.isValid());
46 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
47 assertNotNull(result.getMessageList());
49 AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
50 ValidationResult.VALID, "Some message");
51 result.addValidationMessage(vmess0);
53 assertTrue(result.isOk());
54 assertTrue(result.isValid());
55 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
56 assertNotNull(result.getMessageList());
57 assertNotNull("hello", result.toString());
59 AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
60 ValidationResult.OBSERVATION, "Some message");
61 result.addValidationMessage(vmess1);
63 assertTrue(result.isOk());
64 assertTrue(result.isValid());
65 assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
66 assertNotNull(result.getMessageList());
67 assertNotNull("hello", result.toString());
69 AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
70 ValidationResult.WARNING, "Some message");
71 result.addValidationMessage(vmess2);
73 assertFalse(result.isOk());
74 assertTrue(result.isValid());
75 assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
76 assertNotNull(result.getMessageList());
77 assertNotNull("hello", result.toString());
79 AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
80 ValidationResult.INVALID, "Some message");
81 result.addValidationMessage(vmess3);
83 assertFalse(result.isOk());
84 assertFalse(result.isValid());
85 assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
86 assertNotNull(result.getMessageList());
87 assertNotNull("hello", result.toString());
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());