Update the aai-common with the latest code
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / introspection / validation / IntrospectorValidationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.aai.introspection.validation;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.List;
26
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Ignore;
30 import org.junit.Test;
31
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;
43
44 public class IntrospectorValidationTest {
45
46         
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;
51         @BeforeClass
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/");
56                 
57                 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
58
59         }
60         @Before
61         public void createValidator() {
62                 validator = new IntrospectorValidator.Builder()
63                                 .validateRequired(false)
64                                 .restrictDepth(10000)
65                                 .build();
66         }
67         @Test
68         public void verifySuccessWhenEmpty() throws AAIException {
69                 Introspector obj = loader.introspectorFromName("test-object");
70                 obj.setValue("vnf-id", "key1");
71                 validator.validate(obj);
72                 List<Issue> issues = validator.getIssues();
73                 assertEquals("no issues found", true, issues.isEmpty());
74         }
75
76         @Ignore
77         @Test
78         public void verifyRequiresSingleFieldFailure() throws AAIException {
79                 Introspector obj = loader.introspectorFromName("test-object");
80                 obj.setValue("vnf-id", "key1");
81                 obj.setValue("model-invariant-id", "id1");
82                 validator.validate(obj);
83                 List<Issue> issues = validator.getIssues();
84                 assertEquals("issues found", true, issues.size() == 1);
85                 Issue issue = issues.get(0);
86                 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
87         }
88         
89         @Test
90         public void verifyRequiresSuccess() throws AAIException {
91                 Introspector obj = loader.introspectorFromName("test-object");
92                 obj.setValue("vnf-id", "key1");
93                 obj.setValue("model-invariant-id", "id1");
94                 obj.setValue("model-version-id", "version-id1");
95                 validator.validate(obj);
96                 List<Issue> issues = validator.getIssues();
97                 assertEquals("no issues found", true, issues.isEmpty());
98         }
99 }