2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.introspection.validation;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.*;
28 import org.onap.aai.introspection.tools.IntrospectorValidator;
29 import org.onap.aai.introspection.tools.Issue;
30 import org.onap.aai.introspection.tools.IssueType;
31 import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
32 import org.onap.aai.util.AAIConstants;
34 import java.util.List;
36 import static org.junit.Assert.assertEquals;
38 public class IntrospectorValidationTest {
41 private final static Version version = Version.v10;
42 private final static ModelType introspectorFactoryType = ModelType.MOXY;
43 private static Loader loader;
44 private IntrospectorValidator validator;
46 public static void setUp() throws NoSuchFieldException, SecurityException, Exception {
47 System.setProperty("AJSC_HOME", ".");
48 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
49 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org.onap.aai/introspection/");
51 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
55 public void createValidator() {
56 validator = new IntrospectorValidator.Builder()
57 .validateRequired(false)
63 public void verifySuccessWhenEmpty() throws AAIException {
64 Introspector obj = loader.introspectorFromName("generic-vnf");
65 obj.setValue("vnf-id", "key1");
66 validator.validate(obj);
67 List<Issue> issues = validator.getIssues();
68 assertEquals("no issues found", true, issues.isEmpty());
73 public void verifyRequiresSingleFieldFailure() throws AAIException {
74 Introspector obj = loader.introspectorFromName("generic-vnf");
75 obj.setValue("vnf-id", "key1");
76 obj.setValue("model-invariant-id", "id1");
77 validator.validate(obj);
78 List<Issue> issues = validator.getIssues();
79 assertEquals("issues found", true, issues.size() == 1);
80 Issue issue = issues.get(0);
81 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
85 public void verifyRequiresSuccess() throws AAIException {
86 Introspector obj = loader.introspectorFromName("generic-vnf");
87 obj.setValue("vnf-id", "key1");
88 obj.setValue("model-invariant-id", "id1");
89 obj.setValue("model-version-id", "version-id1");
90 validator.validate(obj);
91 List<Issue> issues = validator.getIssues();
92 assertEquals("no issues found", true, issues.isEmpty());