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.Ignore;
24 import org.junit.Test;
25 import org.onap.aai.AAISetup;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.*;
29 import org.onap.aai.introspection.tools.IntrospectorValidator;
30 import org.onap.aai.introspection.tools.Issue;
31 import org.onap.aai.introspection.tools.IssueType;
32 import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
33 import org.onap.aai.util.AAIConstants;
34 import org.springframework.beans.factory.annotation.Autowired;
36 import java.util.List;
38 import static org.junit.Assert.assertEquals;
40 public class IntrospectorValidationTest extends AAISetup {
42 private final static ModelType introspectorFactoryType = ModelType.MOXY;
43 private Loader loader;
44 private IntrospectorValidator validator;
46 private LoaderFactory loaderFactory;
49 public void createValidator() throws Exception {
50 System.setProperty("AJSC_HOME", ".");
51 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
52 loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getRelatedLinkVersion());
53 validator = new IntrospectorValidator.Builder()
54 .validateRequired(false)
60 public void verifySuccessWhenEmpty() throws AAIException {
61 Introspector obj = loader.introspectorFromName("generic-vnf");
62 obj.setValue("vnf-id", "key1");
63 validator.validate(obj);
64 List<Issue> issues = validator.getIssues();
65 assertEquals("no issues found", true, issues.isEmpty());
70 public void verifyRequiresSingleFieldFailure() throws AAIException {
71 Introspector obj = loader.introspectorFromName("generic-vnf");
72 obj.setValue("vnf-id", "key1");
73 obj.setValue("model-invariant-id", "id1");
74 validator.validate(obj);
75 List<Issue> issues = validator.getIssues();
76 assertEquals("issues found", true, issues.size() == 1);
77 Issue issue = issues.get(0);
78 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
82 public void verifyRequiresSuccess() throws AAIException {
83 Introspector obj = loader.introspectorFromName("generic-vnf");
84 obj.setValue("vnf-id", "key1");
85 obj.setValue("model-invariant-id", "id1");
86 obj.setValue("model-version-id", "version-id1");
87 validator.validate(obj);
88 List<Issue> issues = validator.getIssues();
89 assertEquals("no issues found", true, issues.isEmpty());