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=========================================================
21 package org.onap.aai.introspection.validation;
23 import static org.junit.Assert.assertEquals;
25 import java.util.List;
27 import org.junit.Before;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.introspection.*;
33 import org.onap.aai.introspection.tools.IntrospectorValidator;
34 import org.onap.aai.introspection.tools.Issue;
35 import org.onap.aai.introspection.tools.IssueType;
36 import org.springframework.beans.factory.annotation.Autowired;
38 public class IntrospectorValidationTest extends AAISetup {
40 private final static ModelType introspectorFactoryType = ModelType.MOXY;
41 private Loader loader;
42 private IntrospectorValidator validator;
44 private LoaderFactory loaderFactory;
47 public void createValidator() throws Exception {
48 System.setProperty("AJSC_HOME", ".");
49 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
50 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getRelatedLinkVersion());
51 validator = new IntrospectorValidator.Builder().validateRequired(false).restrictDepth(10000).build();
56 public void verifySuccessWhenEmpty() throws AAIException {
57 Introspector obj = loader.introspectorFromName("generic-vnf");
58 obj.setValue("vnf-id", "key1");
59 validator.validate(obj);
60 List<Issue> issues = validator.getIssues();
61 assertEquals("no issues found", true, issues.isEmpty());
66 public void verifyRequiresSingleFieldFailure() throws AAIException {
67 Introspector obj = loader.introspectorFromName("generic-vnf");
68 obj.setValue("vnf-id", "key1");
69 obj.setValue("model-invariant-id", "id1");
70 validator.validate(obj);
71 List<Issue> issues = validator.getIssues();
72 assertEquals("issues found", true, issues.size() == 1);
73 Issue issue = issues.get(0);
74 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
79 public void verifyRequiresSuccess() throws AAIException {
80 Introspector obj = loader.introspectorFromName("generic-vnf");
81 obj.setValue("vnf-id", "key1");
82 obj.setValue("model-invariant-id", "id1");
83 obj.setValue("model-version-id", "version-id1");
84 validator.validate(obj);
85 List<Issue> issues = validator.getIssues();
86 assertEquals("no issues found", true, issues.isEmpty());