aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java7
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java7
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java6
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java14
-rw-r--r--adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java6
-rw-r--r--adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java332
-rw-r--r--adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java2
7 files changed, 355 insertions, 19 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java
index 821522fedc..da4aebd3d9 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
-@RunWith(PowerMockRunner.class)
+//@RunWith(PowerMockRunner.class)
@PrepareForTest({MsoCloudifyUtils.class})
@@ -109,14 +109,15 @@ public class MsoCloudifyUtilsTest {
@Test(expected = MsoCloudifyManagerNotFound.class)
public void testCloudifyClient() throws MsoException {
-
+ msoPropertiesFactory = mock(MsoPropertiesFactory.class);
+ cloudConfigFactory = mock(CloudConfigFactory.class);
+ cloudSite = mock(CloudSite.class);
MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
mcu.getCloudifyClient(cloudSite);
assert (mcu.getCloudifyClient(cloudSite) != null);
}
-
@Test(expected = NullPointerException.class)
public void testuploadBlueprint() throws MsoException {
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java
index c50ffb03ef..9ba9b2f39d 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java
@@ -44,30 +44,25 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.doReturn;
-@RunWith(PowerMockRunner.class)
+//@RunWith(PowerMockRunner.class)
@PrepareForTest({MsoHeatUtils.class})
public class MsoHeatUtilsTest {
@Mock
-
StackInfo stackInfo;
@Mock
-
MsoPropertiesFactory msoPropertiesFactory;
@Mock
-
CloudConfigFactory cloudConfigFactory;
@Mock
-
Heat heatClient;
@Mock
-
CloudSite cloudSite;
@Test(expected = NullPointerException.class)
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
index 41126759ef..3e4758a8a2 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtilsTest.java
@@ -44,7 +44,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import com.woorea.openstack.keystone.Keystone;
import com.woorea.openstack.keystone.model.Tenant;
-@RunWith(PowerMockRunner.class)
+//@RunWith(PowerMockRunner.class)
@PrepareForTest({MsoKeystoneUtils.class,CloudSite.class,CloudIdentity.class,Tenant.class,Keystone.class,MsoTenant.class,MsoJavaProperties.class})
public class MsoKeystoneUtilsTest {
@@ -71,6 +71,7 @@ public class MsoKeystoneUtilsTest {
MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
+ tenant = mock(Tenant.class);
PowerMockito.when(tenant.getId ()).thenReturn("ID");
doReturn(tenant.getId ()).when(msk).createTenant("tenantName", "cloudSiteId", metadata, true);
PowerMockito.spy(tenant.getId ());
@@ -95,6 +96,7 @@ public class MsoKeystoneUtilsTest {
MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
+ mst = mock(MsoTenant.class);
PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
PowerMockito.when(mst.getTenantName()).thenReturn("name");
@@ -107,6 +109,7 @@ public class MsoKeystoneUtilsTest {
MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
Map<String,String>metadata=new HashMap<>();
metadata.put("1", "value");
+ mst = mock(MsoTenant.class);
PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
PowerMockito.when(mst.getTenantName()).thenReturn("name");
@@ -117,6 +120,7 @@ public class MsoKeystoneUtilsTest {
@Test
public void testgetKeystoneAdminClient() throws MsoException{
+ cloudIdentity = mock(CloudIdentity.class);
Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl ("region", "msoPropID"));
MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
doReturn(keystone).when(msk).getKeystoneAdminClient(cs);
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java
index 5c52cb514f..839da370df 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoNeutronUtilsTest.java
@@ -22,6 +22,7 @@ package org.openecomp.mso.openstack.utils;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.List;
@@ -43,7 +44,8 @@ import com.woorea.openstack.quantum.Quantum;
import com.woorea.openstack.quantum.model.Network;
import com.woorea.openstack.quantum.model.Segment;
-@RunWith(PowerMockRunner.class)
+
+//@RunWith(PowerMockRunner.class)
@PrepareForTest({MsoNeutronUtils.class,MsoCommonUtils.class,NetworkInfo.class,CloudConfigFactory.class,CloudConfig.class,Segment.class,Network.class,Quantum.class})
public class MsoNeutronUtilsTest{
@@ -79,6 +81,8 @@ CloudSite cloudSite;
public void testcreateNetwork() throws MsoException{
List<Integer> vlans=new ArrayList();
vlans.add(1);
+ cloudConfigFactory = mock(CloudConfigFactory.class);
+ ninfo = mock(NetworkInfo.class);
MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
NetworkType type=NetworkType.PROVIDER;
doReturn(ninfo).when(mnu).createNetwork("cloudSiteId", "tenantId", type, "networkName", "provider", vlans);
@@ -87,13 +91,17 @@ CloudSite cloudSite;
}
@Test
public void testqueryNetwork() throws MsoException{
+ cloudConfigFactory = mock(CloudConfigFactory.class);
+ ninfo = mock(NetworkInfo.class);
MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
doReturn(ninfo).when(mnu).queryNetwork("networkNameOrId", "tenantId", "cloudSiteId");
- assert(mnu.queryNetwork("networkNameOrId", "tenantId", "cloudSiteId")!=null);
+ NetworkInfo ni = mnu.queryNetwork("networkNameOrId", "tenantId", "cloudSiteId");
+ assert(ni!=null);
}
@Test
public void testdeleteNetwork() throws MsoException{
+ cloudConfigFactory = mock(CloudConfigFactory.class);
MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
doReturn(true).when(mnu).deleteNetwork("networkId", "tenantId", "cloudSiteId");
assertTrue(mnu.deleteNetwork("networkId", "tenantId", "cloudSiteId"));
@@ -104,6 +112,8 @@ CloudSite cloudSite;
List<Integer> vlans=new ArrayList();
vlans.add(1);
NetworkType type=NetworkType.PROVIDER;
+ cloudConfigFactory = mock(CloudConfigFactory.class);
+ ninfo = mock(NetworkInfo.class);
MsoNeutronUtils mnu=PowerMockito.spy(new MsoNeutronUtils("msoProp",cloudConfigFactory));
doReturn(ninfo).when(mnu).updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans);
assert(mnu.updateNetwork("cloudSiteId", "tenantId", "Nid", type, "provider", vlans)!=null);
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) {
+
+ }
+ }
}
diff --git a/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java
index 8e304c654a..182190b1a7 100644
--- a/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java
+++ b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java
@@ -65,7 +65,7 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-@RunWith(PowerMockRunner.class)
+//@RunWith(PowerMockRunner.class)
@PrepareForTest({NetworkAdapterRest.class, CreateNetworkTask.class, CreateNetworkRequest.class, DeleteNetworkTask.class, DeleteNetworkRequest.class})
public class NetworkAdapterRestTest {
@Mock