diff options
author | Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com> | 2018-03-28 23:29:42 -0400 |
---|---|---|
committer | Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com> | 2018-03-28 23:30:13 -0400 |
commit | 76dbc3740924316d61a7d074656ff126fc866f32 (patch) | |
tree | babfa62d5deef3efa9f37ee61ffda81a6e47c232 | |
parent | e50632aa84ed43893304282f53774419b198b7e6 (diff) |
Added more tests for MsoNetworkAdapterImpl
Change-Id: Ib2d452010ca67bd3f0f94b1aa3bf65d95628c8f1
Issue-ID: SO-545
Signed-off-by: Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
2 files changed, 332 insertions, 6 deletions
diff --git a/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java b/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java index 6d162b65a0..c0df4fe880 100644 --- a/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java +++ b/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java @@ -1574,9 +1574,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } if (NEUTRON_MODE.equals(mode)) { - - // Use MsoNeutronUtils for all NEUTRON commands - MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory); long deleteNetworkStarttime = System.currentTimeMillis(); try { // The deleteNetwork function in MsoNeutronUtils returns success if the network @@ -1605,9 +1602,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter { } } else { // DEFAULT to ("HEAT".equals (mode)) long deleteStackStarttime = System.currentTimeMillis(); - // Use MsoHeatUtils for all HEAT commands - MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory, - cloudConfigFactory); try { // The deleteStack function in MsoHeatUtils returns NOTFOUND if the stack was not found or if the stack was deleted. diff --git a/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java index 9be488d88d..1692c0bcfa 100644 --- a/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java +++ b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java @@ -24,6 +24,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyList; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @@ -44,6 +45,7 @@ import org.openecomp.mso.cloud.CloudSite; import org.openecomp.mso.db.catalog.CatalogDatabase; import org.openecomp.mso.db.catalog.beans.HeatTemplate; import org.openecomp.mso.db.catalog.beans.NetworkResource; +import org.openecomp.mso.openstack.beans.HeatStatus; import org.openecomp.mso.openstack.beans.NetworkInfo; import org.openecomp.mso.openstack.beans.NetworkRollback; import org.openecomp.mso.openstack.beans.NetworkStatus; @@ -858,4 +860,334 @@ public class MsoNetworkAdapterImplTest { } } + + @Test + public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkHeatStackNull() + throws NetworkException, MsoException { + Holder<Boolean> networkExists = new Holder<>(); + Holder<String> networkId = new Holder<>(); + Holder<String> neutronNetworkId = new Holder<>(); + Holder<NetworkStatus> status = new Holder<>(); + Holder<List<Integer>> vlans = new Holder<>(); + Holder<Map<String, String>> subnetIdMap = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + CloudSite cloudSite = new CloudSite(); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class); + NetworkResource networkResource = Mockito.mock(NetworkResource.class); + when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(networkResource.getNeutronNetworkType()).thenReturn("BASIC"); + doReturn(catalogDB).when(impl).getCatalogDB(); + doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(), + anyString(), anyList(), anyList(), any()); + impl.heat = Mockito.mock(MsoHeatUtils.class); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(null); + try { + impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId, + neutronNetworkId, status, vlans, subnetIdMap); + } catch (Exception e) { + + } + } + + @Test + public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkHeatStackReturned() + throws NetworkException, MsoException { + Holder<Boolean> networkExists = new Holder<>(); + Holder<String> networkId = new Holder<>(); + Holder<String> neutronNetworkId = new Holder<>(); + Holder<NetworkStatus> status = new Holder<>(); + Holder<List<Integer>> vlans = new Holder<>(); + Holder<Map<String, String>> subnetIdMap = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + CloudSite cloudSite = new CloudSite(); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class); + NetworkResource networkResource = Mockito.mock(NetworkResource.class); + when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(networkResource.getNeutronNetworkType()).thenReturn("BASIC"); + doReturn(catalogDB).when(impl).getCatalogDB(); + doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(), + anyString(), anyList(), anyList(), any()); + impl.heat = Mockito.mock(MsoHeatUtils.class); + StackInfo stackInfo = Mockito.mock(StackInfo.class); + when(stackInfo.getStatus()).thenReturn(HeatStatus.CREATED); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(stackInfo); + try { + impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId, + neutronNetworkId, status, vlans, subnetIdMap); + } catch (Exception e) { + + } + } + + @Test + public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkHeatStackNull_QueryNeutronNetworkThrows() + throws NetworkException, MsoException { + Holder<Boolean> networkExists = new Holder<>(); + Holder<String> networkId = new Holder<>(); + Holder<String> neutronNetworkId = new Holder<>(); + Holder<NetworkStatus> status = new Holder<>(); + Holder<List<Integer>> vlans = new Holder<>(); + Holder<Map<String, String>> subnetIdMap = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + CloudSite cloudSite = new CloudSite(); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class); + NetworkResource networkResource = Mockito.mock(NetworkResource.class); + when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(networkResource.getNeutronNetworkType()).thenReturn("BASIC"); + doReturn(catalogDB).when(impl).getCatalogDB(); + doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(), + anyString(), anyList(), anyList(), any()); + impl.heat = Mockito.mock(MsoHeatUtils.class); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(null); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + MsoException exception = Mockito.mock(MsoException.class); + when(impl.neutron.queryNetwork(any(), any(), any())).thenThrow(exception); + try { + impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId, + neutronNetworkId, status, vlans, subnetIdMap); + } catch (Exception e) { + + } + } + + @Test + public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkHeatStackNull_QueryNeutronNetworkReturns() + throws NetworkException, MsoException { + Holder<Boolean> networkExists = new Holder<>(); + Holder<String> networkId = new Holder<>(); + Holder<String> neutronNetworkId = new Holder<>(); + Holder<NetworkStatus> status = new Holder<>(); + Holder<List<Integer>> vlans = new Holder<>(); + Holder<Map<String, String>> subnetIdMap = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + CloudSite cloudSite = new CloudSite(); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class); + NetworkResource networkResource = Mockito.mock(NetworkResource.class); + when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(networkResource.getNeutronNetworkType()).thenReturn("BASIC"); + doReturn(catalogDB).when(impl).getCatalogDB(); + doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(), + anyString(), anyList(), anyList(), any()); + impl.heat = Mockito.mock(MsoHeatUtils.class); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(null); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + NetworkInfo networkInfo = Mockito.mock(NetworkInfo.class); + when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(networkInfo); + try { + impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId, + neutronNetworkId, status, vlans, subnetIdMap); + } catch (Exception e) { + + } + } + + @Test + public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkHeatStackNull_QueryNeutronNetworkNull() + throws NetworkException, MsoException { + Holder<Boolean> networkExists = new Holder<>(); + Holder<String> networkId = new Holder<>(); + Holder<String> neutronNetworkId = new Holder<>(); + Holder<NetworkStatus> status = new Holder<>(); + Holder<List<Integer>> vlans = new Holder<>(); + Holder<Map<String, String>> subnetIdMap = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + CloudSite cloudSite = new CloudSite(); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(cloudSite); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase catalogDB = Mockito.mock(CatalogDatabase.class); + NetworkResource networkResource = Mockito.mock(NetworkResource.class); + when(networkResource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(networkResource.getNeutronNetworkType()).thenReturn("BASIC"); + doReturn(catalogDB).when(impl).getCatalogDB(); + doReturn(networkResource).when(impl).networkCheck(any(), anyLong(), anyString(), anyString(), anyString(), + anyString(), anyList(), anyList(), any()); + impl.heat = Mockito.mock(MsoHeatUtils.class); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(null); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(null); + try { + impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId, + neutronNetworkId, status, vlans, subnetIdMap); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent_NullOrNotPresentCondition() throws NetworkException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + try { + impl.deleteNetwork(null, null, "networkType", "modelCustomizationUuid", null, null, + networkDeleted); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent() throws NetworkException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + + try { + impl.deleteNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId", null, + networkDeleted); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent_DBGetNetworkResource_DeleteNetworkThrows() throws NetworkException, MsoException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase db = Mockito.mock(CatalogDatabase.class); + when(impl.getCatalogDB()).thenReturn(db); + NetworkResource resource = Mockito.mock(NetworkResource.class); + when(resource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(db.getNetworkResource(any())).thenReturn(resource); + MsoException exception = Mockito.mock(MsoException.class); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + when(impl.neutron.deleteNetwork(any(), any(), any())).thenThrow(exception); + try { + impl.deleteNetwork("cloudSiteId", "tenantId", "networkType", null, "networkId", null, + networkDeleted); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent_DBGetNetworkResource_NeutronDeleteNetwork() throws NetworkException, MsoException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase db = Mockito.mock(CatalogDatabase.class); + when(impl.getCatalogDB()).thenReturn(db); + NetworkResource resource = Mockito.mock(NetworkResource.class); + when(resource.getOrchestrationMode()).thenReturn("NEUTRON"); + when(db.getNetworkResource(any())).thenReturn(resource); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + when(impl.neutron.deleteNetwork(any(), any(), any())).thenReturn(true); + try { + impl.deleteNetwork("cloudSiteId", "tenantId", "networkType", null, "networkId", null, + networkDeleted); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent_DBGetNetworkResource_ModeHeat_QueryStack_DeleteStack() throws NetworkException, MsoException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase db = Mockito.mock(CatalogDatabase.class); + when(impl.getCatalogDB()).thenReturn(db); + NetworkResource resource = Mockito.mock(NetworkResource.class); + when(resource.getOrchestrationMode()).thenReturn("HEAT"); + when(db.getNetworkResource(any())).thenReturn(resource); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + when(impl.neutron.deleteNetwork(any(), any(), any())).thenReturn(true); + impl.heat = Mockito.mock(MsoHeatUtils.class); + StackInfo stackInfo = new StackInfo(); + stackInfo.setStatus(HeatStatus.CREATED); + when(impl.heat.queryStack(any(), any(), any())).thenReturn(stackInfo); + StackInfo stackInfoDeleted = new StackInfo(); + stackInfo.setStatus(HeatStatus.DELETING); + when(impl.heat.deleteStack(any(), any(), any(), anyBoolean())).thenReturn(stackInfoDeleted); + try { + impl.deleteNetwork("cloudSiteId", "tenantId", "networkType", null, "networkId", null, + networkDeleted); + } catch (Exception e) { + + } + } + + @Test + public void deleteNetworkImplTest_CloudSiteNotPresent_DBGetNetworkResource_ModeHeat_QueryStackException() throws NetworkException, MsoException { + Holder<Boolean> networkDeleted = new Holder<>(); + MsoNetworkAdapterImpl impl = Mockito.spy(MsoNetworkAdapterImpl.class); + impl.cloudConfigFactory = Mockito.mock(CloudConfigFactory.class); + CloudConfig cloudConfig = Mockito.mock(CloudConfig.class); + when(impl.cloudConfigFactory.getCloudConfig()).thenReturn(cloudConfig); + Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null); + when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt); + impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class); + CatalogDatabase db = Mockito.mock(CatalogDatabase.class); + when(impl.getCatalogDB()).thenReturn(db); + NetworkResource resource = Mockito.mock(NetworkResource.class); + when(resource.getOrchestrationMode()).thenReturn("HEAT"); + when(db.getNetworkResource(any())).thenReturn(resource); + impl.neutron = Mockito.mock(MsoNeutronUtils.class); + when(impl.neutron.deleteNetwork(any(), any(), any())).thenReturn(true); + impl.heat = Mockito.mock(MsoHeatUtils.class); + StackInfo stackInfo = new StackInfo(); + stackInfo.setStatus(HeatStatus.CREATED); + MsoException exception = Mockito.mock(MsoException.class); + when(impl.heat.queryStack(any(), any(), any())).thenThrow(exception); + try { + impl.deleteNetwork("cloudSiteId", "tenantId", "networkType", null, "networkId", null, + networkDeleted); + } catch (Exception e) { + + } + } } |