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;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.introspection.Introspector;
35 import org.onap.aai.introspection.Loader;
36 import org.onap.aai.introspection.ModelType;
37 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
38 import org.springframework.test.annotation.DirtiesContext;
40 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
41 public class IntrospectorValidatorTest extends AAISetup {
43 private Loader loader;
45 private Introspector introspector;
46 private IntrospectorValidator.Builder b;
47 private IntrospectorValidator iv;
51 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
54 introspector = loader.introspectorFromName("pserver");
55 } catch (Exception e) {
56 fail("Introspector instantiation call threw an exception " + e);
58 b = new IntrospectorValidator.Builder();
61 b.addResolver(new IssueResolver() {
63 public boolean resolveIssue(Issue issue) {
67 // this method does nothing
68 iv.processPrimitiveList("TEST", introspector);
71 public void setupIssue(String message, IssueType type, String propName, Introspector introspector) {
72 issue.setDetail(message);
74 issue.setPropName(propName);
75 issue.setIntrospector(introspector);
79 public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
80 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
82 assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
86 public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
87 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
88 b.validateRequired(true);
89 assertTrue("Validation should be required", b.getValidateRequired());
93 public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException {
94 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
96 assertFalse("Not currently validated", iv.validate(introspector));
97 } catch (Exception e) {
98 fail("Introspector validate call threw an exception " + e);
103 public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException {
104 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
105 assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
109 public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException {
110 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
111 List<Issue> result = iv.getIssues();
112 Assert.assertNotNull(result);
117 public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException {
118 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
119 iv.processComplexObj(introspector);
120 Assert.assertNotNull(introspector);
124 public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException {
125 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
126 assertEquals("create complex list size should return 0", 0,
127 iv.createComplexListSize(introspector, introspector));
131 public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException {
132 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
133 assertNotNull("Get resolvers should not be null", b.getResolvers());