2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.introspection.validation;
23 import static org.junit.Assert.assertEquals;
25 import java.util.List;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Ignore;
30 import org.junit.Test;
32 import org.openecomp.aai.exceptions.AAIException;
33 import org.openecomp.aai.introspection.Introspector;
34 import org.openecomp.aai.introspection.Loader;
35 import org.openecomp.aai.introspection.LoaderFactory;
36 import org.openecomp.aai.introspection.ModelType;
37 import org.openecomp.aai.introspection.Version;
38 import org.openecomp.aai.introspection.tools.IntrospectorValidator;
39 import org.openecomp.aai.introspection.tools.Issue;
40 import org.openecomp.aai.introspection.tools.IssueType;
41 import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper;
42 import org.openecomp.aai.util.AAIConstants;
44 public class IntrospectorValidationTest {
47 private final static Version version = Version.v10;
48 private final static ModelType introspectorFactoryType = ModelType.MOXY;
49 private static Loader loader;
50 private IntrospectorValidator validator;
52 public static void setUp() throws NoSuchFieldException, SecurityException, Exception {
53 System.setProperty("AJSC_HOME", ".");
54 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
55 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/");
57 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
61 public void createValidator() {
62 validator = new IntrospectorValidator.Builder()
63 .validateRequired(false)
69 public void verifySuccessWhenEmpty() throws AAIException {
70 Introspector obj = loader.introspectorFromName("test-object");
71 obj.setValue("vnf-id", "key1");
72 validator.validate(obj);
73 List<Issue> issues = validator.getIssues();
74 assertEquals("no issues found", true, issues.isEmpty());
79 public void verifyRequiresSingleFieldFailure() throws AAIException {
80 Introspector obj = loader.introspectorFromName("test-object");
81 obj.setValue("vnf-id", "key1");
82 obj.setValue("model-invariant-id", "id1");
83 validator.validate(obj);
84 List<Issue> issues = validator.getIssues();
85 assertEquals("issues found", true, issues.size() == 1);
86 Issue issue = issues.get(0);
87 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
91 public void verifyRequiresSuccess() throws AAIException {
92 Introspector obj = loader.introspectorFromName("test-object");
93 obj.setValue("vnf-id", "key1");
94 obj.setValue("model-invariant-id", "id1");
95 obj.setValue("model-version-id", "version-id1");
96 validator.validate(obj);
97 List<Issue> issues = validator.getIssues();
98 assertEquals("no issues found", true, issues.isEmpty());