aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-08 10:44:03 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-08 11:10:19 +0000
commit71b522de83d67ddd2fec091015ff606ba58eac3a (patch)
tree54dee62b13c8618c524a2e6423f640055c842c4a /adapters
parent4108c5aca1ee4c556af3937c09c4415d2ebbde70 (diff)
Improve unit test for VNFQuery
Imporve unit test for vnfquery. Change-Id: Ie8da164dce3e7f5186a7be742860fbaefc4e1b59 Issue-ID: SO-360 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java121
1 files changed, 91 insertions, 30 deletions
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<Boolean> vnfExists = new Holder<Boolean>();
- Holder<String> vnfId = new Holder<String>();
- Holder<VnfStatus> status = new Holder<VnfStatus>();
- Holder<Map<String,String>> outputs = new Holder<Map<String,String>>();
-
- 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<MsoHeatUtils>() {
+ @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<Boolean> vnfExists = new Holder<Boolean>();
+ Holder<String> vnfId = new Holder<String>();
+ Holder<VnfStatus> status = new Holder<VnfStatus>();
+ Holder<Map<String, String>> outputs = new Holder<Map<String, String>>();
+
+ 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();
+ info.setStatus(HeatStatus.NOTFOUND);
+ return info;
+ }
+ };
+
+ MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
+ String cloudId = "MT";
+ String tenantId = "MSO_Test";
+ String vnfName = "VNF_TEST1";
+ Holder<Boolean> vnfExists = new Holder<Boolean>();
+ Holder<String> vnfId = new Holder<String>();
+ Holder<VnfStatus> status = new Holder<VnfStatus>();
+ Holder<Map<String, String>> outputs = new Holder<Map<String, String>>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
+ vnfExists, vnfId, status, outputs);
+
+ assertFalse(vnfExists.value);
+ }
+ }
+
+ @Test(expected = VnfException.class)
+ public void testQueryVnfWithException() throws VnfException {
+ {
+ new MockUp<MsoHeatUtils>() {
+ @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<Boolean> vnfExists = new Holder<Boolean>();
+ Holder<String> vnfId = new Holder<String>();
+ Holder<VnfStatus> status = new Holder<VnfStatus>();
+ Holder<Map<String, String>> outputs = new Holder<Map<String, String>>();
+
+ vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
+ vnfExists, vnfId, status, outputs);
+ }
+ }
}