Test coverage in aai-client-provider 79/77579/5
authorJoss Armstrong <joss.armstrong@ericsson.com>
Wed, 30 Jan 2019 13:51:13 +0000 (13:51 +0000)
committerTakamune Cho <takamune.cho@att.com>
Wed, 30 Jan 2019 19:25:32 +0000 (19:25 +0000)
Increase coverage to 91%

Issue-ID: APPC-1373
Change-Id: I5de0f532a50bbcd1bf5c305d758a6d1fd95fa3c1
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-outbound/appc-aai-client/provider/pom.xml
appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java
appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/node/AAIResourceNode.java
appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java
appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java

index 27d2d13..4d6e047 100755 (executable)
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!--\r
-  ============LICENSE_START=======================================================\r
-  ONAP : APPC\r
-  ================================================================================\r
-  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
-  Copyright (C) 2017 Amdocs\r
-  ================================================================================\r
-  Licensed under the Apache License, Version 2.0 (the "License");\r
-  you may not use this file except in compliance with the License.\r
-  You may obtain a copy of the License at\r
-  \r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-  \r
-  Unless required by applicable law or agreed to in writing, software\r
-  distributed under the License is distributed on an "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-  See the License for the specific language governing permissions and\r
-  limitations under the License.\r
-  ============LICENSE_END=========================================================\r
-  -->\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-       <modelVersion>4.0.0</modelVersion>\r
-       <parent>\r
-               <groupId>org.onap.appc.parent</groupId>\r
-               <artifactId>binding-parent</artifactId>\r
-               <version>1.5.0-SNAPSHOT</version>\r
-                <relativePath />\r
-       </parent>\r
-        <groupId>org.onap.appc</groupId>\r
-       <artifactId>appc-aai-client-provider</artifactId>\r
-       <packaging>bundle</packaging>\r
-       <name>APPC AAI Client - Provider</name>\r
-\r
-       <properties>\r
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
-       </properties>\r
-       <dependencies>\r
-               <dependency>\r
-                       <groupId>equinoxSDK381</groupId>\r
-                       <artifactId>org.eclipse.osgi</artifactId>\r
-                       <version>${equinox.osgi.version}</version>\r
-               </dependency>\r
-               <dependency>\r
-                       <groupId>org.onap.ccsdk.sli.core</groupId>\r
-                       <artifactId>sli-provider</artifactId>\r
-                       <scope>compile</scope>\r
-               </dependency>\r
-\r
-               <dependency>\r
-                       <groupId>org.onap.ccsdk.sli.adaptors</groupId>\r
-                       <artifactId>aai-service-provider</artifactId>\r
-                       <scope>compile</scope>\r
-               </dependency>\r
-\r
-\r
-               <dependency>\r
-                       <groupId>commons-io</groupId>\r
-                       <artifactId>commons-io</artifactId>\r
-                       <version>2.5</version>\r
-               </dependency>\r
-                <dependency>\r
-                       <groupId>org.apache.commons</groupId>\r
-                       <artifactId>commons-lang3</artifactId>\r
-               </dependency>\r
-                <dependency>\r
-                        <groupId>ch.qos.logback</groupId>\r
-                        <artifactId>logback-classic</artifactId>\r
-                       <version>${logback.version}</version>\r
-                </dependency>\r
-               <dependency>\r
-                       <groupId>com.att.eelf</groupId>\r
-                       <artifactId>eelf-core</artifactId>\r
-                        <exclusions>\r
-                            <exclusion>\r
-                                 <groupId>ch.qos.logback</groupId>\r
-                                 <artifactId>logback-classic</artifactId>\r
-                            </exclusion>\r
-                        </exclusions>\r
-               </dependency>\r
-\r
-               <dependency>\r
-                       <groupId>junit</groupId>\r
-                       <artifactId>junit</artifactId>\r
-                       <scope>test</scope>\r
-               </dependency>\r
-\r
-\r
-\r
-       </dependencies>\r
-       <build>\r
-               <plugins>\r
-                       <plugin>\r
-                               <artifactId>maven-resources-plugin</artifactId>\r
-                               <version>2.6</version>\r
-                               <executions>\r
-                                       <execution>\r
-                                               <id>copy-xsl</id>\r
-                                               <goals>\r
-                                                       <goal>copy-resources</goal>\r
-                                               </goals>\r
-                                               <phase>validate</phase>\r
-                                               <configuration>\r
-                                                       <outputDirectory>${basedir}/target/templates/xslt/sbg</outputDirectory>\r
-                                                       <resources>\r
-                                                               <resource>\r
-                                                                       <directory>src/main/resources/xsl</directory>\r
-                                                                       <includes>\r
-                                                                               <include>*</include>\r
-                                                                       </includes>\r
-                                                                       <filtering>true</filtering>\r
-                                                               </resource>\r
-                                                       </resources>\r
-                                               </configuration>\r
-                                       </execution>\r
-                                       <execution>\r
-                                               <id>copy-properties</id>\r
-                                               <goals>\r
-                                                       <goal>copy-resources</goal>\r
-                                               </goals>\r
-                                               <phase>validate</phase>\r
-                                               <configuration>\r
-                                                       <outputDirectory>${basedir}/target/properties/</outputDirectory>\r
-                                                       <resources>\r
-                                                               <resource>\r
-                                                                       <directory>src/main/resources</directory>\r
-                                                                       <includes>\r
-                                                                               <include>*.properties</include>\r
-                                                                       </includes>\r
-                                                                       <filtering>true</filtering>\r
-                                                               </resource>\r
-                                                       </resources>\r
-                                               </configuration>\r
-                                       </execution>\r
-                               </executions>\r
-                       </plugin>\r
-                       <plugin>\r
-                               <groupId>org.apache.felix</groupId>\r
-                               <artifactId>maven-bundle-plugin</artifactId>\r
-                               <version>${bundle.plugin.version}</version>\r
-                               <extensions>true</extensions>\r
-                               <configuration>\r
-                                       <instructions>\r
-                                               <Bundle-SymbolicName>org.onap.appc.aai.client</Bundle-SymbolicName>\r
-                                               <Bundle-Activator>org.onap.appc.aai.client.AppcAaiClientActivator</Bundle-Activator>\r
-                                               <Export-Package>org.onap.appc.aai.client,org.onap.appc.aai.client.*</Export-Package>\r
-                                               <Import-Package>groovy.lang;resolution:=optional,\r
-                                                   org.codehaus.groovy.*;resolution:=optional,*</Import-Package>\r
-                                               <DynamicImport-Package>*</DynamicImport-Package>\r
-                                               <Embed-Dependency>eelf-core,logback-core,logback-classic</Embed-Dependency>\r
-                                       </instructions>\r
-                                       <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>\r
-                               </configuration>\r
-                       </plugin>\r
-               </plugins>\r
-               <pluginManagement>\r
-                       <plugins>\r
-                       </plugins>\r
-               </pluginManagement>\r
-       </build>\r
-       <version>1.5.0-SNAPSHOT</version>\r
-</project>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ============LICENSE_START=======================================================
+  ONAP : APPC
+  ================================================================================
+  Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+  Copyright (C) 2017 Amdocs
+  Modifications Copyright (C) 2019 Ericsson
+  ================================================================================
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  ============LICENSE_END=========================================================
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.onap.appc.parent</groupId>
+               <artifactId>binding-parent</artifactId>
+               <version>1.5.0-SNAPSHOT</version>
+                <relativePath />
+       </parent>
+        <groupId>org.onap.appc</groupId>
+       <artifactId>appc-aai-client-provider</artifactId>
+       <packaging>bundle</packaging>
+       <name>APPC AAI Client - Provider</name>
+
+       <properties>
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+       </properties>
+       <dependencies>
+               <dependency>
+                       <groupId>org.onap.ccsdk.sli.core</groupId>
+                       <artifactId>sli-provider</artifactId>
+                       <scope>compile</scope>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.onap.ccsdk.sli.adaptors</groupId>
+                       <artifactId>aai-service-provider</artifactId>
+                       <scope>compile</scope>
+               </dependency>
+
+
+               <dependency>
+                       <groupId>commons-io</groupId>
+                       <artifactId>commons-io</artifactId>
+                       <version>2.5</version>
+               </dependency>
+                <dependency>
+                       <groupId>org.apache.commons</groupId>
+                       <artifactId>commons-lang3</artifactId>
+               </dependency>
+                <dependency>
+                        <groupId>ch.qos.logback</groupId>
+                        <artifactId>logback-classic</artifactId>
+                       <version>${logback.version}</version>
+                </dependency>
+               <dependency>
+                       <groupId>com.att.eelf</groupId>
+                       <artifactId>eelf-core</artifactId>
+                        <exclusions>
+                            <exclusion>
+                                 <groupId>ch.qos.logback</groupId>
+                                 <artifactId>logback-classic</artifactId>
+                            </exclusion>
+                        </exclusions>
+               </dependency>
+
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <scope>test</scope>
+               </dependency>
+
+
+
+       </dependencies>
+       <build>
+               <plugins>
+                       <plugin>
+                               <artifactId>maven-resources-plugin</artifactId>
+                               <version>2.6</version>
+                               <executions>
+                                       <execution>
+                                               <id>copy-xsl</id>
+                                               <goals>
+                                                       <goal>copy-resources</goal>
+                                               </goals>
+                                               <phase>validate</phase>
+                                               <configuration>
+                                                       <outputDirectory>${basedir}/target/templates/xslt/sbg</outputDirectory>
+                                                       <resources>
+                                                               <resource>
+                                                                       <directory>src/main/resources/xsl</directory>
+                                                                       <includes>
+                                                                               <include>*</include>
+                                                                       </includes>
+                                                                       <filtering>true</filtering>
+                                                               </resource>
+                                                       </resources>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>copy-properties</id>
+                                               <goals>
+                                                       <goal>copy-resources</goal>
+                                               </goals>
+                                               <phase>validate</phase>
+                                               <configuration>
+                                                       <outputDirectory>${basedir}/target/properties/</outputDirectory>
+                                                       <resources>
+                                                               <resource>
+                                                                       <directory>src/main/resources</directory>
+                                                                       <includes>
+                                                                               <include>*.properties</include>
+                                                                       </includes>
+                                                                       <filtering>true</filtering>
+                                                               </resource>
+                                                       </resources>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <version>${bundle.plugin.version}</version>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-SymbolicName>org.onap.appc.aai.client</Bundle-SymbolicName>
+                                               <Bundle-Activator>org.onap.appc.aai.client.AppcAaiClientActivator</Bundle-Activator>
+                                               <Export-Package>org.onap.appc.aai.client,org.onap.appc.aai.client.*</Export-Package>
+                                               <Import-Package>groovy.lang;resolution:=optional,
+                                                   org.codehaus.groovy.*;resolution:=optional,*</Import-Package>
+                                               <DynamicImport-Package>*</DynamicImport-Package>
+                                               <Embed-Dependency>eelf-core,logback-core,logback-classic</Embed-Dependency>
+                                       </instructions>
+                                       <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+                               </configuration>
+                       </plugin>
+               </plugins>
+               <pluginManagement>
+                       <plugins>
+                       </plugins>
+               </pluginManagement>
+       </build>
+       <version>1.5.0-SNAPSHOT</version>
+</project>
index 76336c1..a25013f 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -263,7 +265,6 @@ public class AaiService {
 
             log.info(QUERY_STR_VNFC_NAME + ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME));
             String vnfcNameAAI = ctx.getAttribute(aaiRefKey + ATTR_VNFC_NAME);
