From 71b522de83d67ddd2fec091015ff606ba58eac3a Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 8 Jan 2018 10:44:03 +0000 Subject: Improve unit test for VNFQuery Imporve unit test for vnfquery. Change-Id: Ie8da164dce3e7f5186a7be742860fbaefc4e1b59 Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../openecomp/mso/adapters/vnf/test/QueryTest.java | 121 ++++++++++++++++----- 1 file changed, 91 insertions(+), 30 deletions(-) (limited to 'adapters/mso-vnf-adapter') diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java index a99bd3952c..315db2eb83 100644 --- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java @@ -25,40 +25,101 @@ import java.util.Map; import javax.xml.ws.Holder; +import mockit.Mock; +import mockit.MockUp; +import org.junit.Test; import org.openecomp.mso.adapters.vnf.MsoVnfAdapter; import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl; +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.adapters.vnf.exceptions.VnfException; +import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.utils.MsoHeatUtils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class QueryTest { - public final static void main (String args[]) - { - MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(); - log ("Got a VnfAdapter"); - - String cloudId = "MT"; - String tenantId = "MSO_Test"; - String vnfName = "VNF_TEST1"; - Holder vnfExists = new Holder(); - Holder vnfId = new Holder(); - Holder status = new Holder(); - Holder> outputs = new Holder>(); - - try { - vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, - vnfExists, vnfId, status, outputs); - } catch (VnfException e) { - log ("Got an Exception: " + e); - } - - if (! vnfExists.value){ - log ("VNF Not Found"); - } else { - log ("Found VNF, ID = " + vnfId.value + ", status=" + status.value); - } - } - - private static void log (String msg) { - System.out.println (msg); - } + + @Test + public void testQueryCreatedVnf() throws VnfException { + { + new MockUp() { + @Mock + public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { + StackInfo info = new StackInfo(); + info.setStatus(HeatStatus.CREATED); + return info; + } + }; + + MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(); + String cloudId = "MT"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder vnfExists = new Holder(); + Holder vnfId = new Holder(); + Holder status = new Holder(); + Holder> outputs = new Holder>(); + + vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, + vnfExists, vnfId, status, outputs); + + assertTrue(vnfExists.value); + } + } + + @Test + public void testQueryNotFoundVnf() throws VnfException { + { + new MockUp() { + @Mock + public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { + StackInfo info = new StackInfo(); + info.setStatus(HeatStatus.NOTFOUND); + return info; + } + }; + + MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(); + String cloudId = "MT"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder vnfExists = new Holder(); + Holder vnfId = new Holder(); + Holder status = new Holder(); + Holder> outputs = new Holder>(); + + vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, + vnfExists, vnfId, status, outputs); + + assertFalse(vnfExists.value); + } + } + + @Test(expected = VnfException.class) + public void testQueryVnfWithException() throws VnfException { + { + new MockUp() { + @Mock + public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { + throw new MsoCloudSiteNotFound(cloudSiteId); + } + }; + + MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(); + String cloudId = "MT"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder vnfExists = new Holder(); + Holder vnfId = new Holder(); + Holder status = new Holder(); + Holder> outputs = new Holder>(); + + vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, + vnfExists, vnfId, status, outputs); + } + } } -- cgit 1.2.3-korg