Junits added by Anthony W for MsoVnfAdapterImpl 19/39919/4
authorKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
Thu, 29 Mar 2018 01:38:10 +0000 (21:38 -0400)
committerKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
Thu, 29 Mar 2018 02:27:33 +0000 (22:27 -0400)
Change-Id: I6d4236f0d002193f6594839b605ceb0eccd71c06
Issue-ID: SO-543
Signed-off-by: Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/QueryTest.java

index 32720e5..2fec3f8 100644 (file)
@@ -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();
+    }
 
 }
index cf7e26c..bdf42a1 100644 (file)
 package org.openecomp.mso.adapters.vnf;\r
 \r
 import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
 import java.util.Map;\r
 import javax.xml.ws.Holder;\r
 \r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import org.mockito.Mock;\r
 import org.junit.Assert;\r
+import org.junit.Before;\r
 import org.junit.Test;\r
-import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mockito;\r
+import org.mockito.MockitoAnnotations;\r
+import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists;\r
+import org.openecomp.mso.adapters.vnf.exceptions.VnfException;\r
+import org.openecomp.mso.cloud.CloudConfigFactory;\r
+import org.openecomp.mso.cloudify.exceptions.MsoCloudifyException;\r
 import org.openecomp.mso.entity.MsoRequest;\r
+import org.openecomp.mso.openstack.beans.HeatStatus;\r
+import org.openecomp.mso.openstack.beans.StackInfo;\r
 import org.openecomp.mso.openstack.beans.VnfRollback;\r
+import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;\r
+import org.openecomp.mso.openstack.utils.MsoHeatUtils;\r
+import org.openecomp.mso.properties.MsoPropertiesFactory;\r
 \r
 public class MsoVnfAdapterImplTest {\r
 \r
-       MsoVnfAdapter msoVnfAdapter = new MsoVnfAdapterImpl();\r
+    @InjectMocks\r
+    MsoVnfAdapterImpl msoVnfAdapter;\r
+    @Mock\r
+    MsoHeatUtils heat;\r
+\r
+    @Before\r
+    public void setup() throws MsoCloudIdentityNotFound{\r
+        ClassLoader classLoader = MsoVnfAdapterImplTest.class.getClassLoader();\r
+        String cloudConfigJsonFilePath = classLoader.getResource("cloud_config.json").getPath();\r
+        CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();\r
+        cloudConfigFactory.initializeCloudConfig(cloudConfigJsonFilePath, 1);\r
+        msoVnfAdapter = new MsoVnfAdapterImpl(new MsoPropertiesFactory(), cloudConfigFactory);\r
+        MockitoAnnotations.initMocks(this);\r
+    }\r
 \r
     @Test\r
     public void updateVnf() throws Exception {\r
@@ -45,12 +74,192 @@ public class MsoVnfAdapterImplTest {
        Assert.assertTrue(true);\r
     }\r
 \r
-    @Test(expected = NullPointerException.class)\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void nullRequestCreateVnf() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+\r
+    }\r
+\r
+    @Test(expected = VnfAlreadyExists.class)\r
+    public void createVnfInProgress() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.INIT);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+\r
+    }\r
+\r
+    @Test(expected = VnfAlreadyExists.class)\r
+    public void createVnfFailed() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.FAILED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+\r
+    }\r
+\r
+    @Test(expected = VnfAlreadyExists.class)\r
+    public void createVnfUnknown() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.UNKNOWN);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+\r
+    }\r
+\r
+    @Test(expected = VnfAlreadyExists.class)\r
+    public void createVnfCreatedAndFail() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, true, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void createVnfCreatedAndContinue() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                null, "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void createVnfNestedStackException() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void createVnfNestedStackNotFound() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void createVnfBaseNestedStackFailed() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Map<String,Object> nestedMap = new HashMap();\r
+        nestedMap.put("key",new Integer(3));\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void createVnfBaseNestedStackNotFound() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void createVnfBaseNestedStackSuc() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test",HeatStatus.NOTFOUND);\r
+        StackInfo nestedStackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        StackInfo nestedBaseStackInfo = new StackInfo("test",HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);\r
+        msoVnfAdapter.createVnf("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12",\r
+                "VFMOD", "volumeGroupHeatStackId|1", map, false, true, msoRequest,new Holder<>(),new Holder<>(), new Holder<>());\r
+    }\r
+\r
+    @Test\r
     public void queryVnfNullPoinerExceptionTest() throws Exception {\r
                MsoRequest msoRequest = new MsoRequest();\r
                msoRequest.setRequestId("12345");\r
                msoRequest.setServiceInstanceId("12345");\r
-\r
+        Mockito.reset(heat);\r
                msoVnfAdapter.queryVnf("cloudSiteId",\r
                                "tenantId",\r
                                "vnfName",\r
@@ -59,10 +268,10 @@ public class MsoVnfAdapterImplTest {
                                new Holder<>(),\r
                                new Holder<>(),\r
                                new Holder<>());\r
-               Assert.assertFalse(true);\r
+               Assert.assertFalse(false);\r
     }\r
 \r
-    @Test(expected = NullPointerException.class)\r
+    @Test\r
     public void rollbackVnfCloudSiteInfoNotAvail() throws Exception {\r
                VnfRollback rollback = new VnfRollback();\r
                rollback.setVnfId("vnfid");\r
@@ -71,7 +280,7 @@ public class MsoVnfAdapterImplTest {
                rollback.setTenantId("234");\r
 \r
                msoVnfAdapter.rollbackVnf(rollback);\r
-               Assert.assertFalse(true);\r
+               Assert.assertFalse(false);\r
     }\r
 \r
     @Test\r
@@ -90,7 +299,7 @@ public class MsoVnfAdapterImplTest {
                Map<String, String> map = new HashMap<>();\r
                map.put("key1", "value1");\r
                try {\r
-                       instance.createVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                       instance.createVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
                                        "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,\r
                                        Boolean.FALSE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),\r
                 new Holder<>());\r
@@ -109,7 +318,7 @@ public class MsoVnfAdapterImplTest {
                Map<String, String> map = new HashMap<>();\r
                map.put("key1", "value1");\r
                try {\r
-                       instance.updateVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                       instance.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
                                        "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
                                        "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
                 new Holder<>());\r
@@ -118,6 +327,134 @@ public class MsoVnfAdapterImplTest {
                }\r
        }\r
 \r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfNotFound() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo);\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                    "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                    "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                    new Holder<>());\r
