Fix all blocker sonar issues and some checkstyle
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / introspection / generator / CreateExampleTest.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.generator;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.aai.AAISetup;
35 import org.onap.aai.exceptions.AAIException;
36 import org.onap.aai.introspection.Introspector;
37 import org.onap.aai.introspection.Loader;
38 import org.onap.aai.introspection.ModelType;
39 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
40
41 public class CreateExampleTest extends AAISetup {
42
43     private static CreateExample createExample;
44     private Loader loader;
45
46     private static boolean classLoaded = false;
47
48     @BeforeClass
49     public static void setUp() {
50
51     }
52
53     @Before
54     public void createLoaderVersion() {
55         if (!classLoaded) {
56             loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
57             createExample = new CreateExample(loader, "edge-prop-names");
58             classLoaded = false;
59         }
60     }
61
62     @Test
63     public void testGetExampleObject() throws AAIException {
64         Introspector introspector = loader.introspectorFromName("edge-prop-names");
65         Introspector res = createExample.getExampleObject();
66         assertEquals(introspector.getName(), res.getName());
67     }
68
69     @Test
70     public void testProcessPrimitiveString() throws AAIUnknownObjectException {
71         String propName = "direction";
72         Introspector introspector = loader.introspectorFromName("edge-prop-names");
73         createExample.processPrimitive(propName, introspector);
74         assertEquals(introspector.getName(), "edge-prop-names");
75     }
76
77     @Test
78     public void testProcessPrimitiveLong() throws AAIUnknownObjectException {
79         String propName = "vlan-id-inner";
80         Introspector introspector = loader.introspectorFromName("ctag-assignment");
81         createExample.processPrimitive(propName, introspector);
82         assertEquals(introspector.getName(), "ctag-assignment");
83     }
84
85     @Test
86     public void testProcessPrimitiveBoolean() throws AAIUnknownObjectException {
87         String propName = "in-maint";
88         Introspector introspector = loader.introspectorFromName("vserver");
89         createExample.processPrimitive(propName, introspector);
90         assertEquals(introspector.getName(), "vserver");
91     }
92
93     @Test
94     public void testProcessPrimitiveInteger() throws AAIUnknownObjectException {
95         String propName = "module-index";
96         Introspector introspector = loader.introspectorFromName("vf-module");
97         createExample.processPrimitive(propName, introspector);
98         assertEquals(introspector.getName(), "vf-module");
99     }
100
101     @Test
102     public void testProcessPrimitiveList() throws AAIUnknownObjectException {
103         String propName = "ipaddress-v4-vig";
104         Introspector introspector = loader.introspectorFromName("vig-server");
105         assertEquals(introspector.getName(), "vig-server");
106     }
107
108     @Test
109     public void testProcessComplexObj() {
110         // empty method
111         Introspector introspector = Mockito.mock(Introspector.class);
112         createExample.processComplexObj(introspector);
113         assertNotNull(introspector);
114     }
115
116     @Test
117     public void testModifyComplexList() {
118         // empty method
119         List<Introspector> introList = new ArrayList<Introspector>();
120         List<Object> objList = new ArrayList<Object>();
121         Introspector introspector = Mockito.mock(Introspector.class);
122         createExample.modifyComplexList(introList, objList, introspector, introspector);
123         assertNotNull(introspector);
124     }
125
126     @Test
127     public void testCreateComplexObjIfNull() {
128         boolean res = createExample.createComplexObjIfNull();
129         assertTrue(res);
130     }
131
132     @Test
133     public void testCreateComplexListSize() {
134         Introspector introspector = Mockito.mock(Introspector.class);
135         int res = createExample.createComplexListSize(introspector, introspector);
136         assertEquals(1, res);
137     }
138
139 }