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;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.introspection.*;
35 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
36 import org.springframework.test.annotation.DirtiesContext;
38 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
39 public class InjectKeysFromURITest extends AAISetup {
41 private Loader loader;
43 private InjectKeysFromURI ik;
47 loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
52 public void testInjectKeysFromURIOfPserverIsNotResolved() throws AAIUnknownObjectException {
54 ik = new InjectKeysFromURI(loader, new URI("/aai/v12/cloud-infrastructure/complexes"));
55 } catch (Exception e) {
56 fail("InjectKeys instantiation threw an exception");
59 Introspector pserver = loader.introspectorFromName("pserver");
60 pserver.setValue("in-maint", false);
61 pserver.setValue("hostname", "pserver2");
62 assertNotNull("Unable to load the template introspector", pserver);
64 issue.setDetail("Some message");
65 issue.setType(IssueType.MISSING_KEY_PROP);
66 issue.setPropName("in-maint");
67 issue.setIntrospector(pserver);
69 Boolean issueResolved = ik.resolveIssue(issue);
71 assertFalse("Unable to resolve the pserver in-maint issue", issueResolved);
72 assertEquals("Introspector didn't successfully modify the pserver in-maint", false,
73 pserver.getValue("in-maint"));
77 public void testInjectKeysFromURIOfPserverSuccessfullyResolved() throws AAIUnknownObjectException {
79 ik = new InjectKeysFromURI(loader, new URI("/aai/v12/cloud-infrastructure/pservers/pserver/pserver1"));
80 } catch (Exception e) {
81 fail("InjectKeys instantiation threw an exception");
84 Introspector pserver = loader.introspectorFromName("pserver");
85 assertNotNull("Unable to load the template introspector", pserver);
87 issue.setDetail("Some message");
88 issue.setType(IssueType.MISSING_KEY_PROP);
89 issue.setPropName("hostname");
90 issue.setIntrospector(pserver);
92 Boolean issueResolved = ik.resolveIssue(issue);
94 assertTrue("Unable to resolve the pserver hostname default field issue", issueResolved);
95 assertEquals("Introspector didn't successfully modify the pserver hostname", "pserver1",
96 pserver.getValue("hostname"));