From: Soumendu Sekhar Acharya Date: Tue, 7 Aug 2018 11:20:48 +0000 (+0530) Subject: Epic-231 cbr junit testcase of SDNC-258 X-Git-Tag: 1.4.1~72 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=46cb2d3a105021fe4aeed8aa462c31ce50bad39f;p=sdnc%2Foam.git 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 Former-commit-id: c07d55ffd5e1838e2ec4fc6204e8a6762674f5e9 --- 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"); + } + + +}