-
             // Get Vnfc_reference data from the table
             String vnfcRefKey = STR_VNFC_REF + vnfcRefIndx + "].";
 
index e32cc94..27bf84a 100644 (file)
@@ -7,6 +7,8 @@
  * Copyright (C) 2017 Amdocs
  * =============================================================================
  * Modifications Copyright (C) 2018 IBM.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -79,8 +81,8 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
             AaiService aai = getAaiService();
             aai.getGenericVnfInfo(inParams, ctx);
 
-            String cloudOwnerValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
-            String cloudRegionValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
+            String cloudOwnerValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
+            String cloudRegionValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
 
             log.debug("Cloud Owner" + cloudOwnerValue);
             log.debug("CloudRegionId" + cloudOwnerValue);
@@ -88,7 +90,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
             paramsCloud.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
                     inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
 
-            if(StringUtils.isNotBlank(cloudOwnerValue)&&StringUtils.isNotBlank(cloudRegionValue)) {
+            if(StringUtils.isNotBlank(cloudOwnerValue) && StringUtils.isNotBlank(cloudRegionValue)) {
 
                 paramsCloud.put(PARAM_CLOUD_OWNER, cloudOwnerValue);
                 paramsCloud.put(PARAM_CLOUD_REGION_ID, cloudRegionValue);
@@ -127,7 +129,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
             int vmCountForVfModule = 0;
             String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
             String vfModuleFromRequest =  ctx.getAttribute("req-vf-module-id");
-            log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
+            log.info("getAllVServersVnfcsInfo()::: vfMOdule=" + vfModuleFromRequest);
 
             if (vmCountStr == null) {
                 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
@@ -196,7 +198,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
                 } else {
                     vmWithNoVnfcsCount++;
                     //ConfigScaleOut
-                    log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
+                    log.info("getAllVServersVnfcsInfo()::Vf Modules: " + vfModuleForVserver+", " + vfModuleFromRequest);
                     if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
                         vmsWithNoVnfcsForVfModule++;
                     }
@@ -342,19 +344,19 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
         int vmsWithoutVnfcsForVfModule = 0;
         String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
         if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
-            log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
+            log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule=" + vfModuleIdFromRequest);
         }
         else {
             vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
         }
-        log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
-        String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
+        log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: " + vmsWithoutVnfcsForVfModule);
+        String vmsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-count-for-vf-module");
         int vmsForVfModule = 0;
         if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
             vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
         }
         if ((vmsForVfModule != vnfcRefLen ) &&  StringUtils.isNotBlank(vfModuleIdFromRequest)) {
-            throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
+            throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request=" + vfModuleIdFromRequest);
         }
         log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
 
