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