From c07d55ffd5e1838e2ec4fc6204e8a6762674f5e9 Mon Sep 17 00:00:00 2001 From: Soumendu Sekhar Acharya Date: Tue, 7 Aug 2018 16:50:48 +0530 Subject: [PATCH] Epic-231 cbr junit testcase of SDNC-258 JUNIT Testcase for getBackupVnfDetailService Change-Id: I8b4f96b46bcfb23d35c183eed7c2ee949b956900 Issue-ID: SDNC-413 Signed-off-by: Soumendu Sekhar Acharya --- .../service/VnfComparisonServiceTest.java | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java diff --git a/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java b/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java new file mode 100644 index 00000000..0afcd69c --- /dev/null +++ b/configbackuprestore/getBackupVnfDetailService/src/test/java/com/onap/sdnc/vnfconfigcomparsion/service/VnfComparisonServiceTest.java @@ -0,0 +1,123 @@ +package com.onap.sdnc.vnfconfigcomparsion.service; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.anyString; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails; + + + +@RunWith(MockitoJUnitRunner.class) +public class VnfComparisonServiceTest { + + @InjectMocks + VnfComparisonService vnfComparisonService; + + @Mock + VnfComparisonRepository vnfComparisonRepository; + + @Test + public void testGetConfigurationDeatils_1() throws JSONException { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\"] }"); + String vnfId = "1a"; + List vnfDetailslist = new ArrayList(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + //Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId); + assertEquals(value.getConfiginfo(), exampleJson); + + } + + @Test + public void testGetConfigurationDeatils() throws Exception { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }"); + // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }"; + String vnfId = "1a"; + List vnfDetailslist = new ArrayList(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + + response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId); + System.out.println(response); + assertNotNull(response); + assertEquals(value.getConfiginfo(), exampleJson); + assertEquals(value.getVnfid(), vnfId); + assertEquals(value.getStatus(), "Y"); + } + + @Test + public void testgetConfigDeatilsByVnfIdVnfVersion() throws JSONException { + VnfCompareResponse response = new VnfCompareResponse(); + String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}"; + JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }"); + // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }"; + String vnfId = "1a"; + List vnfDetailslist = new ArrayList(); + VnfDetails vnfdetails = new VnfDetails(); + JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames"); + VnfConfigDetailsDB value = new VnfConfigDetailsDB(); + value.setVnfid("1a"); + value.setConfiginfo(exampleJson); + value.setId(1); + value.setLastupdated("05-22-2018"); + value.setStatus("Y"); + value.setVnfname("vnf1"); + value.setVnfversion("1.0"); + + Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value); + response.setVnfDetails(vnfDetailslist); + + response = vnfComparisonService.getConfigDeatilsByVnfIdVnfVersion(vnfVersionNames, vnfId); + System.out.println(response); + assertNotNull(response); + assertEquals(value.getConfiginfo(), exampleJson); + assertEquals(value.getVnfid(), vnfId); + assertEquals(value.getStatus(), "Y"); + } + + +} -- 2.16.6