Sync the latest code changes
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.introspection.validation;
23
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;
35
36 import java.util.List;
37
38 import static org.junit.Assert.assertEquals;
39
40 public class IntrospectorValidationTest {
41
42         
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;
47         @BeforeClass
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/");
52                 
53                 loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
54
55         }
56         @Before
57         public void createValidator() {
58                 validator = new IntrospectorValidator.Builder()
59                                 .validateRequired(false)
60                                 .restrictDepth(10000)
61                                 .build();
62         }
63         @Ignore
64         @Test
65         public void verifySuccessWhenEmpty() throws AAIException {
66                 Introspector obj = loader.introspectorFromName("generic-vnf");
67                 obj.setValue("vnf-id", "key1");
68                 validator.validate(obj);
69                 List<Issue> issues = validator.getIssues();
70                 assertEquals("no issues found", true, issues.isEmpty());
71         }
72
73         @Ignore
74         @Test
75         public void verifyRequiresSingleFieldFailure() throws AAIException {
76                 Introspector obj = loader.introspectorFromName("generic-vnf");
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());
84         }
85         @Ignore
86         @Test
87         public void verifyRequiresSuccess() throws AAIException {
88                 Introspector obj = loader.introspectorFromName("generic-vnf");
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());
95         }
96 }