Epic-231 cbr junit testcase of SDNC-258
[sdnc/oam.git] / configbackuprestore / getBackupVnfDetailService / src / test / java / com / onap / sdnc / vnfconfigcomparsion / service / VnfComparisonServiceTest.java
1 package com.onap.sdnc.vnfconfigcomparsion.service;
2
3
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.mockito.Matchers.anyString;
7
8 import java.util.ArrayList;
9 import java.util.List;
10
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;
20
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;
25
26
27
28 @RunWith(MockitoJUnitRunner.class)
29 public class VnfComparisonServiceTest {
30
31         @InjectMocks
32         VnfComparisonService vnfComparisonService;
33         
34         @Mock
35         VnfComparisonRepository vnfComparisonRepository;
36         
37         @Test
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\"]  }");
42                 String vnfId = "1a";
43                 List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>();
44                 VnfDetails vnfdetails = new VnfDetails();
45                 JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames");
46                 VnfConfigDetailsDB value = new VnfConfigDetailsDB();
47                 value.setVnfid("1a");
48                 value.setConfiginfo(exampleJson);
49                 value.setId(1);
50                 value.setLastupdated("05-22-2018");
51                 value.setStatus("Y");
52                 value.setVnfname("vnf1");
53                 value.setVnfversion("1.0");
54
55                 //Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
56                 response.setVnfDetails(vnfDetailslist);
57                 response = vnfComparisonService.getConfigurationDeatils(vnfVersionNames, vnfId);
58                 assertEquals(value.getConfiginfo(), exampleJson);
59                 
60         }
61         
62         @Test
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\"] }";
68                 String vnfId = "1a";
69                 List<VnfDetails> vnfDetailslist = new ArrayList<VnfDetails>();
70                 VnfDetails vnfdetails = new VnfDetails();
71                 JSONArray vnfIdArray = vnfVersionNames.getJSONArray("versionNames");
72                 VnfConfigDetailsDB value = new VnfConfigDetailsDB();
73                 value.setVnfid("1a");
74                 value.setConfiginfo(exampleJson);
75                 value.setId(1);
76                 value.setLastupdated("05-22-2018");
77                 value.setStatus("Y");
78                 value.setVnfname("vnf1");
79                 value.setVnfversion("1.0");
80
81                 Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
82                 response.setVnfDetails(vnfDetailslist);
83
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");
90         }
91         
92         @Test
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\"] }";
98                 String vnfId = "1a";
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);
105                 value.setId(1);
106                 value.setLastupdated("05-22-2018");
107                 value.setStatus("Y");
108                 value.setVnfname("vnf1");
109                 value.setVnfversion("1.0");
110
111                 Mockito.when(vnfComparisonRepository.getVnfDetails(anyString(), anyString())).thenReturn(value);
112                 response.setVnfDetails(vnfDetailslist);
113
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");
120         }
121
122
123 }