diff options
author | DushyantSinghThakur <dt00503496@techmahindra.com> | 2018-09-06 12:46:04 +0530 |
---|---|---|
committer | Dan Timoney <dt5972@att.com> | 2018-09-12 13:10:46 +0000 |
commit | 43d4b00848ebd0567b020fe219f07d4f7049ff0b (patch) | |
tree | f5c09d0006348c82a94693605349e79db4889b71 /configbackuprestore/vnfconfigbackupservice/src/test/java | |
parent | 4e2db0d6e56bc19425e6afa3efc7011820942e9e (diff) |
Epic-231:versioning, and backup the configuration
Merging the sdnc jira stories- 255,256
Change-Id: Iacb9274dae93f534f1331c4eb7d0669896d379d4
Issue-ID: SDNC-256
Signed-off-by: DushyantSinghThakur <dt00503496@techmahindra.com>
Former-commit-id: 94d8b3d82b82dedfd5949da2e5d1ed348ab066e2
Diffstat (limited to 'configbackuprestore/vnfconfigbackupservice/src/test/java')
5 files changed, 398 insertions, 0 deletions
diff --git a/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDBTest.java b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDBTest.java new file mode 100644 index 00000000..38973235 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDBTest.java @@ -0,0 +1,62 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.model; + +import static org.junit.Assert.assertEquals; + +import java.sql.Timestamp; + +import org.junit.Test; + +import com.onap.sdnc.vnfbackupservice.model.VnfConfigDetailsDB; + +public class VnfConfigDetailsDBTest { + + @Test + public void configDetailsDbTest() { + + long millis = System.currentTimeMillis(); + Timestamp date = new java.sql.Timestamp(millis); + String configinfo = "configifo"; + Timestamp creationDate = date; + Timestamp lastupdated = date; + int status = 1; + String vnfid = "vnfId"; + String vnfname = "vnfname"; + String vnfversion = "Version-1"; + + VnfConfigDetailsDB vnfConfigDetailsDB = new VnfConfigDetailsDB(); + vnfConfigDetailsDB.setVnfid(vnfid); + vnfConfigDetailsDB.setConfiginfo(configinfo); + vnfConfigDetailsDB.setCreationdate(creationDate); + vnfConfigDetailsDB.setLastupdated(lastupdated); + vnfConfigDetailsDB.setStatus(status); + vnfConfigDetailsDB.setVnfname(vnfname); + vnfConfigDetailsDB.setVnfversion(vnfversion); + + assertEquals(vnfid, vnfConfigDetailsDB.getVnfid()); + assertEquals(configinfo, vnfConfigDetailsDB.getConfiginfo()); + assertEquals(creationDate, vnfConfigDetailsDB.getCreationdate()); + assertEquals(lastupdated, vnfConfigDetailsDB.getLastupdated()); + assertEquals(status, vnfConfigDetailsDB.getStatus()); + assertEquals(vnfname, vnfConfigDetailsDB.getVnfname()); + assertEquals(vnfversion, vnfConfigDetailsDB.getVnfversion()); + } +} diff --git a/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStampTest.java b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStampTest.java new file mode 100644 index 00000000..ee6d5326 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStampTest.java @@ -0,0 +1,39 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.model; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class VnfConfigSchedulerTimeStampTest { + + @Test + public void vnfConfSchedulerTimeTest() { + String time="12:00"; + int id=1; + + VnfConfigSchedulerTimeStamp vcst= new VnfConfigSchedulerTimeStamp(); + vcst.setBackuptime(time); + vcst.setId(id); + assertEquals(time, vcst.getBackuptime()); + assertEquals(id, vcst.getId()); + } +} diff --git a/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupSchedulerTest.java b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupSchedulerTest.java new file mode 100644 index 00000000..9308eeb8 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupSchedulerTest.java @@ -0,0 +1,85 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.scheduler; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import com.onap.sdnc.vnfbackupservice.model.VnfDisplayParams; +import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse; +import com.onap.sdnc.vnfbackupservice.scheduler.VnfConfigBackupScheduler; +import com.onap.sdnc.vnfbackupservice.service.VnfbackupServiceImpl; + +public class VnfConfigBackupSchedulerTest { + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Mock + VnfbackupServiceImpl vnfbackupServiceImpl; + + @InjectMocks + VnfConfigBackupScheduler vnfconfigBackScheduler; + + @Test + public void initiateBackupServiceTest() { + + String backuptime="timeee"; + String vnfId = "vnfid"; + String vnfName = "vnfname"; + VnfDisplayParams vnfDisplayParams = new VnfDisplayParams(); + vnfDisplayParams.setVnfId(vnfId); + vnfDisplayParams.setVnfName(vnfName); + + VnfServiceResponse vnfServiceResponse = new VnfServiceResponse(); + + List<VnfDisplayParams> vnfdisplaylist = new ArrayList<VnfDisplayParams>(); + vnfdisplaylist.add(vnfDisplayParams); + vnfServiceResponse.setVnfDisplayList(vnfdisplaylist); + + when(vnfbackupServiceImpl.getAllVnfDetails()).thenReturn(vnfServiceResponse); + when(vnfconfigBackScheduler.initiateBackupService()).thenReturn(backuptime); + + vnfconfigBackScheduler.initiateBackupService(); + } + + @Test + public void invokebackupTest() { + + String vnfId="vnfid"; + VnfConfigBackupScheduler vnfConBackSch= mock(VnfConfigBackupScheduler.class); + when(vnfConBackSch.invokeDetails(vnfId)).thenReturn(vnfId); + assertEquals(vnfId, vnfConBackSch.invokeDetails(vnfId)); + vnfConBackSch.invokeDetails(vnfId); + } + +} diff --git a/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClientTest.java b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClientTest.java new file mode 100644 index 00000000..29b1c0f0 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClientTest.java @@ -0,0 +1,62 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.scheduler; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Test; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import mockit.Mock; +import mockit.MockUp; + + +public class VnfRestClientTest { + + String url = "/restconf/config/VNF-API:vnfs"; + String userName = "abc"; + String password = "abc"; + + @Test + public void restClientTest() { + + new MockUp<RestTemplate>() { + @SuppressWarnings("unchecked") + @Mock + public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, + Class<T> responseType, Object... uriVariables) throws RestClientException { + ResponseEntity<String> str = new ResponseEntity<String>(HttpStatus.ACCEPTED); + return (ResponseEntity<T>) str; + } + }; + VnfRestClient vnfRestClientmock = mock(VnfRestClient.class); + when(vnfRestClientmock.vnfRestClient(url, userName, password)).thenReturn("successfully mocked"); + + VnfRestClient vnfRestClient =new VnfRestClient(); + vnfRestClient.vnfRestClient(url, userName, password); + + } +} diff --git a/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImplTest.java b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImplTest.java new file mode 100644 index 00000000..3428bce9 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/test/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImplTest.java @@ -0,0 +1,150 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import com.onap.sdnc.vnfbackupservice.dao.VnfBackupServiceRepo; +import com.onap.sdnc.vnfbackupservice.model.VnfConfigDetailsDB; +import com.onap.sdnc.vnfbackupservice.scheduler.VnfRestClient; +import com.onap.sdnc.vnfbackupservice.service.VnfbackupServiceImpl; + +public class VnfbackupServiceImplTest { + + @Mock + VnfBackupServiceRepo vrepo; + + @Mock + private RestTemplate rTemplate; + + @Mock + private VnfRestClient vnfclient; + + @InjectMocks + VnfbackupServiceImpl vnfserviceimpl; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + String json = "{\r\n" + " \"vnfs\": {\r\n" + " \"vnf-list\": [\r\n" + " {\r\n" + + " \"vnf-id\": \"f24ae4f1-ed6b-4f8b-9ad6-4110a6fe26e7\",\r\n" + + " \"service-data\": {\r\n" + " \"vnf-request-information\": {\r\n" + + " \"vnf-name\": \"vDNS-Techm_vIMS_vnf_1\"\r\n" + " },\r\n" + + " \"service-status\": { \r\n" + " \"response-code\": \"200\"\r\n" + + " }},\r\n" + " \"service-status\": { \r\n" + + " \"response-code\": \"200\"\r\n" + " }\r\n" + " }\r\n" + " \r\n" + + " ]\r\n" + " }\r\n" + " }"; + + String url = "http://localhost:8023/test/api/foos"; + String vnfId="vnfid"; + String userName = "abc"; + String password = "abc"; + String configfile="config"; + String vnfversion = "Version-1"; + String jsonInput="jsoninput"; + String vnfName = "vnfname"; + + long millis = System.currentTimeMillis(); + Timestamp date = new java.sql.Timestamp(millis); + String configinfo =json; + Timestamp creationDate = date; + Timestamp lastupdated = date; + int status = 1; + String vnfname = "vnfname"; + + @Test + public void parseConfigTest() { + VnfbackupServiceImpl vnfbackupServiceImpl = new VnfbackupServiceImpl(); + vnfbackupServiceImpl.parseVnfConfigDetails(json); + assertTrue(true); + } + + @Test() + public void backupVnfconfigTest() + { + HttpHeaders headers = new HttpHeaders(); + HttpHeaders headers1= new HttpHeaders(); + + headers1.setAccept(Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON })); + headers1.setContentType(MediaType.APPLICATION_JSON); + String base64Username = userName + ":" + password; + byte[] message = base64Username.getBytes(); + headers1.set("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString(message)); + + when(vnfclient.generateHeaders(headers, userName, password)).thenReturn(headers1); + + ResponseEntity<String> entity = new ResponseEntity<String>(HttpStatus.OK); + + when(rTemplate.exchange(url, HttpMethod.GET, entity, String.class)).thenReturn(entity) ; + + when(vnfclient.vnfRestClient(url, userName, password)).thenReturn(json); + + VnfConfigDetailsDB vnfConfigDetailsDB = new VnfConfigDetailsDB(); + vnfConfigDetailsDB.setVnfid(vnfId); + vnfConfigDetailsDB.setConfiginfo(configinfo); + vnfConfigDetailsDB.setCreationdate(date); + vnfConfigDetailsDB.setLastupdated(date); + vnfConfigDetailsDB.setStatus(status); + vnfConfigDetailsDB.setVnfname(vnfname); + vnfConfigDetailsDB.setVnfversion(vnfversion); + + when(vrepo.getVnfDetail(vnfId)).thenReturn(vnfConfigDetailsDB); + + List<VnfConfigDetailsDB> listvnfconfdb= new ArrayList<VnfConfigDetailsDB>(); + + when(vrepo.getVnfDetails(vnfId)).thenReturn(listvnfconfdb); + + doNothing().when(vrepo).saveVnfDetails(configinfo, creationDate, lastupdated, status, vnfId, vnfname, vnfversion); + + vnfserviceimpl.backupVnfconfig(vnfId); + + assertEquals("success", vnfserviceimpl.backupVnfconfig(vnfId)); + } + + @Test + public void updatedBackuptimeTest() { + String sdtime="12:00"; + when(vrepo.getvnfschedulertime()).thenReturn(sdtime); + vnfserviceimpl.updatedBackuptime(); + } + +} |