Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / introspection / validation / IntrospectorValidationTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.introspection.validation;
21
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.*;
28 import org.onap.aai.introspection.tools.IntrospectorValidator;
29 import org.onap.aai.introspection.tools.Issue;
30 import org.onap.aai.introspection.tools.IssueType;
31 import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
32 import org.onap.aai.util.AAIConstants;
33
34 import java.util.List;
35
36 import static org.junit.Assert.assertEquals;
37
38 public class IntrospectorValidationTest {
39
40         
41         private final static Version version = Version.v10;
42         private final static ModelType introspectorFactoryType = ModelType.MOXY;
43         private static Loader loader;
44         private IntrospectorValidator validator;
45         @BeforeClass
46         public static void setUp() throws NoSuchFieldException, SecurityException, Exception {
47                 System.setProperty("AJSC_HOME", ".");
48                 System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
49                 QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org.onap.aai/introspection/");
50                 
51                 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
52
53         }
54         @Before
55         public void createValidator() {
56                 validator = new IntrospectorValidator.Builder()
57                                 .validateRequired(false)
58                                 .restrictDepth(10000)
59                                 .build();
60         }
61         @Ignore
62         @Test
63         public void verifySuccessWhenEmpty() throws AAIException {
64                 Introspector obj = loader.introspectorFromName("generic-vnf");
65                 obj.setValue("vnf-id", "key1");
66                 validator.validate(obj);
67                 List<Issue> issues = validator.getIssues();
68                 assertEquals("no issues found", true, issues.isEmpty());
69         }
70
71         @Ignore
72         @Test
73         public void verifyRequiresSingleFieldFailure() throws AAIException {
74                 Introspector obj = loader.introspectorFromName("generic-vnf");
75                 obj.setValue("vnf-id", "key1");
76                 obj.setValue("model-invariant-id", "id1");
77                 validator.validate(obj);
78                 List<Issue> issues = validator.getIssues();
79                 assertEquals("issues found", true, issues.size() == 1);
80                 Issue issue = issues.get(0);
81                 assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
82         }
83         @Ignore
84         @Test
85         public void verifyRequiresSuccess() throws AAIException {
86                 Introspector obj = loader.introspectorFromName("generic-vnf");
87                 obj.setValue("vnf-id", "key1");
88                 obj.setValue("model-invariant-id", "id1");
89                 obj.setValue("model-version-id", "version-id1");
90                 validator.validate(obj);
91                 List<Issue> issues = validator.getIssues();
92                 assertEquals("no issues found", true, issues.isEmpty());
93         }
94 }