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;
28 import static junit.framework.TestCase.assertNotNull;
29 import static org.eclipse.persistence.jpa.jpql.Assert.fail;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertTrue;
34 public class IntrospectorValidatorTest extends AAISetup {
36 private Loader loader;
38 private Introspector introspector;
39 private IntrospectorValidator.Builder b;
40 private IntrospectorValidator iv;
44 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
47 introspector = loader.introspectorFromName("pserver");
49 fail("Introspector instantiation call threw an exception " + e);
51 b = new IntrospectorValidator.Builder();
54 b.addResolver(new IssueResolver() {
56 public boolean resolveIssue(Issue issue) {
60 //this method does nothing
61 iv.processPrimitiveList("TEST",introspector);
64 public void setupIssue(String message, IssueType type, String propName, Introspector introspector){
65 issue.setDetail(message);
67 issue.setPropName(propName);
68 issue.setIntrospector(introspector);
72 public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
73 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
75 assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
79 public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
80 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
81 b.validateRequired(true);
82 assertTrue("Validation should be required", b.getValidateRequired());
86 public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException{
87 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
89 assertFalse("Not currently validated", iv.validate(introspector));
91 fail("Introspector validate call threw an exception " + e);
96 public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException{
97 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
98 assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
102 public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException{
103 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
108 public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException{
109 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
110 iv.processComplexObj(introspector);
114 public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException{
115 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
116 assertEquals("create complex list size should return 0", 0, iv.createComplexListSize(introspector, introspector));
120 public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException{
121 setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
122 assertNotNull("Get resolvers should not be null", b.getResolvers());