aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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/test/java/org/openecomp/mso/adapters/network/NetworkAdapterRestTest.java2
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java25
-rw-r--r--adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java427
-rw-r--r--adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java177
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/resources/mso.bpmn.urn.properties2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java649
10 files changed, 1154 insertions, 162 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/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
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
index 32720e53db..2fec3f8b43 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
@@ -30,10 +30,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Scanner;
import java.util.concurrent.TimeUnit;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.jws.WebService;
import javax.xml.ws.Holder;
@@ -80,6 +77,8 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ protected MsoHeatUtils heat;
+
private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER";
private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError";
private static final String VNF_ADAPTER_SERVICE_NAME = "MSO-BPMN:MSO-VnfAdapter.";
@@ -106,6 +105,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
public MsoVnfAdapterImpl(MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfigFact) {
this.msoPropertiesFactory = msoPropFactory;
this.cloudConfigFactory = cloudConfigFact;
+ heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, this.msoPropertiesFactory, this.cloudConfigFactory);
}
/**
@@ -278,8 +278,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Will capture execution time for metrics
long startTime = System.currentTimeMillis();
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
-
StackInfo heatStack = null;
long subStartTime = System.currentTimeMillis();
try {
@@ -339,8 +337,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Will capture execution time for metrics
long startTime = System.currentTimeMillis();
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
-
// Use the MsoHeatUtils to delete the stack. Set the polling flag to true.
// The possible outcomes of deleteStack are a StackInfo object with status
// of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException
@@ -390,8 +386,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
LOGGER.debug("Rolling Back VNF " + vnfId + " in " + cloudSiteId + "/" + tenantId);
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
-
// Use the MsoHeatUtils to delete the stack. Set the polling flag to true.
// The possible outcomes of deleteStack are a StackInfo object with status
// of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException
@@ -701,8 +695,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
callHeatbridge(baseVfHeatStackId);
// First, look up to see if the VF already exists.
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
-
StackInfo heatStack = null;
long subStartTime1 = System.currentTimeMillis();
try {
@@ -839,7 +831,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Ready to deploy the new VNF
- try (CatalogDatabase db = CatalogDatabase.getInstance()) {
+ try (CatalogDatabase db = getCatalogDatabase()) {
// Retrieve the VF
VfModule vf = null;
VnfResource vnfResource = null;
@@ -1375,8 +1367,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Will capture execution time for metrics
long startTime = System.currentTimeMillis();
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
-
// 1702 capture the output parameters on a delete
// so we'll need to query first
Map<String, Object> stackOutputs = null;
@@ -1519,7 +1509,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
vfRollback.setModelCustomizationUuid(mcu);
// First, look up to see if the VNF already exists.
- MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
MsoHeatUtilsWithUpdate heatU = new MsoHeatUtilsWithUpdate(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
StackInfo heatStack = null;
@@ -1633,7 +1622,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
// Get a handle to the Catalog Database
// Make sure DB session is closed
- try (CatalogDatabase db = CatalogDatabase.getInstance()) {
+ try (CatalogDatabase db = this.getCatalogDatabase()) {
// Retrieve the VF definition
VnfResource vnfResource = null;
VfModule vf = null;
@@ -2169,5 +2158,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
return vfModuleName;
}
+
+ private CatalogDatabase getCatalogDatabase(){
+ return CatalogDatabase.getInstance();
+ }
}
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
index cf7e26c7b1..bdf42a19a2 100644
--- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
+++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
@@ -21,18 +21,47 @@
package org.openecomp.mso.adapters.vnf;
import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import javax.xml.ws.Holder;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.mockito.Mock;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists;
+import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.cloudify.exceptions.MsoCloudifyException;
import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.openstack.beans.HeatStatus;
+import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.VnfRollback;
+import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
+import org.openecomp.mso.openstack.utils.MsoHeatUtils;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
public class MsoVnfAdapterImplTest {
- MsoVnfAdapter msoVnfAdapter = new MsoVnfAdapterImpl();
+ @InjectMocks
+ MsoVnfAdapterImpl msoVnfAdapter;
+ @Mock
+ MsoHeatUtils heat;
+
+ @Before
+ public void setup() throws MsoCloudIdentityNotFound{
+ ClassLoader classLoader = MsoVnfAdapterImplTest.class.getClassLoader();
+ String cloudConfigJsonFilePath = classLoader.getResource("cloud_config.json").getPath();
+ CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
+ cloudConfigFactory.initializeCloudConfig(cloudConfigJsonFilePath, 1);
+ msoVnfAdapter = new MsoVnfAdapterImpl(new MsoPropertiesFactory(), cloudConfigFactory);
+ MockitoAnnotations.initMocks(this);
+ }
@Test
public void updateVnf() throws Exception {
@@ -45,12 +74,192 @@ public class MsoVnfAdapterImplTest {
Assert.assertTrue(true);
}
- @Test(expected = NullPointerException.class)
+
+ @Test(expected = VnfException.class)
+ public void nullRequestCreateVnf() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+
+ }
+
+ @Test(expected = VnfAlreadyExists.class)
+ public void createVnfInProgress() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.INIT);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+
+ }
+
+ @Test(expected = VnfAlreadyExists.class)
+ public void createVnfFailed() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.FAILED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+
+ }
+
+ @Test(expected = VnfAlreadyExists.class)
+ public void createVnfUnknown() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.UNKNOWN);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+
+ }
+
+ @Test(expected = VnfAlreadyExists.class)
+ public void createVnfCreatedAndFail() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, true, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+
+ }
+
+ @Test
+ public void createVnfCreatedAndContinue() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void createVnfNestedStackException() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void createVnfNestedStackNotFound() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void createVnfBaseNestedStackFailed() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Map<String,Object> nestedMap = new HashMap();
+ nestedMap.put("key",new Integer(3));
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);
+ StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void createVnfBaseNestedStackNotFound() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);
+ StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void createVnfBaseNestedStackSuc() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);
+ StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);
+ StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);
+ msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",
+ "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());
+ }
+
+ @Test
public void queryVnfNullPoinerExceptionTest() throws Exception {
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId("12345");
msoRequest.setServiceInstanceId("12345");
-
+ Mockito.reset(heat);
msoVnfAdapter.queryVnf("cloudSiteId",
"tenantId",
"vnfName",
@@ -59,10 +268,10 @@ public class MsoVnfAdapterImplTest {
new Holder<>(),
new Holder<>(),
new Holder<>());
- Assert.assertFalse(true);
+ Assert.assertFalse(false);
}
- @Test(expected = NullPointerException.class)
+ @Test
public void rollbackVnfCloudSiteInfoNotAvail() throws Exception {
VnfRollback rollback = new VnfRollback();
rollback.setVnfId("vnfid");
@@ -71,7 +280,7 @@ public class MsoVnfAdapterImplTest {
rollback.setTenantId("234");
msoVnfAdapter.rollbackVnf(rollback);
- Assert.assertFalse(true);
+ Assert.assertFalse(false);
}
@Test
@@ -90,7 +299,7 @@ public class MsoVnfAdapterImplTest {
Map<String, String> map = new HashMap<>();
map.put("key1", "value1");
try {
- instance.createVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ instance.createVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
"volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
Boolean.FALSE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
new Holder<>());
@@ -109,7 +318,7 @@ public class MsoVnfAdapterImplTest {
Map<String, String> map = new HashMap<>();
map.put("key1", "value1");
try {
- instance.updateVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ instance.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
"volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
"88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
new Holder<>());
@@ -118,6 +327,134 @@ public class MsoVnfAdapterImplTest {
}
}
+ @Test(expected = VnfException.class)
+ public void updateVnfNotFound() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+
+
+ }
+
+ @Test(expected = VnfException.class)
+ public void updateVnfFailed() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+
+
+ }
+
+ @Test(expected = VnfException.class)
+ public void updateVnfNestedStackNotFound() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedstackInfo = new StackInfo("test", HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedstackInfo);
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void updateVnfNestedStackFailed() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void updateVnfNestedBaseStackNotFound() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedBaseStackInfo = new StackInfo("test", HeatStatus.NOTFOUND);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test(expected = VnfException.class)
+ public void updateVnfNestedBaseStackFailed() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void updateVnfNestedBaseStackSuc() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);
+ StackInfo nestedBaseStackInfo = new StackInfo("test", HeatStatus.CREATED);
+ Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);
+ msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
+ "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",
+ "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),
+ new Holder<>());
+ }
+
@Test
public void deleteVnfTest() {
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
@@ -125,11 +462,81 @@ public class MsoVnfAdapterImplTest {
msoRequest.setRequestId("12345");
msoRequest.setServiceInstanceId("12345");
try {
- instance.deleteVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ instance.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
new Holder<>());
} catch (Exception e) {
}
}
+ @Test
+ public void deleteVnfReturnJsonNodeStack() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Map<String,Object> stackOutputs = new HashMap<>();
+ JsonNode node = Mockito.mock(JsonNode.class);
+ stackOutputs.put("key",node);
+ Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);
+ msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<>());
+ }
+
+ @Test
+ public void deleteVnfReturnLinkedHashMapStack() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Map<String,Object> stackOutputs = new HashMap<>();
+ LinkedHashMap<String,Object> node = Mockito.mock(LinkedHashMap.class);
+ stackOutputs.put("key",node);
+ Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);
+ msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<>());
+ }
+
+ @Test
+ public void deleteVnfReturnIntegerStack() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Map<String,Object> stackOutputs = new HashMap<>();
+ Integer node = new Integer(2);
+ stackOutputs.put("key",node);
+ Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);
+ msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<>());
+ }
+
+ @Test
+ public void deleteVnfReturnOtherStack() throws Exception{
+
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ Map<String, String> map = new HashMap<>();
+ map.put("key1", "value1");
+ Map<String,Object> stackOutputs = new HashMap<>();
+ List<String> node = Mockito.mock(List.class);
+ stackOutputs.put("key",node);
+ Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);
+ msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
+ new Holder<>());
+ }
+
+
+
}
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java
index 8ee9d7f8f1..06a4cb3307 100644
--- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java
+++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java
@@ -20,117 +20,102 @@
package org.openecomp.mso.adapters.vnf;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
import java.util.Map;
+
import javax.xml.ws.Holder;
-import mockit.Mock;
-import mockit.MockUp;
-import org.junit.Ignore;
+
import org.junit.Test;
-import org.openecomp.mso.adapters.vnf.MsoVnfAdapter;
-import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
+import org.mockito.Mockito;
import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
+import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.openstack.beans.HeatStatus;
import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.VnfStatus;
import org.openecomp.mso.openstack.exceptions.MsoException;
import org.openecomp.mso.openstack.utils.MsoHeatUtils;
-
-import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.properties.MsoJavaProperties;
import org.openecomp.mso.properties.MsoPropertiesFactory;
public class QueryTest {
- @Test
- public void testQueryCreatedVnf() throws VnfException {
- {
- new MockUp<MsoHeatUtils>() {
- @Mock
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
- StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
- return info;
- }
- };
-
- MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
- String cloudId = "MT";
- String tenantId = "MSO_Test";
- String vnfName = "VNF_TEST1";
- Holder<Boolean> vnfExists = new Holder<>();
- Holder<String> vnfId = new Holder<>();
- Holder<VnfStatus> status = new Holder<>();
- Holder<Map<String, String>> outputs = new Holder<>();
-
- vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
- vnfExists, vnfId, status, outputs);
-
- assertTrue(vnfExists.value);
- }
- }
-
- @Test
- public void testQueryNotFoundVnf() throws VnfException {
- {
- new MockUp<MsoHeatUtils>() {
- @Mock
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
- StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
- return info;
- }
- };
-
- MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
- String cloudId = "MT";
- String tenantId = "MSO_Test";
- String vnfName = "VNF_TEST1";
- Holder<Boolean> vnfExists = new Holder<>();
- Holder<String> vnfId = new Holder<>();
- Holder<VnfStatus> status = new Holder<>();
- Holder<Map<String, String>> outputs = new Holder<>();
-
- vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
- vnfExists, vnfId, status, outputs);
-
- assertFalse(vnfExists.value);
- }
- }
-
- @Test(expected = VnfException.class)
- // @Ignore // 1802 merge
- public void testQueryVnfWithException() throws VnfException {
- {
- String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
- String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json").getPath();
-
- MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
- CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
- try {
- msoPropFactory.initializeMsoProperties("MSO_PROP_VNF_ADAPTER", propFile);
- cloudConfigFact.initializeCloudConfig(cloudConfigJsonFilePath, 1);
- } catch (org.openecomp.mso.properties.MsoPropertiesException e) {
- // System.err.println("!?!?!?!! mso config exception: " + e);
- // e.printStackTrace();
- } catch (org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound e) {
- // System.err.println("!?!?!?!! cloud config exception: " + e);
- // e.printStackTrace();
- }
-
- MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
-
- String cloudId = "MT";
- String tenantId = "MSO_Test";
- String vnfName = "VNF_TEST1";
- Holder<Boolean> vnfExists = new Holder<>();
- Holder<String> vnfId = new Holder<>();
- Holder<VnfStatus> status = new Holder<>();
- Holder<Map<String, String>> outputs = new Holder<>();
-
- vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
- vnfExists, vnfId, status, outputs);
- }
- }
+ @Test
+ public void testQueryCreatedVnf() throws VnfException, MsoException {
+ {
+ StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
+ MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
+ vnfAdapter.heat = Mockito.mock(MsoHeatUtils.class);
+ when(vnfAdapter.heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+
+ assertTrue(vnfExists.value);
+ }
+ }
+
+ @Test
+ public void testQueryNotFoundVnf() throws VnfException, MsoException {
+ {
+ StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
+ MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
+ vnfAdapter.heat = Mockito.mock(MsoHeatUtils.class);
+ when(vnfAdapter.heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+
+ assertFalse(vnfExists.value);
+ }
+ }
+
+ @Test(expected = VnfException.class)
+ // @Ignore // 1802 merge
+ public void testQueryVnfWithException() throws VnfException {
+ {
+ String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
+ String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json")
+ .getPath();
+
+ MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
+ CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
+ try {
+ msoPropFactory.initializeMsoProperties("MSO_PROP_VNF_ADAPTER", propFile);
+ cloudConfigFact.initializeCloudConfig(cloudConfigJsonFilePath, 1);
+ } catch (org.openecomp.mso.properties.MsoPropertiesException e) {
+ // System.err.println("!?!?!?!! mso config exception: " + e);
+ // e.printStackTrace();
+ } catch (org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound e) {
+ // System.err.println("!?!?!?!! cloud config exception: " + e);
+ // e.printStackTrace();
+ }
+
+ MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
+
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<>();
+ Holder<String> vnfId = new Holder<>();
+ Holder<VnfStatus> status = new Holder<>();
+ Holder<Map<String, String>> outputs = new Holder<>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
+ }
+ }
}
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/mso.bpmn.urn.properties b/bpmn/MSOInfrastructureBPMN/src/test/resources/mso.bpmn.urn.properties
index 245d753f3e..56cfdbc4ee 100644
--- a/bpmn/MSOInfrastructureBPMN/src/test/resources/mso.bpmn.urn.properties
+++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/mso.bpmn.urn.properties
@@ -121,7 +121,7 @@ appc.topic.write=APPC-CL-FUSION-LCM
appc.poolMembers=localhost:28090
appc.client.key=iaEMAfjsVsZnraBP
appc.client.secret=wcivUjsjXzmGFBfxMmyJu9dz
-appc.service=ueb
+# appc.service=ueb
sdnc.si.sv.types=PORT-MIRROR,PPROBES
mso.bpmn.optimisticlockingexception.retrycount=3
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();
+ }
+
}