Spring-boot 3.1 update
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / introspection / tools / DefaultFieldsTest.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.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.introspection.Introspector;
32 import org.onap.aai.introspection.Loader;
33 import org.onap.aai.introspection.ModelType;
34 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
35 import org.springframework.test.annotation.DirtiesContext;
36
37 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
38 public class DefaultFieldsTest extends AAISetup {
39
40     private Loader loader;
41     private Issue issue;
42     private DefaultFields defaultFields;
43
44     @Before
45     public void setup() {
46         loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
47         issue = new Issue();
48         defaultFields = new DefaultFields();
49     }
50
51     @Test
52     public void testDefaultFieldOfPserverIsSucccessfullyResolved() throws AAIUnknownObjectException {
53
54         Introspector pserver = loader.introspectorFromName("pserver");
55         assertNotNull("Unable to load the template introspector", pserver);
56
57         issue.setDetail("Some message");
58         issue.setType(IssueType.MISSING_REQUIRED_PROP);
59         issue.setPropName("in-maint");
60         issue.setIntrospector(pserver);
61
62         boolean isResolved = defaultFields.resolveIssue(issue);
63
64         assertTrue("Unable to resolve the pserver in-maint default field issue", isResolved);
65         assertEquals("Introspector didn't successfully modify the pserver in-maint", false,
66                 pserver.getValue("in-maint"));
67     }
68
69     @Test
70     public void testDefaultFieldResolverShouldFailWhenResolveOnNonDefaultField() throws AAIUnknownObjectException {
71
72         Introspector pserver = loader.introspectorFromName("pserver");
73         assertNotNull("Unable to load the template introspector", pserver);
74
75         issue.setDetail("Some message");
76         issue.setType(IssueType.MISSING_REQUIRED_PROP);
77         issue.setPropName("hostname");
78         issue.setIntrospector(pserver);
79
80         boolean isResolved = defaultFields.resolveIssue(issue);
81
82         assertFalse("It shouldn't be resolving this issue as hostname is required key", isResolved);
83     }
84 }