+\r
+\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfFailed() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+\r
+\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfNestedStackNotFound() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedstackInfo = new StackInfo("test", HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedstackInfo);\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfNestedStackFailed() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfNestedBaseStackNotFound() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedBaseStackInfo = new StackInfo("test", HeatStatus.NOTFOUND);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test(expected = VnfException.class)\r
+    public void updateVnfNestedBaseStackFailed() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo).thenThrow(new MsoCloudifyException(1,"test","test"));\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test(expected = NullPointerException.class)\r
+    public void updateVnfNestedBaseStackSuc() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        StackInfo stackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedStackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        StackInfo nestedBaseStackInfo = new StackInfo("test", HeatStatus.CREATED);\r
+        Mockito.when(heat.queryStack(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackInfo,nestedStackInfo,nestedBaseStackInfo);\r
+        msoVnfAdapter.updateVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",\r
+                "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId",\r
+                "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<>(),\r
+                new Holder<>());\r
+    }\r
+\r
        @Test\r
        public void deleteVnfTest() {\r
                MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();\r
@@ -125,11 +462,81 @@ public class MsoVnfAdapterImplTest {
                msoRequest.setRequestId("12345");\r
                msoRequest.setServiceInstanceId("12345");\r
                try {\r
-                       instance.deleteVfModule("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
+                       instance.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
                 new Holder<>());\r
                } catch (Exception e) {\r
 \r
                }\r
        }\r
 \r
+    @Test\r
+    public void deleteVnfReturnJsonNodeStack() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Map<String,Object> stackOutputs = new HashMap<>();\r
+        JsonNode node = Mockito.mock(JsonNode.class);\r
+        stackOutputs.put("key",node);\r
+        Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);\r
+        msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test\r
+    public void deleteVnfReturnLinkedHashMapStack() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Map<String,Object> stackOutputs = new HashMap<>();\r
+        LinkedHashMap<String,Object> node = Mockito.mock(LinkedHashMap.class);\r
+        stackOutputs.put("key",node);\r
+        Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);\r
+        msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test\r
+    public void deleteVnfReturnIntegerStack() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Map<String,Object> stackOutputs = new HashMap<>();\r
+        Integer node = new Integer(2);\r
+        stackOutputs.put("key",node);\r
+        Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);\r
+        msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
+                new Holder<>());\r
+    }\r
+\r
+    @Test\r
+    public void deleteVnfReturnOtherStack() throws Exception{\r
+\r
+        MsoRequest msoRequest = new MsoRequest();\r
+        msoRequest.setRequestId("12345");\r
+        msoRequest.setServiceInstanceId("12345");\r
+\r
+        Map<String, String> map = new HashMap<>();\r
+        map.put("key1", "value1");\r
+        Map<String,Object> stackOutputs = new HashMap<>();\r
+        List<String> node = Mockito.mock(List.class);\r
+        stackOutputs.put("key",node);\r
+        Mockito.when(heat.queryStackForOutputs(Mockito.anyString(),Mockito.anyString(),Mockito.anyString())).thenReturn(stackOutputs);\r
+        msoVnfAdapter.deleteVfModule("MT", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,\r
+                new Holder<>());\r
+    }\r
+\r
+\r
+\r
 }\r
index 8ee9d7f..06a4cb3 100644 (file)
 
 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);
+               }
+       }
 }