diff options
author | 2022-03-07 16:58:57 +0530 | |
---|---|---|
committer | 2022-03-07 17:01:06 +0530 | |
commit | 20e0886d5fbec91e472e21ae9ead6dfb10a1b5b1 (patch) | |
tree | 19661acac1d33271ada4d43dcac2c307ba570885 | |
parent | 41df59d03938aca3f24ed5210d572b5017c3b98b (diff) |
Add Testcases to get Coverage
Issue-ID: SO-3845
Signed-off-by: Mukesh Paliwal <mukesh.paliwal1@huawei.com>
Change-Id: I00ca6b27f56d2eb7663f9efc6983ae40604c98a4
-rw-r--r-- | so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java index e188a64..517aa89 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java @@ -27,6 +27,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.onap.so.adapters.cnf.MulticloudConfiguration; +import org.onap.so.adapters.cnf.client.SoCallbackClient; import org.onap.so.adapters.cnf.model.BpmnInstanceRequest; import org.onap.so.adapters.cnf.model.CheckInstanceRequest; import org.onap.so.adapters.cnf.model.ConfigTemplateEntity; @@ -42,8 +43,16 @@ import org.onap.so.adapters.cnf.model.ProfileEntity; import org.onap.so.adapters.cnf.model.Resource; import org.onap.so.adapters.cnf.model.ResourceBundleEntity; import org.onap.so.adapters.cnf.model.Tag; +import org.onap.so.adapters.cnf.model.aai.AaiCallbackResponse; import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse; +import org.onap.so.adapters.cnf.model.instantiation.AaiRequest; +import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse; +import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest; import org.onap.so.adapters.cnf.service.CnfAdapterService; +import org.onap.so.adapters.cnf.service.aai.AaiService; +import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService; +import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService; +import org.onap.so.adapters.cnf.service.upgrade.InstanceUpgradeService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; @@ -69,6 +78,18 @@ public class CnfAdapterRestTest { CnfAdapterService cnfAdapterService; @Mock + InstanceUpgradeService instanceUpgradeService; + + @Mock + HealthCheckService healthCheckService; + + @Mock + private SoCallbackClient callbackClient; + + @Mock + SimpleStatusCheckService simpleStatusCheckService; + + @Mock private MulticloudConfiguration multicloudConfiguration; @Mock @@ -598,4 +619,94 @@ public class CnfAdapterRestTest { assert(true); } } + + @Test + public void upgradeTest() throws Exception { + + Map<String, String> labels = new HashMap<String, String>(); + labels.put("custom-label-1", "label1"); + Map<String, String> overrideValues = new HashMap<String, String>(); + labels.put("image.tag", "latest"); + labels.put("dcae_collector_ip", "1.2.3.4"); + InstanceUpgradeRequest instanceUpgradeRequest = new InstanceUpgradeRequest(); + instanceUpgradeRequest.setCloudRegionId("v1"); + instanceUpgradeRequest.setK8sRBInstanceStatusCheck(true); + instanceUpgradeRequest.setK8sRBProfileName("test"); + instanceUpgradeRequest.setLabels(labels); + instanceUpgradeRequest.setModelCustomizationId("12345"); + instanceUpgradeRequest.setModelInvariantId("krd"); + instanceUpgradeRequest.setOverrideValues(overrideValues); + instanceUpgradeRequest.setVfModuleUUID("20200824"); + + ResponseEntity<String> upgradeResponse = new ResponseEntity<String>(HttpStatus.OK); + InstanceUpgradeService instanceUpgradeService = Mockito.mock(InstanceUpgradeService.class); + Mockito.when(instanceUpgradeService.upgradeInstance("123", instanceUpgradeRequest)) + .thenReturn(String.valueOf(upgradeResponse)); + cnfAdapterRest.upgrade("123", instanceUpgradeRequest); + Assert.assertNotNull(upgradeResponse); + assertEquals(HttpStatus.OK, upgradeResponse.getStatusCode()); + } + + @Test + public void healthCheckTest() throws Exception { + HealthCheckResponse response = new HealthCheckResponse(); + DeferredResult<HealthCheckResponse> deferredResponse = new DeferredResult<>(); + deferredResponse.setResult(response); + HealthCheckService healthCheckService = Mockito.mock(HealthCheckService.class); + CheckInstanceRequest healthCheckRequest = Mockito.mock(CheckInstanceRequest.class); + Mockito.when(healthCheckService.healthCheck(healthCheckRequest)).thenReturn(response); + + cnfAdapterRest.healthCheck(healthCheckRequest); + + Assert.assertNotNull(response); + } + + @Test + public void aaiUpdateTest() throws Exception { + AaiCallbackResponse response = new AaiCallbackResponse(); + DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>(); + deferredResponse.setResult(response); + + AaiRequest aaiRequest = new AaiRequest(); + aaiRequest.setCallbackUrl("asdf"); + aaiRequest.setVfModuleId("20200824"); + AaiService aaiService = Mockito.mock(AaiService.class); + SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class); + + cnfAdapterRest.aaiUpdate(aaiRequest); + + Assert.assertNotNull(response); + } + + @Test + public void aaiDeleteTest() throws Exception { + AaiCallbackResponse response = new AaiCallbackResponse(); + DeferredResult<AaiCallbackResponse> deferredResponse = new DeferredResult<>(); + deferredResponse.setResult(response); + + AaiRequest aaiRequest = new AaiRequest(); + aaiRequest.setCallbackUrl("asdfds"); + aaiRequest.setVfModuleId("20200824"); + AaiService aaiService = Mockito.mock(AaiService.class); + SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class); + + cnfAdapterRest.aaiDelete(aaiRequest); + + Assert.assertNotNull(response); + } + + @Test + public void statusCheckTest() throws Exception { + StatusCheckResponse response = new StatusCheckResponse(); + DeferredResult<StatusCheckResponse> deferredResponse = new DeferredResult<>(); + deferredResponse.setResult(response); + + CheckInstanceRequest statusCheckRequest = Mockito.mock(CheckInstanceRequest.class); + SimpleStatusCheckService simpleStatusCheckService = Mockito.mock(SimpleStatusCheckService.class); + SoCallbackClient callbackClient = Mockito.mock(SoCallbackClient.class); + Mockito.when(simpleStatusCheckService.statusCheck(statusCheckRequest)).thenReturn(response); + cnfAdapterRest.statusCheck(statusCheckRequest); + + Assert.assertNotNull(response); + } } |