aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-03-29 02:31:12 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-29 02:31:12 +0000
commite50632aa84ed43893304282f53774419b198b7e6 (patch)
tree25d3f94d699af65c54e413e5cf3811710229cd55
parent4925835e1b095781ed15c045bd9e7ddcfc421535 (diff)
parent089e3eb2ac652a7af34449d0e1e667da8844a804 (diff)
Merge "Junits added by Anthony W for MsoVnfAdapterImpl"
-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
3 files changed, 507 insertions, 122 deletions
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);
+ }
+ }
}