summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImpl.java40
-rw-r--r--adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java861
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java649
3 files changed, 1500 insertions, 50 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 e5e6c853db..6d162b65a0 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
@@ -71,6 +71,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
+
+ protected MsoNeutronUtils neutron;
+
+ protected MsoHeatUtils heat;
+
+ protected MsoHeatUtilsWithUpdate heatWithUpdate;
private static final String AIC3_NW_PROPERTY= "org.openecomp.mso.adapters.network.aic3nw";
private static final String AIC3_NW="OS::ContrailV2::VirtualNetwork";
@@ -112,6 +118,10 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
this.msoPropertiesFactory = msoPropFactory;
this.cloudConfigFactory=cloudConfigFact;
cloudConfig = cloudConfigFactory.getCloudConfig ();
+ neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
+ heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
+ heatWithUpdate = new MsoHeatUtilsWithUpdate(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
+ cloudConfigFactory);
}
@Override
@@ -226,7 +236,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
* the orchestration fails on a subsequent operation.
*/
- private void createNetwork (String cloudSiteId,
+ protected void createNetwork (String cloudSiteId,
String tenantId,
String networkType,
String modelCustomizationUuid,
@@ -306,9 +316,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
if (NEUTRON_MODE.equals(mode)) {
- // Use an MsoNeutronUtils for all neutron commands
- MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
// See if the Network already exists (by name)
NetworkInfo netInfo = null;
long queryNetworkStarttime = System.currentTimeMillis();
@@ -406,10 +413,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
LOGGER.debug("Network " + networkName + " created, id = " + netInfo.getId());
} else if ("HEAT".equals(mode)) {
- // Use an MsoHeatUtils for all Heat commands
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
- cloudConfigFactory);
-
//HeatTemplate heatTemplate = db.getHeatTemplate (networkResource.getTemplateId ());
HeatTemplate heatTemplate = db
.getHeatTemplateByArtifactUuidRegularQuery(networkResource.getHeatTemplateArtifactUUID());
@@ -857,9 +860,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
String mode = networkResource.getOrchestrationMode();
NetworkType neutronNetworkType = NetworkType.valueOf(networkResource.getNeutronNetworkType());
- // Use an MsoNeutronUtils for all Neutron commands
- MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
if (NEUTRON_MODE.equals(mode)) {
// Verify that the Network exists
@@ -943,16 +943,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
LOGGER.debug("Network " + networkId + " updated, id = " + netInfo.getId());
} else if ("HEAT".equals(mode)) {
- // Use an MsoHeatUtils for all Heat commands
- MsoHeatUtilsWithUpdate heat = new MsoHeatUtilsWithUpdate(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
- cloudConfigFactory);
-
// First, look up to see that the Network already exists.
// For Heat-based orchestration, the networkId is the network Stack ID.
StackInfo heatStack = null;
long queryStackStarttime = System.currentTimeMillis();
try {
- heatStack = heat.queryStack(cloudSiteId, tenantId, networkName);
+ heatStack = heatWithUpdate.queryStack(cloudSiteId, tenantId, networkName);
LOGGER.recordMetricEvent(queryStackStarttime, MsoLogger.StatusCode.COMPLETE,
MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack",
"QueryStack", null);
@@ -1056,7 +1052,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Validate (and update) the input parameters against the DB definition
// Shouldn't happen unless DB config is wrong, since all networks use same inputs
try {
- stackParams = heat.validateStackParams(stackParams, heatTemplate);
+ stackParams = heatWithUpdate.validateStackParams(stackParams, heatTemplate);
} catch (IllegalArgumentException e) {
String error = "UpdateNetwork: Configuration Error: Network Type=" + networkType;
LOGGER.error(MessageEnum.RA_CONFIG_EXC, "Network Type=" + networkType, "OpenStack", "",
@@ -1138,7 +1134,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
// Ignore MsoStackNotFound exception because we already checked.
long updateStackStarttime = System.currentTimeMillis();
try {
- heatStack = heat.updateStack(cloudSiteId,
+ heatStack = heatWithUpdate.updateStack(cloudSiteId,
tenantId,
networkId,
template,
@@ -1202,7 +1198,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
return;
}
- private NetworkResource networkCheck (CatalogDatabase db,
+ protected NetworkResource networkCheck (CatalogDatabase db,
long startTime,
String networkType,
String modelCustomizationUuid,
@@ -1404,10 +1400,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
throw new NetworkException (error, MsoExceptionCategory.USERDATA);
}
- // Use MsoNeutronUtils for all NEUTRON commands
- MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_NETWORK_ADAPTER,msoPropertiesFactory,cloudConfigFactory);
- MsoNeutronUtils neutron = new MsoNeutronUtils (MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
String mode;
String neutronId;
// Try Heat first, since networks may be named the same as the Heat stack
@@ -1807,7 +1799,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
return missing.toString ();
}
- private Map <String, Object> populateNetworkParams (NetworkType neutronNetworkType,
+ protected Map <String, Object> populateNetworkParams (NetworkType neutronNetworkType,
String networkName,
String physicalNetwork,
List <Integer> vlans,
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
new file mode 100644
index 0000000000..9be488d88d
--- /dev/null
+++ b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/MsoNetworkAdapterImplTest.java
@@ -0,0 +1,861 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.network;
+
+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.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.xml.ws.Holder;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.mso.adapters.network.exceptions.NetworkException;
+import org.openecomp.mso.cloud.CloudConfig;
+import org.openecomp.mso.cloud.CloudConfigFactory;
+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.NetworkInfo;
+import org.openecomp.mso.openstack.beans.NetworkRollback;
+import org.openecomp.mso.openstack.beans.NetworkStatus;
+import org.openecomp.mso.openstack.beans.StackInfo;
+import org.openecomp.mso.openstack.beans.Subnet;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.utils.MsoHeatUtils;
+import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
+import org.openecomp.mso.openstack.utils.MsoNeutronUtils;
+import org.openecomp.mso.properties.MsoJavaProperties;
+import org.openecomp.mso.properties.MsoPropertiesException;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+
+public class MsoNetworkAdapterImplTest {
+
+ @Test
+ public void createNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
+ 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.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
+ throws NetworkException, MsoException {
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenThrow(exception);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkExists_FailIfExistsTrue()
+ throws NetworkException, MsoException {
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkExists_FailIfExistsNotTrue()
+ throws NetworkException, MsoException {
+ Holder<String> networkId = new Holder<>();
+ Holder<String> neutronNetworkId = new Holder<>();
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, false, true, null, null, networkId, neutronNetworkId, subnetIdMap,
+ rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoDoesntExist_CreateNetworkException()
+ throws NetworkException, MsoException {
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = null;
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ when(impl.neutron.createNetwork(any(), any(), any(), any(), any(), any())).thenThrow(exception);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoDoesntExist_CreateNetwork()
+ throws NetworkException, MsoException {
+ Holder<String> networkId = new Holder<>();
+ Holder<String> neutronNetworkId = new Holder<>();
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = Mockito.mock(NetworkInfo.class);
+ when(netInfo.getId()).thenReturn("Id");
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(null);
+ when(impl.neutron.createNetwork(any(), any(), any(), any(), any(), anyList())).thenReturn(netInfo);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, networkId, neutronNetworkId, subnetIdMap,
+ rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_NeutronMode_NetInfoExists()
+ throws NetworkException, MsoException {
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = null;
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNull() throws NetworkException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_ThrowMsoPropsException()
+ throws NetworkException, MsoPropertiesException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplate");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoPropertiesException exception = Mockito.mock(MsoPropertiesException.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenThrow(exception);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull()
+ throws NetworkException, MsoPropertiesException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoPropertiesException exception = Mockito.mock(MsoPropertiesException.class);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStackThrowsException()
+ throws NetworkException, MsoPropertiesException, MsoException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ MsoException exception = Mockito.mock(MsoException.class);
+ impl.heat = Mockito.mock(MsoHeatUtils.class);
+ when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenThrow(exception);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNull()
+ throws NetworkException, MsoPropertiesException, MsoException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ StackInfo heatStack = null;
+ impl.heat = Mockito.mock(MsoHeatUtils.class);
+ when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_FailIfExists()
+ throws NetworkException, MsoPropertiesException, MsoException {
+ 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ StackInfo heatStack = Mockito.mock(StackInfo.class);
+ impl.heat = Mockito.mock(MsoHeatUtils.class);
+ when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, true, true, null, null, null, null, null, null);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_DontFailIfExists()
+ throws NetworkException, MsoPropertiesException, MsoException {
+ Holder<String> networkId = new Holder<>();
+ Holder<String> neutronNetworkId = new Holder<>();
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ StackInfo heatStack = Mockito.mock(StackInfo.class);
+ Map<String, Object> outputs = new HashMap<>();
+ outputs.put("subnet", "");
+ when(heatStack.getOutputs()).thenReturn(outputs);
+ impl.heat = Mockito.mock(MsoHeatUtils.class);
+ when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, false, true, null, null, networkId, neutronNetworkId, subnetIdMap,
+ rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void createNetworkImplTest_CloudSitePresent_HeatMode_HeatTemplateNotNull_QueryStack_HeatStackNotNull_DontFailIfExists_Validate()
+ throws NetworkException, MsoPropertiesException, MsoException {
+ List<Subnet> subnets = new ArrayList<>();
+ Holder<String> networkId = new Holder<>();
+ Holder<String> neutronNetworkId = new Holder<>();
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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("HEAT");
+ 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ HeatTemplate heatTemplate = Mockito.mock(HeatTemplate.class);
+ when(heatTemplate.toString()).thenReturn("heatTemplate");
+ when(heatTemplate.getHeatTemplate()).thenReturn("heatTemplateaic");
+ when(catalogDB.getHeatTemplateByArtifactUuidRegularQuery(any())).thenReturn(heatTemplate);
+ MsoJavaProperties props = Mockito.mock(MsoJavaProperties.class);
+ when(impl.msoPropertiesFactory.getMsoJavaProperties(any())).thenReturn(props);
+ when(props.getProperty(anyString(), anyString())).thenReturn("aic");
+ StackInfo heatStack = Mockito.mock(StackInfo.class);
+ Map<String, Object> outputs = new HashMap<>();
+ outputs.put("subnet", "");
+ when(heatStack.getOutputs()).thenReturn(outputs);
+ impl.heat = Mockito.mock(MsoHeatUtils.class);
+ when(impl.heat.queryStack(anyString(), anyString(), anyString())).thenReturn(heatStack);
+ try {
+ impl.createNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkName",
+ "physicalNetworkName", null, false, true, subnets, null, networkId, neutronNetworkId, subnetIdMap,
+ rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenThrow(exception);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkReturnsNull()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(null);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkDoesntExist_UpdateNetworkException()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = new NetworkInfo(null);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ when(impl.neutron.updateNetwork(any(), any(), any(), any(), any(), anyList())).thenThrow(exception);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkDoesntExist_UpdateNetwork()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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.neutron = Mockito.mock(MsoNeutronUtils.class);
+ NetworkInfo netInfo = new NetworkInfo(null);
+ NetworkInfo mockedNetworkInfo = Mockito.mock(NetworkInfo.class);
+ when(mockedNetworkInfo.getId()).thenReturn("Id");
+ when(impl.neutron.queryNetwork(any(), any(), any())).thenReturn(netInfo);
+ when(impl.neutron.updateNetwork(any(), any(), any(), any(), any(), anyList())).thenReturn(mockedNetworkInfo);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackThrowException()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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("HEAT");
+ 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.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenThrow(exception);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackReturnNull()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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("HEAT");
+ 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.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenReturn(null);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void updateNetworkImplTest_CloudSitePresent_HeatMode_QueryStackReturnInfo()
+ throws NetworkException, MsoException {
+ Holder<Map<String, String>> subnetIdMap = new Holder<>();
+ Holder<NetworkRollback> rollback = 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("HEAT");
+ 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.heatWithUpdate = Mockito.mock(MsoHeatUtilsWithUpdate.class);
+ MsoException exception = Mockito.mock(MsoException.class);
+ StackInfo stackInfo = Mockito.mock(StackInfo.class);
+ when(impl.heatWithUpdate.queryStack(any(), any(), any())).thenReturn(stackInfo);
+ try {
+ impl.updateNetwork("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId",
+ "networkName", "physicalNetworkName", null, null, null, subnetIdMap, rollback);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void queryNetworkImplTest_CloudSiteNotPresent() throws NetworkException {
+ 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);
+ Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(null);
+ when(cloudConfig.getCloudSite(any())).thenReturn(cloudSiteOpt);
+ impl.msoPropertiesFactory = Mockito.mock(MsoPropertiesFactory.class);
+ try {
+ impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId,
+ neutronNetworkId, status, vlans, subnetIdMap);
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void queryNetworkImplTest_CloudSitePresent_NeutronMode_QueryNetworkThrowsException()
+ 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);
+ MsoException exception = Mockito.mock(MsoException.class);
+ when(impl.heat.queryStack(any(), any(), any())).thenThrow(exception);
+ try {
+ impl.queryNetwork("cloudSiteId", "tenantId", "networkNameOrId", null, networkExists, networkId,
+ neutronNetworkId, status, vlans, subnetIdMap);
+ } catch (Exception e) {
+
+ }
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java
index 831a789711..d8a6282a8a 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java
@@ -20,16 +20,12 @@
package org.openecomp.mso.apihandlerinfra;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.HashMap;
import javax.ws.rs.core.Response;
@@ -38,33 +34,40 @@ import org.apache.http.ProtocolVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHttpResponse;
-import org.hibernate.HibernateException;
import org.hibernate.Session;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Order;
-import org.hibernate.internal.SessionFactoryImpl;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.Ignore;
-import org.mockito.Mockito;
import org.openecomp.mso.apihandler.common.CamundaClient;
import org.openecomp.mso.apihandler.common.RequestClient;
import org.openecomp.mso.apihandler.common.RequestClientFactory;
+import org.openecomp.mso.apihandler.common.ValidationException;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.db.catalog.CatalogDatabase;
import org.openecomp.mso.db.catalog.beans.Service;
import org.openecomp.mso.db.catalog.beans.ServiceRecipe;
import org.openecomp.mso.properties.MsoDatabaseException;
import org.openecomp.mso.properties.MsoJavaProperties;
import org.openecomp.mso.properties.MsoPropertiesFactory;
-import org.openecomp.mso.requestsdb.InfraActiveRequests;
import org.openecomp.mso.requestsdb.OperationStatus;
import org.openecomp.mso.requestsdb.RequestsDatabase;
+import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest;
+import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
+import mockit.Mocked;
public class E2EServiceInstancesTest {
+ private final String compareModelsRequest = "{" +
+ "\"globalSubscriberId\": \"60c3e96e-0970-4871-b6e0-3b6de7561519\"," +
+ "\"serviceType\": \"vnf\"," +
+ "\"modelInvariantIdTarget\": \"60c3e96e-0970-4871-b6e0-3b6de1234567\"," +
+ "\"modelVersionIdTarget\": \"modelVersionIdTarget\"" +
+ "}";
+
+ private final String scaleRequest = "{\"service\":{\"serviceType\":\"example-service-type\",\"globalSubscriberId\":\"test_custormer\",\"resources\":[{\"resourceInstanceId\":\"ns111\",\"scaleType\":\"SCALE_NS\",\"scaleNsData\":{\"scaleNsByStepsData\":{\"numberOfSteps\":\"4\",\"aspectId\":\"TIC_EDGE_HW\",\"scalingDirection\":\"UP\"}}}],\"serviceInstanceName\":\"XXXX\"}}";
+
String jsonBody = "{" +
"\"service\": {" +
"\"name\": \"so_test4\"," +
@@ -143,13 +146,6 @@ public class E2EServiceInstancesTest {
"}" +
"}";
- private final String compareModelsRequest = "{" +
- "\"globalSubscriberId\": \"60c3e96e-0970-4871-b6e0-3b6de7561519\"," +
- "\"serviceType\": \"vnf\"," +
- "\"modelInvariantIdTarget\": \"60c3e96e-0970-4871-b6e0-3b6de1234567\"," +
- "\"modelVersionIdTarget\": \"modelVersionIdTarget\"" +
- "}";
-
@BeforeClass
public static void setUp() throws Exception {
@@ -530,7 +526,8 @@ public class E2EServiceInstancesTest {
}
};
E2EServiceInstances instance = new E2EServiceInstances();
- String request = jsonBody;;
+ String request = jsonBody;
+ ;
Response resp = instance.createE2EServiceInstance(request, "v3");
String respStr = resp.getEntity().toString();
assertTrue(respStr.contains("SVC2000"));
@@ -673,15 +670,166 @@ public class E2EServiceInstancesTest {
.contains("Mapping of request to JSON object failed. No content to map due to end-of-input"));
}
- @Ignore // 1802 merge
@Test
public void deleteE2EServiceInstanceTestNormal() {
+
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ rec.setOrchestrationUri("/test/delE2E");
+ rec.setRecipeTimeout(180);
+ return rec;
+ }
+ };
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ final MockUp<CamundaClient> mockCmaundaClient = new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction, String serviceInstanceId,
+ String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId,
+ String serviceType, String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd)
+ throws ClientProtocolException, IOException {
+ ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
+ HttpResponse resp = new BasicHttpResponse(pv, 200, "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+
+
E2EServiceInstances instance = new E2EServiceInstances();
String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
- Response resp = instance.deleteE2EServiceInstance(request, "v3",
- "12345678");
- String respStr = resp.getEntity().toString();
- assertTrue(respStr.contains("SVC1000"));
+
+ instance.deleteE2EServiceInstance(request, "v3", "12345678");
+ mockCDB.tearDown();
+ mockMsoRequest.tearDown();
+ mockCmaundaClient.tearDown();
+
+ }
+
+ @Test
+ public void deleteE2EServiceInstanceTestFail() {
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
+ instance.deleteE2EServiceInstance(request, "v3", "12345678");
+ }
+
+ @Test
+ public void deleteE2EServiceInstanceTestFailClient(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) {
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ rec.setOrchestrationUri("/test/delE2E");
+ rec.setRecipeTimeout(180);
+ return rec;
+ }
+ };
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
+
+ instance.deleteE2EServiceInstance(request, "v3", "12345678");
+ mockCDB.tearDown();
+ mockMsoRequest.tearDown();
+
+ }
+
+ @Test
+ public void deleteE2EServiceInstanceTestFailRecipe(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) {
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession();
+ result = session;
+ }};
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
+
+ instance.deleteE2EServiceInstance(request, "v3", "12345678");
+ mockCDB.tearDown();
+ mockMsoRequest.tearDown();
+
+ }
+
+ @Test
+ public void deleteE2EServiceInstanceTestFailModelName(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) {
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession();
+ result = session;
+ }};
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}";
+
+ instance.deleteE2EServiceInstance(request, "v3", "12345678");
+ mockMsoRequest.tearDown();
+
}
@Test
@@ -857,6 +1005,294 @@ public class E2EServiceInstancesTest {
}
@Test
+ public void updateE2EServiceInstanceExceptionMsoRequestTest() {
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public OperationStatus getOperationStatusByServiceId(
+ String serviceID) {
+ OperationStatus operationStatus = new OperationStatus();
+ operationStatus.setProgress("100");
+ operationStatus.setResult("finish");
+ return operationStatus;
+ }
+ };
+ new MockUp<E2EServiceInstances>() {
+ @Mock
+ private void createOperationStatusRecordForError(Action action,
+ String requestId) throws MsoDatabaseException {
+
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction,
+ String serviceInstanceId, String vnfId, String vfModuleId,
+ String volumeGroupId, String networkId, String configurationId, String serviceType,
+ String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd) {
+ ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
+ HttpResponse resp = new BasicHttpResponse(pv, 202,
+ "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+ MockUp<MsoRequest> msoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action, String version, String originalRequestJSON) throws ValidationException {
+
+ throw new ValidationException("mock failure");
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = jsonBody;
+ Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ msoRequest.tearDown();
+ }
+
+ @Test
+ public void updateE2EServiceInstanceExceptionCatalogDbTest() {
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public OperationStatus getOperationStatusByServiceId(
+ String serviceID) {
+ OperationStatus operationStatus = new OperationStatus();
+ operationStatus.setProgress("100");
+ operationStatus.setResult("finish");
+ return operationStatus;
+ }
+ };
+ new MockUp<E2EServiceInstances>() {
+ @Mock
+ private void createOperationStatusRecordForError(Action action,
+ String requestId) throws MsoDatabaseException {
+
+ }
+ };
+ MockUp<CatalogDatabase> catalog = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) throws Exception {
+ throw new Exception();
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction,
+ String serviceInstanceId, String vnfId, String vfModuleId,
+ String volumeGroupId, String networkId, String configurationId, String serviceType,
+ String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd) {
+ ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
+ HttpResponse resp = new BasicHttpResponse(pv, 202,
+ "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = jsonBody;
+ Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
+ catalog.tearDown();
+ }
+
+ @Test
+ public void updateE2EServiceInstanceNullServiceTest() {
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public OperationStatus getOperationStatusByServiceId(
+ String serviceID) {
+ OperationStatus operationStatus = new OperationStatus();
+ operationStatus.setProgress("100");
+ operationStatus.setResult("finish");
+ return operationStatus;
+ }
+ };
+ new MockUp<E2EServiceInstances>() {
+ @Mock
+ private void createOperationStatusRecordForError(Action action,
+ String requestId) throws MsoDatabaseException {
+
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ MockUp<CatalogDatabase> catalog = new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ return null;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction,
+ String serviceInstanceId, String vnfId, String vfModuleId,
+ String volumeGroupId, String networkId, String configurationId, String serviceType,
+ String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd) {
+ ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
+ HttpResponse resp = new BasicHttpResponse(pv, 202,
+ "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = jsonBody;
+ Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
+ catalog.tearDown();
+ }
+
+ @Test
+ public void updateE2EServiceInstanceRequestClientExceptionTest() {
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public OperationStatus getOperationStatusByServiceId(
+ String serviceID) {
+ OperationStatus operationStatus = new OperationStatus();
+ operationStatus.setProgress("100");
+ operationStatus.setResult("finish");
+ return operationStatus;
+ }
+ };
+ new MockUp<E2EServiceInstances>() {
+ @Mock
+ private void createOperationStatusRecordForError(Action action,
+ String requestId) throws MsoDatabaseException {
+
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ MockUp<CamundaClient> client = new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction,
+ String serviceInstanceId, String vnfId, String vfModuleId,
+ String volumeGroupId, String networkId, String configurationId, String serviceType,
+ String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd) throws Exception {
+ throw new Exception();
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = jsonBody;
+ Response resp = instance.updateE2EServiceInstance(request, "v3", "12345");
+ assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), resp.getStatus());
+ client.tearDown();
+ }
+
+ @Test
public void compareModelwithTargetVersionBadRequest(){
E2EServiceInstances instance = new E2EServiceInstances();
@@ -922,4 +1358,165 @@ public class E2EServiceInstancesTest {
assertTrue(response.getStatus()==202);
}
+
+ @Test
+ public void scaleE2EserviceInstancesTestFailInvalidRequest(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session ) {
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ Response response = instance.scaleE2EServiceInstance(jsonBody, "v3", "12345");
+ }
+
+ @Test
+ public void scaleE2EserviceInstancesTestNormal() {
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ rec.setOrchestrationUri("/test/delE2E");
+ rec.setRecipeTimeout(180);
+ return rec;
+ }
+ };
+
+ final MockUp<RequestClientFactory> mockRequestClient = new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ final MockUp<CamundaClient> mockCamundaClient = new MockUp<CamundaClient>() {
+ @Mock
+ public HttpResponse post(String requestId, boolean isBaseVfModule,
+ int recipeTimeout, String requestAction,
+ String serviceInstanceId, String vnfId, String vfModuleId,
+ String volumeGroupId, String networkId, String configurationId, String serviceType,
+ String vnfType, String vfModuleType, String networkType,
+ String requestDetails, String recipeParamXsd) {
+ ProtocolVersion pv = new ProtocolVersion("HTTP", 1, 1);
+ HttpResponse resp = new BasicHttpResponse(pv, 202,
+ "test response");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ String body = "{\"response\":\"success\",\"message\":\"success\"}";
+ InputStream instream = new ByteArrayInputStream(body.getBytes());
+ entity.setContent(instream);
+ resp.setEntity(entity);
+ return resp;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ Response response = instance.scaleE2EServiceInstance(scaleRequest, "v3", "12345");
+ mockMsoRequest.tearDown();
+ mockCDB.tearDown();
+ mockRequestClient.tearDown();
+ mockCamundaClient.tearDown();
+ }
+
+ @Test
+ public void scaleE2EserviceInstancesTestFailCamundaClient(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) {
+
+ new Expectations() {{
+ sessionFactoryManager.getSessionFactory().openSession(); result = session;
+ }};
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ rec.setOrchestrationUri("/test/delE2E");
+ rec.setRecipeTimeout(180);
+ return rec;
+ }
+ };
+
+ final MockUp<RequestClientFactory> mockRequestClient = new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI,
+ MsoJavaProperties props) throws IllegalStateException {
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ Response response = instance.scaleE2EServiceInstance(scaleRequest, "v3", "12345");
+ mockMsoRequest.tearDown();
+ mockCDB.tearDown();
+ mockRequestClient.tearDown();
+ }
+
+ @Test
+ public void scaleE2EserviceInstancesTestFailRequestClient(@Mocked AbstractSessionFactoryManager sessionFactoryManager,
+ @Mocked Session session) {
+
+ final MockUp<MsoRequest> mockMsoRequest = new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord(Status status, Action action) {
+ return;
+ }
+ };
+
+ final MockUp<CatalogDatabase> mockCDB = new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName(String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID,
+ String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ rec.setOrchestrationUri("/test/delE2E");
+ rec.setRecipeTimeout(180);
+ return rec;
+ }
+ };
+
+ E2EServiceInstances instance = new E2EServiceInstances();
+ Response response = instance.scaleE2EServiceInstance(scaleRequest, "v3", "12345");
+ mockMsoRequest.tearDown();
+ mockCDB.tearDown();
+ }
+
}