AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / introspection / tools / InjectKeysFromURITest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.introspection.tools;
22
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;
28
29 import java.net.URI;
30
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;
37
38 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
39 public class InjectKeysFromURITest extends AAISetup {
40
41     private Loader loader;
42     private Issue issue;
43     private InjectKeysFromURI ik;
44
45     @Before
46     public void setup() {
47         loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
48         issue = new Issue();
49     }
50
51     @Test
52     public void testInjectKeysFromURIOfPserverIsNotResolved() throws AAIUnknownObjectException {
53         try {
54             ik = new InjectKeysFromURI(loader, new URI("/aai/v12/cloud-infrastructure/complexes"));
55         } catch (Exception e) {
56             fail("InjectKeys instantiation threw an exception");
57         }
58
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);
63
64         issue.setDetail("Some message");
65         issue.setType(IssueType.MISSING_KEY_PROP);
66         issue.setPropName("in-maint");
67         issue.setIntrospector(pserver);
68
69         Boolean issueResolved = ik.resolveIssue(issue);
70
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"));
74     }
75
76     @Test
77     public void testInjectKeysFromURIOfPserverSuccessfullyResolved() throws AAIUnknownObjectException {
78         try {
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");
82         }
83
84         Introspector pserver = loader.introspectorFromName("pserver");
85         assertNotNull("Unable to load the template introspector", pserver);
86
87         issue.setDetail("Some message");
88         issue.setType(IssueType.MISSING_KEY_PROP);
89         issue.setPropName("hostname");
90         issue.setIntrospector(pserver);
91
92         Boolean issueResolved = ik.resolveIssue(issue);
93
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"));
97     }
98
99 }