1 package com.onap.sdnc.vnfconfigcomparsion.service;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.mockito.Matchers.anyString;
8 import java.util.ArrayList;
11 import org.json.JSONArray;
12 import org.json.JSONException;
13 import org.json.JSONObject;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.InjectMocks;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
21 import com.onap.sdnc.vnfcomparsion.dao.VnfComparisonRepository;
22 import com.onap.sdnc.vnfconfigcomparsion.model.VnfCompareResponse;
23 import com.onap.sdnc.vnfconfigcomparsion.model.VnfConfigDetailsDB;
24 import com.onap.sdnc.vnfconfigcomparsion.model.VnfDetails;
28 @RunWith(MockitoJUnitRunner.class)
29 public class VnfComparisonServiceTest {
32 VnfComparisonService vnfComparisonService;
35 VnfComparisonRepository vnfComparisonRepository;
38 public void testGetConfigurationDeatils_1() throws JSONException {
39 VnfCompareResponse response = new VnfCompareResponse();
40 String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}";
41 JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\"] }");
43 List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>();
44 VnfDetails vnfdetails = new VnfDetails();
45 JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames");
46 VnfConfigDetailsDB value = new VnfConfigDetailsDB();
48 value.setConfiginfo(exampleJson);
50 value.setLastupdated("05-22-2018");
52 value.setVnfname("vnf1");
53 value.setVnfversion("1.0");
55 //Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
56 response.setVnfDetails(vnfDetailslist);
57 response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId);
58 assertEquals(value.getConfiginfo(), exampleJson);
63 public void testGetConfigurationDeatils() throws Exception {
64 VnfCompareResponse response = new VnfCompareResponse();
65 String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}";
66 JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }");
67 // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }";
69 List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>();
70 VnfDetails vnfdetails = new VnfDetails();
71 JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames");
72 VnfConfigDetailsDB value = new VnfConfigDetailsDB();
74 value.setConfiginfo(exampleJson);
76 value.setLastupdated("05-22-2018");
78 value.setVnfname("vnf1");
79 value.setVnfversion("1.0");
81 Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
82 response.setVnfDetails(vnfDetailslist);
84 response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId);
85 System.out.println(response);
86 assertNotNull(response);
87 assertEquals(value.getConfiginfo(), exampleJson);
88 assertEquals(value.getVnfid(), vnfId);
89 assertEquals(value.getStatus(), "Y");
93 public void testgetConfigDeatilsByVnfIdVnfVersion() throws JSONException {
94 VnfCompareResponse response = new VnfCompareResponse();
95 String exampleJson = "{\"vnfname\":\"vnfversion\":[\"vnf1\",\"1.0\"]}";
96 JSONObject vnfVersionNames = new JSONObject("{ \"versionNames\":[\"1.0\",\"2.0\"] }");
97 // String vnfversion = "{ \"versionNames\":[\"Version-1\"] }";
99 List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>();
100 VnfDetails vnfdetails = new VnfDetails();
101 JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames");
102 VnfConfigDetailsDB value = new VnfConfigDetailsDB();
103 value.setVnfid("1a");
104 value.setConfiginfo(exampleJson);
106 value.setLastupdated("05-22-2018");
107 value.setStatus("Y");
108 value.setVnfname("vnf1");
109 value.setVnfversion("1.0");
111 Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
112 response.setVnfDetails(vnfDetailslist);
114 response = vnfComparisonService.getConfigDeatilsByVnfIdVnfVersion(vnfVersionNames, vnfId);
115 System.out.println(response);
116 assertNotNull(response);
117 assertEquals(value.getConfiginfo(), exampleJson);
118 assertEquals(value.getVnfid(), vnfId);
119 assertEquals(value.getStatus(), "Y");