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