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 org.junit.Before;
30 import org.junit.Test;
31 import org.onap.aai.AAISetup;
32 import org.onap.aai.introspection.*;
33 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
34 import org.springframework.test.annotation.DirtiesContext;
36 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
37 public class IntrospectorValidatorTest extends AAISetup {
39 private Loader loader;
41 private Introspector introspector;
42 private IntrospectorValidator.Builder b;
43 private IntrospectorValidator iv;
47 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
50 introspector = loader.introspectorFromName("pserver");
51 } catch (Exception e) {
52 fail("Introspector instantiation call threw an exception " + e);
54 b = new IntrospectorValidator.Builder();
57 b.addResolver(new IssueResolver() {
59 public boolean resolveIssue(Issue issue) {
63 // this method does nothing
64 iv.processPrimitiveList("TEST", introspector);
67 public void setupIssue(String message, IssueType type, String propName, Introspector introspector) {
68 issue.setDetail(message);
70 issue.setPropName(propName);
71 issue.setIntrospector(introspector);
75 public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
76 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
78 assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
82 public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
83 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
84 b.validateRequired(true);
85 assertTrue("Validation should be required", b.getValidateRequired());
89 public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException {
90 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
92 assertFalse("Not currently validated", iv.validate(introspector));
93 } catch (Exception e) {
94 fail("Introspector validate call threw an exception " + e);
99 public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException {
100 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
101 assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
105 public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException {
106 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
111 public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException {
112 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
113 iv.processComplexObj(introspector);
117 public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException {
118 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
119 assertEquals("create complex list size should return 0", 0,
120 iv.createComplexListSize(introspector, introspector));
124 public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException {
125 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
126 assertNotNull("Get resolvers should not be null", b.getResolvers());