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=========================================================
20 package org.onap.aai.introspection.tools;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.onap.aai.AAISetup;
25 import org.onap.aai.introspection.*;
26 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
27 import org.springframework.test.annotation.DirtiesContext;
29 import static junit.framework.TestCase.assertNotNull;
30 import static org.eclipse.persistence.jpa.jpql.Assert.fail;
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertFalse;
33 import static org.junit.Assert.assertTrue;
35 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
36 public class IntrospectorValidatorTest extends AAISetup {
38 private Loader loader;
40 private Introspector introspector;
41 private IntrospectorValidator.Builder b;
42 private IntrospectorValidator iv;
46 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
49 introspector = loader.introspectorFromName("pserver");
51 fail("Introspector instantiation call threw an exception " + e);
53 b = new IntrospectorValidator.Builder();
56 b.addResolver(new IssueResolver() {
58 public boolean resolveIssue(Issue issue) {
62 //this method does nothing
63 iv.processPrimitiveList("TEST",introspector);
66 public void setupIssue(String message, IssueType type, String propName, Introspector introspector){
67 issue.setDetail(message);
69 issue.setPropName(propName);
70 issue.setIntrospector(introspector);
74 public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
75 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
77 assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
81 public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
82 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
83 b.validateRequired(true);
84 assertTrue("Validation should be required", b.getValidateRequired());
88 public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException{
89 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
91 assertFalse("Not currently validated", iv.validate(introspector));
93 fail("Introspector validate call threw an exception " + e);
98 public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException{
99 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
100 assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
104 public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException{
105 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
110 public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException{
111 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
112 iv.processComplexObj(introspector);
116 public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException{
117 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
118 assertEquals("create complex list size should return 0", 0, iv.createComplexListSize(introspector, introspector));
122 public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException{
123 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
124 assertNotNull("Get resolvers should not be null", b.getResolvers());