9be488d88dbebbfd4226cba8df041b489929e665
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 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.openecomp.mso.adapters.network;
22
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Matchers.anyList;
25 import static org.mockito.Matchers.anyLong;
26 import static org.mockito.Matchers.anyString;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.when;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Optional;
35
36 import javax.xml.ws.Holder;
37
38 import org.junit.Test;
39 import org.mockito.Mockito;
40 import org.openecomp.mso.adapters.network.exceptions.NetworkException;
41 import org.openecomp.mso.cloud.CloudConfig;
42 import org.openecomp.mso.cloud.CloudConfigFactory;
43 import org.openecomp.mso.cloud.CloudSite;
44 import org.openecomp.mso.db.catalog.CatalogDatabase;
45 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
46 import org.openecomp.mso.db.catalog.beans.NetworkResource;
47 import org.openecomp.mso.openstack.beans.NetworkInfo;
48 import org.openecomp.mso.openstack.beans.NetworkRollback;
49 import org.openecomp.mso.openstack.beans.NetworkStatus;
50 import org.openecomp.mso.openstack.beans.StackInfo;
51 import org.openecomp.mso.openstack.beans.Subnet;
52 import org.openecomp.mso.openstack.exceptions.MsoException;
53 import org.openecomp.mso.openstack.utils.MsoHeatUtils;
54 import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
55 import org.openecomp.mso.openstack.utils.MsoNeutronUtils;
56 import org.openecomp.mso.properties.MsoJavaProperties;
57 import org.openecomp.mso.properties.MsoPropertiesException;
58 import org.openecomp.mso.properties.MsoPropertiesFactory;
59
60 public class MsoNetworkAdapterImplTest {
61
62         @Test
63         public void createNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
64                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
65                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
66                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
67                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
68                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null);
69                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
70                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
71                 try {
72                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
73                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
74                 } catch (Exception e) {
75
76                 }
77         }
78
79         @Test
80         public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
81                         throws NetworkException, MsoException {
82                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
83                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
84                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
85                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
86                 CloudSite cloudSite = new CloudSite();
87                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
88                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
89                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
90                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
91                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
92                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
93                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
94                 doReturn(catalogDB).when(impl).getCatalogDB();
95                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
96                                 anyString(), anyList(), anyList(), any());
97                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
98                 MsoException exception = Mockito.mock(MsoException.class);
99                 when(impl.neutron.queryNetwork(any(), any(), any())).thenThrow(exception);
100                 try {
101                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
102                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
103                 } catch (Exception e) {
104
105                 }
106         }
107
108         @Test
109         public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkExists_FailIfExistsTrue()
110                         throws NetworkException, MsoException {
111                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
112                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
113                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
114                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
115                 CloudSite cloudSite = new CloudSite();
116                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
117                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
118                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
119                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
120                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
121                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
122                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
123                 doReturn(catalogDB).when(impl).getCatalogDB();
124                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
125                                 anyString(), anyList(), anyList(), any());
126                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
127                 NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
128                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
129                 try {
130                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
131                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
132                 } catch (Exception e) {
133
134                 }
135         }
136
137         @Test
138         public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkExists_FailIfExistsNotTrue()
139                         throws NetworkException, MsoException {
140                 Holder<String> networkId = new Holder<>();
141                 Holder<String> neutronNetworkId = new Holder<>();
142                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
143                 Holder<NetworkRollback> rollback = new Holder<>();
144                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
145                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
146                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
147                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
148                 CloudSite cloudSite = new CloudSite();
149                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
150                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
151                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
152                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
153                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
154                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
155                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
156                 doReturn(catalogDB).when(impl).getCatalogDB();
157                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
158                                 anyString(), anyList(), anyList(), any());
159                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
160                 NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
161                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
162                 try {
163                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
164                                         "physicalNetworkName", null, false, true, null, null, networkId, neutronNetworkId, subnetIdMap,
165                                         rollback);
166                 } catch (Exception e) {
167
168                 }
169         }
170
171         @Test
172         public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoDoesntExist_CreateNetworkException()
173                         throws NetworkException, MsoException {
174                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
175                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
176                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
177                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
178                 CloudSite cloudSite = new CloudSite();
179                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
180                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
181                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
182                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
183                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
184                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
185                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
186                 doReturn(catalogDB).when(impl).getCatalogDB();
187                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
188                                 anyString(), anyList(), anyList(), any());
189                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
190                 NetworkInfo netInfo = null;
191                 MsoException exception = Mockito.mock(MsoException.class);
192                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
193                 when(impl.neutron.createNetwork(any(), any(), any(), any(), any(), any())).thenThrow(exception);
194                 try {
195                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
196                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
197                 } catch (Exception e) {
198
199                 }
200         }
201
202         @Test
203         public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoDoesntExist_CreateNetwork()
204                         throws NetworkException, MsoException {
205                 Holder<String> networkId = new Holder<>();
206                 Holder<String> neutronNetworkId = new Holder<>();
207                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
208                 Holder<NetworkRollback> rollback = new Holder<>();
209                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
210                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
211                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
212                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
213                 CloudSite cloudSite = new CloudSite();
214                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
215                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
216                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
217                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
218                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
219                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
220                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
221                 doReturn(catalogDB).when(impl).getCatalogDB();
222                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
223                                 anyString(), anyList(), anyList(), any());
224                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
225                 NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
226                 when(netInfo.getId()).thenReturn("Id");
227                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(null);
228                 when(impl.neutron.createNetwork(any(), any(), any(), any(), any(), anyList())).thenReturn(netInfo);
229                 try {
230                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
231                                         "physicalNetworkName", null, true, true, null, null, networkId, neutronNetworkId, subnetIdMap,
232                                         rollback);
233                 } catch (Exception e) {
234
235                 }
236         }
237
238         @Test
239         public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoExists()
240                         throws NetworkException, MsoException {
241                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
242                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
243                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
244                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
245                 CloudSite cloudSite = new CloudSite();
246                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
247                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
248                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
249                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
250                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
251                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
252                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
253                 doReturn(catalogDB).when(impl).getCatalogDB();
254                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
255                                 anyString(), anyList(), anyList(), any());
256                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
257                 NetworkInfo netInfo = null;
258                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
259                 try {
260                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
261                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
262                 } catch (Exception e) {
263
264                 }
265         }
266
267         @Test
268         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNull() throws NetworkException {
269                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
270                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
271                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
272                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
273                 CloudSite cloudSite = new CloudSite();
274                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
275                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
276                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
277                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
278                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
279                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
280                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
281                 doReturn(catalogDB).when(impl).getCatalogDB();
282                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
283                                 anyString(), anyList(), anyList(), any());
284                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
285                 try {
286                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
287                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
288                 } catch (Exception e) {
289
290                 }
291         }
292
293         @Test
294         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_ThrowMsoPropsException()
295                         throws NetworkException, MsoPropertiesException {
296                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
297                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
298                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
299                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
300                 CloudSite cloudSite = new CloudSite();
301                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
302                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
303                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
304                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
305                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
306                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
307                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
308                 doReturn(catalogDB).when(impl).getCatalogDB();
309                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
310                                 anyString(), anyList(), anyList(), any());
311                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
312                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
313                 when(heatTemplate.toString()).thenReturn("heatTemplate");
314                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplate");
315                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
316                 MsoPropertiesException exception = Mockito.mock(MsoPropertiesException.class);
317                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenThrow(exception);
318                 try {
319                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
320                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
321                 } catch (Exception e) {
322
323                 }
324         }
325
326         @Test
327         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull()
328                         throws NetworkException, MsoPropertiesException {
329                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
330                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
331                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
332                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
333                 CloudSite cloudSite = new CloudSite();
334                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
335                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
336                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
337                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
338                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
339                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
340                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
341                 doReturn(catalogDB).when(impl).getCatalogDB();
342                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
343                                 anyString(), anyList(), anyList(), any());
344                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
345                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
346                 when(heatTemplate.toString()).thenReturn("heatTemplate");
347                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
348                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
349                 MsoPropertiesException exception = Mockito.mock(MsoPropertiesException.class);
350                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
351                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
352                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
353                 try {
354                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
355                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
356                 } catch (Exception e) {
357
358                 }
359         }
360
361         @Test
362         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStackThrowsException()
363                         throws NetworkException, MsoPropertiesException, MsoException {
364                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
365                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
366                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
367                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
368                 CloudSite cloudSite = new CloudSite();
369                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
370                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
371                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
372                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
373                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
374                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
375                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
376                 doReturn(catalogDB).when(impl).getCatalogDB();
377                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
378                                 anyString(), anyList(), anyList(), any());
379                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
380                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
381                 when(heatTemplate.toString()).thenReturn("heatTemplate");
382                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
383                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
384                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
385                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
386                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
387                 MsoException exception = Mockito.mock(MsoException.class);
388                 impl.heat = Mockito.mock(MsoHeatUtils.class);
389                 when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenThrow(exception);
390                 try {
391                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
392                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
393                 } catch (Exception e) {
394
395                 }
396         }
397
398         @Test
399         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNull()
400                         throws NetworkException, MsoPropertiesException, MsoException {
401                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
402                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
403                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
404                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
405                 CloudSite cloudSite = new CloudSite();
406                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
407                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
408                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
409                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
410                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
411                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
412                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
413                 doReturn(catalogDB).when(impl).getCatalogDB();
414                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
415                                 anyString(), anyList(), anyList(), any());
416                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
417                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
418                 when(heatTemplate.toString()).thenReturn("heatTemplate");
419                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
420                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
421                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
422                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
423                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
424                 StackInfo heatStack = null;
425                 impl.heat = Mockito.mock(MsoHeatUtils.class);
426                 when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
427                 try {
428                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
429                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
430                 } catch (Exception e) {
431
432                 }
433         }
434
435         @Test
436         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_FailIfExists()
437                         throws NetworkException, MsoPropertiesException, MsoException {
438                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
439                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
440                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
441                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
442                 CloudSite cloudSite = new CloudSite();
443                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
444                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
445                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
446                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
447                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
448                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
449                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
450                 doReturn(catalogDB).when(impl).getCatalogDB();
451                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
452                                 anyString(), anyList(), anyList(), any());
453                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
454                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
455                 when(heatTemplate.toString()).thenReturn("heatTemplate");
456                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
457                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
458                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
459                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
460                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
461                 StackInfo heatStack = Mockito.mock(StackInfo.class);
462                 impl.heat = Mockito.mock(MsoHeatUtils.class);
463                 when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
464                 try {
465                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
466                                         "physicalNetworkName", null, true, true, null, null, null, null, null, null);
467                 } catch (Exception e) {
468
469                 }
470         }
471
472         @Test
473         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_DontFailIfExists()
474                         throws NetworkException, MsoPropertiesException, MsoException {
475                 Holder<String> networkId = new Holder<>();
476                 Holder<String> neutronNetworkId = new Holder<>();
477                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
478                 Holder<NetworkRollback> rollback = new Holder<>();
479                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
480                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
481                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
482                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
483                 CloudSite cloudSite = new CloudSite();
484                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
485                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
486                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
487                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
488                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
489                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
490                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
491                 doReturn(catalogDB).when(impl).getCatalogDB();
492                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
493                                 anyString(), anyList(), anyList(), any());
494                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
495                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
496                 when(heatTemplate.toString()).thenReturn("heatTemplate");
497                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
498                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
499                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
500                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
501                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
502                 StackInfo heatStack = Mockito.mock(StackInfo.class);
503                 Map<String, Object> outputs = new HashMap<>();
504                 outputs.put("subnet", "");
505                 when(heatStack.getOutputs()).thenReturn(outputs);
506                 impl.heat = Mockito.mock(MsoHeatUtils.class);
507                 when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
508                 try {
509                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
510                                         "physicalNetworkName", null, false, true, null, null, networkId, neutronNetworkId, subnetIdMap,
511                                         rollback);
512                 } catch (Exception e) {
513
514                 }
515         }
516
517         @Test
518         public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_DontFailIfExists_Validate()
519                         throws NetworkException, MsoPropertiesException, MsoException {
520                 List<Subnet> subnets = new ArrayList<>();
521                 Holder<String> networkId = new Holder<>();
522                 Holder<String> neutronNetworkId = new Holder<>();
523                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
524                 Holder<NetworkRollback> rollback = new Holder<>();
525                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
526                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
527                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
528                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
529                 CloudSite cloudSite = new CloudSite();
530                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
531                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
532                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
533                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
534                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
535                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
536                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
537                 doReturn(catalogDB).when(impl).getCatalogDB();
538                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
539                                 anyString(), anyList(), anyList(), any());
540                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
541                 HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
542                 when(heatTemplate.toString()).thenReturn("heatTemplate");
543                 when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
544                 when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
545                 MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
546                 when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
547                 when(props.getProperty(anyString(), anyString())).thenReturn("aic");
548                 StackInfo heatStack = Mockito.mock(StackInfo.class);
549                 Map<String, Object> outputs = new HashMap<>();
550                 outputs.put("subnet", "");
551                 when(heatStack.getOutputs()).thenReturn(outputs);
552                 impl.heat = Mockito.mock(MsoHeatUtils.class);
553                 when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
554                 try {
555                         impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
556                                         "physicalNetworkName", null, false, true, subnets, null, networkId, neutronNetworkId, subnetIdMap,
557                                         rollback);
558                 } catch (Exception e) {
559
560                 }
561         }
562
563         @Test
564         public void updateNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
565                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
566                 Holder<NetworkRollback> rollback = new Holder<>();
567                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
568                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
569                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
570                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
571                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null);
572                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
573                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
574                 try {
575                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
576                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
577                 } catch (Exception e) {
578
579                 }
580         }
581
582         @Test
583         public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
584                         throws NetworkException, MsoException {
585                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
586                 Holder<NetworkRollback> rollback = new Holder<>();
587                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
588                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
589                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
590                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
591                 CloudSite cloudSite = new CloudSite();
592                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
593                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
594                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
595                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
596                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
597                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
598                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
599                 doReturn(catalogDB).when(impl).getCatalogDB();
600                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
601                                 anyString(), anyList(), anyList(), any());
602                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
603                 MsoException exception = Mockito.mock(MsoException.class);
604                 when(impl.neutron.queryNetwork(any(), any(), any())).thenThrow(exception);
605                 try {
606                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
607                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
608                 } catch (Exception e) {
609
610                 }
611         }
612
613         @Test
614         public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkReturnsNull()
615                         throws NetworkException, MsoException {
616                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
617                 Holder<NetworkRollback> rollback = new Holder<>();
618                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
619                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
620                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
621                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
622                 CloudSite cloudSite = new CloudSite();
623                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
624                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
625                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
626                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
627                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
628                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
629                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
630                 doReturn(catalogDB).when(impl).getCatalogDB();
631                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
632                                 anyString(), anyList(), anyList(), any());
633                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
634                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(null);
635                 try {
636                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
637                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
638                 } catch (Exception e) {
639
640                 }
641         }
642
643         @Test
644         public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkDoesntExist_UpdateNetworkException()
645                         throws NetworkException, MsoException {
646                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
647                 Holder<NetworkRollback> rollback = new Holder<>();
648                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
649                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
650                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
651                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
652                 CloudSite cloudSite = new CloudSite();
653                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
654                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
655                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
656                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
657                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
658                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
659                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
660                 doReturn(catalogDB).when(impl).getCatalogDB();
661                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
662                                 anyString(), anyList(), anyList(), any());
663                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
664                 NetworkInfo netInfo = new NetworkInfo(null);
665                 MsoException exception = Mockito.mock(MsoException.class);
666                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
667                 when(impl.neutron.updateNetwork(any(), any(), any(), any(), any(), anyList())).thenThrow(exception);
668                 try {
669                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
670                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
671                 } catch (Exception e) {
672
673                 }
674         }
675
676         @Test
677         public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkDoesntExist_UpdateNetwork()
678                         throws NetworkException, MsoException {
679                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
680                 Holder<NetworkRollback> rollback = new Holder<>();
681                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
682                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
683                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
684                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
685                 CloudSite cloudSite = new CloudSite();
686                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
687                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
688                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
689                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
690                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
691                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
692                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
693                 doReturn(catalogDB).when(impl).getCatalogDB();
694                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
695                                 anyString(), anyList(), anyList(), any());
696                 impl.neutron = Mockito.mock(MsoNeutronUtils.class);
697                 NetworkInfo netInfo = new NetworkInfo(null);
698                 NetworkInfo mockedNetworkInfo = Mockito.mock(NetworkInfo.class);
699                 when(mockedNetworkInfo.getId()).thenReturn("Id");
700                 when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
701                 when(impl.neutron.updateNetwork(any(), any(), any(), any(), any(), anyList())).thenReturn(mockedNetworkInfo);
702                 try {
703                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
704                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
705                 } catch (Exception e) {
706
707                 }
708         }
709
710         @Test
711         public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackThrowException()
712                         throws NetworkException, MsoException {
713                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
714                 Holder<NetworkRollback> rollback = new Holder<>();
715                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
716                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
717                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
718                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
719                 CloudSite cloudSite = new CloudSite();
720                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
721                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
722                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
723                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
724                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
725                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
726                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
727                 doReturn(catalogDB).when(impl).getCatalogDB();
728                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
729                                 anyString(), anyList(), anyList(), any());
730                 impl.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
731                 MsoException exception = Mockito.mock(MsoException.class);
732                 when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenThrow(exception);
733                 try {
734                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
735                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
736                 } catch (Exception e) {
737
738                 }
739         }
740
741         @Test
742         public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackReturnNull()
743                         throws NetworkException, MsoException {
744                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
745                 Holder<NetworkRollback> rollback = new Holder<>();
746                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
747                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
748                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
749                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
750                 CloudSite cloudSite = new CloudSite();
751                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
752                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
753                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
754                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
755                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
756                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
757                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
758                 doReturn(catalogDB).when(impl).getCatalogDB();
759                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
760                                 anyString(), anyList(), anyList(), any());
761                 impl.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
762                 MsoException exception = Mockito.mock(MsoException.class);
763                 when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenReturn(null);
764                 try {
765                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
766                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
767                 } catch (Exception e) {
768
769                 }
770         }
771
772         @Test
773         public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackReturnInfo()
774                         throws NetworkException, MsoException {
775                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
776                 Holder<NetworkRollback> rollback = new Holder<>();
777                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
778                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
779                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
780                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
781                 CloudSite cloudSite = new CloudSite();
782                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
783                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
784                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
785                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
786                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
787                 when(networkResource.getOrchestrationMode()).thenReturn("HEAT");
788                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
789                 doReturn(catalogDB).when(impl).getCatalogDB();
790                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
791                                 anyString(), anyList(), anyList(), any());
792                 impl.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
793                 MsoException exception = Mockito.mock(MsoException.class);
794                 StackInfo stackInfo = Mockito.mock(StackInfo.class);
795                 when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenReturn(stackInfo);
796                 try {
797                         impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
798                                         "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
799                 } catch (Exception e) {
800
801                 }
802         }
803
804         @Test
805         public void queryNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
806                 Holder<Boolean> networkExists = new Holder<>();
807                 Holder<String> networkId = new Holder<>();
808                 Holder<String> neutronNetworkId = new Holder<>();
809                 Holder<NetworkStatus> status = new Holder<>();
810                 Holder<List<Integer>> vlans = new Holder<>();
811                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
812                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
813                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
814                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
815                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
816                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null);
817                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
818                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
819                 try {
820                         impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId,
821                                         neutronNetworkId, status, vlans, subnetIdMap);
822                 } catch (Exception e) {
823
824                 }
825         }
826
827         @Test
828         public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
829                         throws NetworkException, MsoException {
830                 Holder<Boolean> networkExists = new Holder<>();
831                 Holder<String> networkId = new Holder<>();
832                 Holder<String> neutronNetworkId = new Holder<>();
833                 Holder<NetworkStatus> status = new Holder<>();
834                 Holder<List<Integer>> vlans = new Holder<>();
835                 Holder<Map<String, String>> subnetIdMap = new Holder<>();
836                 MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class);
837                 impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
838                 CloudConfig cloudConfig = Mockito.mock(CloudConfig.class);
839                 when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig);
840                 CloudSite cloudSite = new CloudSite();
841                 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite);
842                 when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
843                 impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
844                 CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class);
845                 NetworkResource networkResource = Mockito.mock(NetworkResource.class);
846                 when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON");
847                 when(networkResource.getNeutronNetworkType()).thenReturn("BASIC");
848                 doReturn(catalogDB).when(impl).getCatalogDB();
849                 doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(),
850                                 anyString(), anyList(), anyList(), any());
851                 impl.heat = Mockito.mock(MsoHeatUtils.class);
852                 MsoException exception = Mockito.mock(MsoException.class);
853                 when(impl.heat.queryStack(any(), any(), any())).thenThrow(exception);
854                 try {
855                         impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId,
856                                         neutronNetworkId, status, vlans, subnetIdMap);
857                 } catch (Exception e) {
858
859                 }
860         }
861 }