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