@@ -516,7 +518,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
         try {
             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
             AaiService aaiService = getAaiService();
-            processForVfModuleModelInfo(aaiService,inParams,ctx);
+            processForVfModuleModelInfo(aaiService, inParams, ctx);
         } catch (Exception e) {
             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
                 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
@@ -554,10 +556,10 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
                 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
                 return;
             }
-            aaiService.getModelVersionInfo(modelParams,modelCtx);
-            String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
-            log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
-            log.info("Setting context template-model-id as :::"+modelName);
+            aaiService.getModelVersionInfo(modelParams, modelCtx);
+            String modelName = modelCtx.getAttribute(responsePrefix + "vfModule.model-name");
+            log.info("processForVfModuleModelInfo()::modelName for vfModule:::" + modelName);
+            log.info("Setting context template-model-id as :::" + modelName);
             ctx.setAttribute("template-model-id", modelName);
             log.info("processForVfModuleModelInfo() ::: End");
             }
@@ -580,7 +582,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
                 return;
             }
             String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
-            outputValue = StringUtils.replace(outputValue," ","");//remove space
+            outputValue = StringUtils.replace(outputValue, " ", "");//remove space
             ctx.setAttribute("template-model-id", outputValue);
         } catch (Exception e) {
             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
index 671c355..9087a7f 100644 (file)
@@ -7,6 +7,8 @@
  * Copyright (C) 2017 Amdocs
  * =============================================================================
  * Modification Copyright (C) 2018 IBM.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,20 +31,134 @@ import static org.junit.Assert.assertEquals;
 
 import java.util.HashMap;
 import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({FrameworkUtil.class})
 public class TestAaiService {
     // ONAP merging
 
     private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class);
-    private AAIClient aaiClient;
+    private AAIClient aaiClient = Mockito.mock(AAIClient.class);
+    private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
+    private final Bundle bundleService=Mockito.mock(Bundle.class);
+    private final ServiceReference sref=Mockito.mock(ServiceReference.class);
+
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
+
+    @Before
+    public void setup() {
+        PowerMockito.mockStatic(FrameworkUtil.class);
+        PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
+        PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
+        PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
+        PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiClient);
+    }
+
+    @Test
+    public void testMissingVnfId() throws AaiServiceInternalException, SvcLogicException {
+        AaiService aaiService = new AaiService();
+        expectedEx.expect(AaiServiceInternalException.class);
+        expectedEx.expectMessage("VnfId is missing");
+        aaiService.getGenericVnfInfo(new HashMap<String, String>(), new SvcLogicContext());
+    }
+
+    @Test
+    public void testGetVmInfoExceptionFlow() throws SvcLogicException, AaiServiceInternalException {
+        AaiService aaiService = Mockito.spy(new AaiService());
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("vserverId", "vserverId1");
+        inParams.put("tenantId", "tenantId1");
+        inParams.put("cloudOwner", "cloudOwner1");
+        inParams.put("cloudRegionId", "cloudRegionId1");
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+
+        SvcLogicContext ctx = new SvcLogicContext();
+        Mockito.doThrow(new SvcLogicException()).when(aaiService).readResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("Failed to fetch VM info");
+        aaiService.getVMInfo(inParams, ctx);
+    }
+
+    @Test
+    public void testGetVnfcInfoExceptionFlow() throws Exception {
+        AaiService aaiService = new AaiService();
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("vnfcName", "");
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        SvcLogicContext ctx = new SvcLogicContext();
+        expectedEx.expect(AaiServiceInternalException.class);
+        expectedEx.expectMessage("Vnfc Name is missing");
+        aaiService.getVnfcInfo(inParams, ctx);
+    }
+
+    @Test
+    public void testInsertVnfcsExceptionFlow() throws Exception {
+        AaiService aaiService = new AaiService();
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        SvcLogicContext ctx = new SvcLogicContext();
+        inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-name", "nullnull001");
+        aaiService.insertVnfcs(inParams, ctx, 2, 2, null);
+    }
+
+    @Test
+    public void testGetVnfcData() {
+        AaiService aaiService = new AaiService();
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        SvcLogicContext ctx = new SvcLogicContext();
+        inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-name", "nullnull001");
+        aaiService.getVnfcData(inParams, ctx, 1, 1);
+    }
+
+    @Test
+    public void testReadResource() throws AaiServiceInternalException, SvcLogicException {
+        AaiService aaiService = Mockito.spy(new AaiService());
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+        Mockito.doReturn(QueryStatus.FAILURE).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+                Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class));
+        expectedEx.expect(AaiServiceInternalException.class);
+        expectedEx.expectMessage("Error Retrieving null from A&AI");
+        aaiService.readResource(null, null, null);
+    }
+
+    @Test
+    public void testCheckAndUpdateVnfc() throws AaiServiceInternalException, SvcLogicException {
+        AaiService aaiService = Mockito.spy(new AaiService());
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        SvcLogicContext ctx = new SvcLogicContext();
+        inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+        ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-name", "nullnull001");
+        aaiService.checkAndUpdateVnfc(inParams, ctx, 1, 1);
+        Mockito.verify(aaiService).updateVnfcStatus(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString());
+    }
 
     @Test
     public void testGetGenericVnfInfo() throws Exception {
@@ -255,6 +371,7 @@ public class TestAaiService {
 
 
     }
+
     @Test
     public void testInsertVnfcsForRelativeValueSame() throws Exception {
 
@@ -327,23 +444,6 @@ public class TestAaiService {
         mockAai.updateVnfStatus(inParams, ctx);
     }
 
-    @Test
-    public void testReadResource() throws Exception {
-
-        MockAaiService mockAai = new MockAaiService(aaiClient);
-        // AaiService mockAai = new AaiService(new AAIClientMock());
-
-        String vnfId = "ibcx0001v";
-        String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
-        String resourceType = "generic-vnf";
-        String queryPrefix = "vnfInfo";
-        SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType);
-
-        // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type");
-
-        assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch");
-
-    }
     private void printContext(SvcLogicContext ctx) throws Exception {
         for (String key : ctx.getAttributeKeySet()) {
             log.info(" KEY " + key);
@@ -399,7 +499,7 @@ public class TestAaiService {
         assertEquals(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url"), "TestUrl");
 
     } 
-    
+
     @Test
     public void testAddvnfc()
     {
index b3944b7..cb07584 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.appc.aai.client.node;
 
-import static org.junit.Assert.*;
 
-import java.io.File;
-import java.nio.charset.Charset;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
 import org.onap.appc.aai.client.AppcAaiClientConstant;
 import org.onap.appc.aai.client.aai.AaiService;
-import org.onap.appc.aai.client.aai.TestAaiService;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 
 public class TestAAIResourceNode {
@@ -58,27 +53,40 @@ public class TestAAIResourceNode {
 
     private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class);
 
-    @Test
-    public void sortVServer() throws Exception{
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
 
-        //log.info("Test");
+    @Test
+    public void testGetVnfInfo() throws Exception {
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("vm[0].cloud-owner", "TEST");
+        ctx.setAttribute("vm[0].cloud-region-id", "TEST");
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        aai.getVnfInfo(inParams, ctx);
+        Mockito.verify(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+    }
 
+    @Test
+    public void sortVServer() throws Exception{
         ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
-        HashMap<String, String> vserverMap = new HashMap<String, String>();
+        Map<String, String> vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId9");
         vserverMap.put("tenant-id", "tenantId9");
         vserverMap.put("cloud-owner", "cloudOwner9");
         vserverMap.put("cloud-region-id", "cloudRegionId9");
         vserverMap.put("vserver-name", "vServerName9");
         vservers.add(vserverMap);
-        vserverMap = new HashMap<String, String>();
+        vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId1");
         vserverMap.put("tenant-id", "tenantId1");
         vserverMap.put("cloud-owner", "cloudOwner1");
         vserverMap.put("cloud-region-id", "cloudRegionId1");
         vserverMap.put("vserver-name", "vServerName1");
         vservers.add(vserverMap);
-        vserverMap = new HashMap<String, String>();
+        vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId3");
         vserverMap.put("tenant-id", "tenantId3");
         vserverMap.put("cloud-owner", "cloudOwner3");
@@ -104,7 +112,7 @@ public class TestAAIResourceNode {
         MockAAIResourceNode mrn = new MockAAIResourceNode();
         SvcLogicContext ctx = new SvcLogicContext();
         populateAllVServerInfo(ctx, "tmp.vnfInfo");
-        Map<String, String> inParams  =new HashMap<String, String>();
+        Map<String, String> inParams = new HashMap<>();
         inParams.put("responsePrefix", "tmp.vnfInfo");
         mrn.getAllVServersVnfcsInfo(inParams, ctx);
         assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
@@ -138,6 +146,18 @@ public class TestAAIResourceNode {
         assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count-for-vf-module"),"1");
     }
 
+    @Test
+    public void testAllVServerExceptionFlow() throws Exception{
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        SvcLogicContext ctx = new SvcLogicContext();
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("Unable to get VServers for the VNF");
+        aai.getAllVServersVnfcsInfo(inParams, ctx);
+    }
+
     public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception {
          ctx.setAttribute("vnf-id", "ibcx0001v");
          ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
@@ -150,7 +170,6 @@ public class TestAAIResourceNode {
          ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1");
          ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1");
          ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1");
-
     }
 
     public static class MockAAIResourceNode extends AAIResourceNode {
@@ -165,10 +184,9 @@ public class TestAAIResourceNode {
 
     @Test
     public void testPopulateContext() throws Exception{
-
         ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
-        HashMap<String, String> vserverMap = new HashMap<String, String>();
-        vserverMap = new HashMap<String, String>();
+        Map<String, String> vserverMap = new HashMap<>();
+        vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId1");
         vserverMap.put("tenant-id", "tenantId1");
         vserverMap.put("cloud-owner", "cloudOwner1");
@@ -176,14 +194,14 @@ public class TestAAIResourceNode {
         vserverMap.put("vserver-name", "vServerName1");
         vserverMap.put("vnfc-name", "vnfcName1");
         vservers.add(vserverMap);
-        vserverMap = new HashMap<String, String>();
+        vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId3");
         vserverMap.put("tenant-id", "tenantId3");
         vserverMap.put("cloud-owner", "cloudOwner3");
         vserverMap.put("cloud-region-id", "cloudRegionId3");
         vserverMap.put("vserver-name", "vServerName3");
         vservers.add(vserverMap);
-        vserverMap = new HashMap<String, String>();
+        vserverMap = new HashMap<>();
         vserverMap.put("vserver-id", "vserverId9");
         vserverMap.put("tenant-id", "tenantId9");
         vserverMap.put("cloud-owner", "cloudOwner9");
@@ -202,84 +220,107 @@ public class TestAAIResourceNode {
     }
 
     @Test
-    public final void testGetVnfInfo() {
+    public final void testGetVnfInfoExceptionFlow() throws Exception {
         SvcLogicContext ctx = new SvcLogicContext();
-        AAIResourceNode aai = new AAIResourceNode();
-Map<String, String> inParams  =new HashMap<String, String>();
-        inParams.put("responsePrefix", "tmp.vnfInfo");
-        try {
-            aai.getVnfInfo(inParams, ctx);
-        } catch (SvcLogicException e) {
-            e.printStackTrace();
-        }
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        ctx.setAttribute("vm[0].cloud-owner", "TEST");
+        ctx.setAttribute("vm[0].cloud-region-id", "TEST");
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        expectedEx.expect(SvcLogicException.class);
+        expectedEx.expectMessage("TEST");
+        aai.getVnfInfo(inParams, ctx);
+    }
 
+    @Test
+    public final void testaddVnfcs() throws SvcLogicException
+    {
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("vnfcReference_length", "1");
+        ctx.setAttribute("vnf.vm-count", "1");
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        aai.addVnfcs(inParams, ctx);
     }
+
     @Test
-    public final void testaddVnfcs()
+    public final void testaddVnfcsExceptionFlow() throws Exception
     {
         SvcLogicContext ctx = new SvcLogicContext();
-        AAIResourceNode aai = new AAIResourceNode();
-Map<String, String> inParams  =new HashMap<String, String>();
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
         inParams.put("responsePrefix", "tmp.vnfInfo");
-        try {
-            aai.addVnfcs(inParams, ctx);
-        } catch (SvcLogicException e) {
-            e.printStackTrace();
-        }
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        expectedEx.expect(SvcLogicException.class);
+        aai.addVnfcs(inParams, ctx);
+    }
 
+    @Test
+    public final void  testupdateVnfAndVServerStatus() throws SvcLogicException{
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("vnf.vm-count", "1");
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        aai.updateVnfAndVServerStatus(inParams, ctx);
+        assertEquals(AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute(AppcAaiClientConstant.OUTPUT_PARAM_STATUS));
     }
+
     @Test
-    public final void  testupdateVnfAndVServerStatus(){
+    public final void  testupdateVnfAndVServerStatusExceptionFlow() throws SvcLogicException{
         SvcLogicContext ctx = new SvcLogicContext();
         AAIResourceNode aai = new AAIResourceNode();
-Map<String, String> inParams  =new HashMap<String, String>();
-
-        inParams.put("responsePrefix", "tmp.vnfInfo");
-        try {
-            aai.updateVnfAndVServerStatus(inParams, ctx);
-        } catch (SvcLogicException e) {
-            e.printStackTrace();
-        }
+        Map<String, String> inParams = new HashMap<>();
+        expectedEx.expect(SvcLogicException.class);
+        aai.updateVnfAndVServerStatus(inParams, ctx);
     }
 
     @Test
     public void testgetVfModduleModelInfo() throws Exception{
         SvcLogicContext ctx = new SvcLogicContext();
         AAIResourceNode aai = new AAIResourceNode();
-        AAIClient aaic=null;
-        MockAaiService aaiService=new MockAaiService(aaic);
-        Map<String, String> inParams  =new HashMap<String, String>();
+        AAIClient aaic = null;
+        MockAaiService aaiService = new MockAaiService(aaic);
+        Map<String, String> inParams = new HashMap<>();
         inParams.put("responsePrefix", "tmp.vnfInfo");
-        aai.processForVfModuleModelInfo(aaiService,inParams, ctx);
-        assertEquals(ctx.getAttribute("template-model-id"),"model0001");
-
+        aai.processForVfModuleModelInfo(aaiService, inParams, ctx);
+        assertEquals(ctx.getAttribute("template-model-id"), "model0001");
     }
+
     @Test
     public final void testSetVmParams() {
         SvcLogicContext ctx = new SvcLogicContext();
         String vServerId = "vserver02";
         ctx.setAttribute("tmp.vnfInfo.vm-count","3");
-        ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id","vserver01");
-        ctx.setAttribute("tmp.vnfInfo.vm[1].vserver-id","vserver02");
-        ctx.setAttribute("tmp.vnfInfo.vm[1].tenant-id","ten01");
-        ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-region-id","cr01");
-        ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-owner","co01");
+        ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id", "vserver01");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].vserver-id", "vserver02");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].tenant-id", "ten01");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-region-id", "cr01");
+        ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-owner", "co01");
         AAIResourceNode aairn= new AAIResourceNode();
-        Map <String, String> params  = aairn.setVmParams(ctx, vServerId);
+        Map <String, String> params = aairn.setVmParams(ctx, vServerId);
         assertNotNull(params);
     }
+
     @Test
     public final void testGetVnfcInformationForVserver() throws Exception{
         MockAAIResourceNode aairn = new MockAAIResourceNode();
         SvcLogicContext ctx = new SvcLogicContext();
         SvcLogicContext newVnfcCtx = new SvcLogicContext();
-        Map<String,String> inParams = new HashMap<String, String>();
-        Map<String,String> vnfcParams = new HashMap<String, String>();
-        String responsePrefix="test.";
+        Map<String, String> inParams = new HashMap<>();
+        Map<String, String> vnfcParams = new HashMap<>();
+        String responsePrefix = "test.";
         inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
         vnfcParams.put("vnfcName", "vnfcName2");
         aairn.getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aairn.getAaiService(), responsePrefix);
-        assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-name"),"vnfcName2");
+        assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-name"), "vnfcName2");
         assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-type"), "vnfcType2");
         assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-function-code"), "vnfcFuncCode2");
         assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-group-notation"), "vnfcGrpNot2");
@@ -289,12 +330,11 @@ Map<String, String> inParams  =new HashMap<String, String>();
     public final void testGetFormattedValue() throws Exception{
         MockAAIResourceNode aairn = new MockAAIResourceNode();
         SvcLogicContext ctx = new SvcLogicContext();
-        Map<String,String> inParams = new HashMap<String, String>();
+        Map<String, String> inParams = new HashMap<>();
         inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
         inParams.put("inputParameter", "Some/Value/With/ Many Spaces");
         aairn.getFormattedValue(inParams, ctx);
-        assertEquals(ctx.getAttribute("template-model-id"),"Some_Value_With_ManySpaces");
-
+        assertEquals(ctx.getAttribute("template-model-id"), "Some_Value_With_ManySpaces");
     }
 
     @Test
@@ -307,7 +347,30 @@ Map<String, String> inParams  =new HashMap<String, String>();
         ctx.setAttribute("test.vnf.vm-with-no-vnfcs-count-vf-module", "0");
         ctx.setAttribute("test.vnf.vm-count-for-vf-module", "2");
         aairn.processCheckForVfModule("vfmoduleId1", ctx, "test.", 2);
+    }
 
+    @Test
+    public void testGetVserverInfo() throws SvcLogicException {
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("tmp.vnfInfo.vm-count", "1");
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Map<String, String> inParams = new HashMap<>();
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        aai.getVserverInfo(inParams, ctx);
+        Mockito.verify(aaiService).getVMInfo(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+    }
 
+    @Test
+    public void testGetVserverInfoExceptionFlow() throws Exception {
+        SvcLogicContext ctx = new SvcLogicContext();
+        ctx.setAttribute("tmp.vnfInfo.vm-count", "1");
+        Map<String, String> inParams = new HashMap<>();
+        AaiService aaiService = Mockito.mock(AaiService.class);
+        AAIResourceNode aai = Mockito.spy(new AAIResourceNode());
+        Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getVMInfo(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+        Mockito.doReturn(aaiService).when(aai).getAaiService();
+        aai.getVserverInfo(inParams, ctx);
+        assertEquals("TEST", ctx.getAttribute(AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE));
     }
 }