2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.introspection.validation;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.onap.aai.exceptions.AAIException;
29 import org.onap.aai.introspection.*;
30 import org.onap.aai.introspection.tools.IntrospectorValidator;
31 import org.onap.aai.introspection.tools.Issue;
32 import org.onap.aai.introspection.tools.IssueType;
33 import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
34 import org.onap.aai.util.AAIConstants;
36 import java.util.List;
38 import static org.junit.Assert.assertEquals;
40 public class IntrospectorValidationTest {
43 private final static Version version = Version.v10;
44 private final static ModelType introspectorFactoryType = ModelType.MOXY;
45 private static Loader loader;
46 private IntrospectorValidator validator;
48 public static void setUp() throws NoSuchFieldException, SecurityException, Exception {
49 System.setProperty("AJSC_HOME", ".");
50 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
51 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org.onap.aai/introspection/");
53 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
57 public void createValidator() {
58 validator = new IntrospectorValidator.Builder()
59 .validateRequired(false)
65 public void verifySuccessWhenEmpty() throws AAIException {
66 Introspector obj = loader.introspectorFromName("test-object");
67 obj.setValue("vnf-id", "key1");
68 validator.validate(obj);
69 List<Issue> issues = validator.getIssues();
70 assertEquals("no issues found", true, issues.isEmpty());
75 public void verifyRequiresSingleFieldFailure() throws AAIException {
76 Introspector obj = loader.introspectorFromName("test-object");
77 obj.setValue("vnf-id", "key1");
78 obj.setValue("model-invariant-id", "id1");
79 validator.validate(obj);
80 List<Issue> issues = validator.getIssues();
81 assertEquals("issues found", true, issues.size() == 1);
82 Issue issue = issues.get(0);
83 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
87 public void verifyRequiresSuccess() throws AAIException {
88 Introspector obj = loader.introspectorFromName("test-object");
89 obj.setValue("vnf-id", "key1");
90 obj.setValue("model-invariant-id", "id1");
91 obj.setValue("model-version-id", "version-id1");
92 validator.validate(obj);
93 List<Issue> issues = validator.getIssues();
94 assertEquals("no issues found", true, issues.isEmpty());