2 * ============LICENSE_START=======================================================
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
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.onap.aai.introspection.tools;
23 import static junit.framework.TestCase.assertNotNull;
24 import static org.eclipse.persistence.jpa.jpql.Assert.fail;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
29 import java.util.List;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.aai.AAISetup;
35 import org.onap.aai.introspection.Introspector;
36 import org.onap.aai.introspection.Loader;
37 import org.onap.aai.introspection.ModelType;
38 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
39 import org.springframework.test.annotation.DirtiesContext;
41 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
42 public class IntrospectorValidatorTest extends AAISetup {
44 private Loader loader;
46 private Introspector introspector;
47 private IntrospectorValidator.Builder b;
48 private IntrospectorValidator iv;
52 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
55 introspector = loader.introspectorFromName("pserver");
56 } catch (Exception e) {
57 fail("Introspector instantiation call threw an exception " + e);
59 b = new IntrospectorValidator.Builder();
62 b.addResolver(new IssueResolver() {
64 public boolean resolveIssue(Issue issue) {
68 // this method does nothing
69 iv.processPrimitiveList("TEST", introspector);
72 public void setupIssue(String message, IssueType type, String propName, Introspector introspector) {
73 issue.setDetail(message);
75 issue.setPropName(propName);
76 issue.setIntrospector(introspector);
80 public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
81 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
83 assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
87 public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
88 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
89 b.validateRequired(true);
90 assertTrue("Validation should be required", b.getValidateRequired());
94 public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException {
95 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
97 assertFalse("Not currently validated", iv.validate(introspector));
98 } catch (Exception e) {
99 fail("Introspector validate call threw an exception " + e);
104 public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException {
105 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
106 assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
110 public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException {
111 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
112 List<Issue> result = iv.getIssues();
113 Assert.assertNotNull(result);
118 public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException {
119 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
120 iv.processComplexObj(introspector);
121 Assert.assertNotNull(introspector);
125 public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException {
126 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
127 assertEquals("create complex list size should return 0", 0,
128 iv.createComplexListSize(introspector, introspector));
132 public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException {
133 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
134 assertNotNull("Get resolvers should not be null", b.getResolvers());