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