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