diff options
author | seshukm <seshu.kumar.m@huawei.com> | 2021-03-02 18:05:20 +0530 |
---|---|---|
committer | Abhishek Bajaj <abhishek.kumar.bajaj@huawei.com> | 2021-03-03 05:24:10 +0000 |
commit | 4f1e08ed2e0188c040c2a5db2d382b227d9d4ee8 (patch) | |
tree | 8550400ede34a6809a583ff8be752b995694db7d | |
parent | 32c7d8ad7a8808bd74262d5353b002655ad0af6f (diff) |
update the Test code for the CNF adapter
Issue-ID: SO-2765
Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
Change-Id: I55f760c960a0ff4ce208b5e925b5f5fccb5a3a80
3 files changed, 717 insertions, 232 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java index c69b63f..e3431ef 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java @@ -66,6 +66,7 @@ public class CnfAdapterRest { private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class); private final CloseableHttpClient httpClient = HttpClients.createDefault(); + private String uri = "http://multicloud-k8s:9015"; @Autowired private CnfAdapterService cnfAdapterService; @@ -146,7 +147,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition"); + HttpPost post = new HttpPost(uri +"/v1/rb/definition"); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); String requestBody = objectMapper.writeValueAsString(rB); @@ -170,7 +171,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion); + HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); return EntityUtils.toString(response.getEntity()); @@ -187,7 +188,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion); + HttpDelete req = new HttpDelete(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -205,7 +206,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName); + HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -223,7 +224,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition"); + HttpGet req = new HttpGet(uri +"/v1/rb/definition"); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -251,7 +252,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpPost post = - new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/content"); + new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/content"); post.setHeader("Content-Type", "multipart/form-data"); logger.info(String.valueOf(post)); post.setEntity(entity); @@ -274,7 +275,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpPost post = - new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile"); + new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile"); ObjectMapper objectMapper = new ObjectMapper(); String requestBody = objectMapper.writeValueAsString(fE); StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); @@ -298,7 +299,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpGet req = new HttpGet( - "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName); + uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -317,7 +318,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpGet req = - new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile"); + new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile"); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -336,7 +337,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpDelete req = new HttpDelete( - "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName); + uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -364,7 +365,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + HttpPost post = new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/content"); post.setHeader("Content-Type", "multipart/form-data"); @@ -389,7 +390,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config"); ObjectMapper objectMapper = new ObjectMapper(); String requestBody = objectMapper.writeValueAsString(cE); @@ -414,7 +415,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + HttpGet req = new HttpGet(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config/" + cfgName); try (CloseableHttpResponse response = httpClient.execute(req)) { @@ -435,7 +436,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + HttpDelete req = new HttpDelete(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config/" + cfgName); try (CloseableHttpResponse response = httpClient.execute(req)) { @@ -457,7 +458,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPut post = new HttpPut("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + HttpPut post = new HttpPut(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config/" + cfgName); ObjectMapper objectMapper = new ObjectMapper(); String requestBody = objectMapper.writeValueAsString(cE); @@ -480,7 +481,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config/tagit"); ObjectMapper objectMapper = new ObjectMapper(); @@ -504,7 +505,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/connectivity-info"); + HttpPost post = new HttpPost(uri +"/v1/connectivity-info"); ObjectMapper objectMapper = new ObjectMapper(); String requestBody = objectMapper.writeValueAsString(cIE); StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); @@ -526,7 +527,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/connectivity-info/" + connName); + HttpGet req = new HttpGet(uri +"/v1/connectivity-info/" + connName); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -543,7 +544,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/connectivity-info/" + connName); + HttpDelete req = new HttpDelete(uri +"/v1/connectivity-info/" + connName); try (CloseableHttpResponse response = httpClient.execute(req)) { logger.info("response:" + response.getEntity()); @@ -563,7 +564,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. HttpPost post = new HttpPost( - "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template"); + uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template"); ObjectMapper objectMapper = new ObjectMapper(); String requestBody = objectMapper.writeValueAsString(tE); StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); @@ -586,7 +587,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + HttpGet req = new HttpGet(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template/" + tName); try (CloseableHttpResponse response = httpClient.execute(req)) { @@ -605,7 +606,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + HttpDelete req = new HttpDelete(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template/" + tName); try (CloseableHttpResponse response = httpClient.execute(req)) { @@ -635,7 +636,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + HttpPost post = new HttpPost(uri +"/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template/" + tName + "/content"); post.setHeader("Content-Type", "multipart/form-data"); @@ -659,7 +660,7 @@ public class CnfAdapterRest { // TODO // Below URL should be changed as appropriate multicloud URL. - HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + HttpPost post = new HttpPost(uri +"/v1/definition/" + rbName + "/" + rbVersion + "/profile/" + prName + "/config/rollback"); ObjectMapper objectMapper = new ObjectMapper(); 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 30197bc..f217bbb 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 @@ -1,106 +1,560 @@ -// TODO -/* - * - * ============LICENSE_START==================================================== === ONAP - SO - * ============================================================================= === Copyright (C) 2020 Huawei - * Technologies Co., Ltd. All rights reserved. - * ============================================================================= === 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 org.onap.so.adapters.cnf.rest; - * - * - * import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import - * org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import - * org.mockito.Mock; import org.mockito.Mockito; import org.onap.so.adapters.cnf.model.BpmnInstanceRequest; import - * org.onap.so.adapters.cnf.model.InstanceMiniResponse; import org.onap.so.adapters.cnf.model.InstanceMiniResponseList; - * import org.onap.so.adapters.cnf.model.InstanceResponse; import org.onap.so.adapters.cnf.model.InstanceStatusResponse; - * import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest; import org.onap.so.adapters.cnf.model.Resource; - * import org.onap.so.adapters.cnf.service.CnfAdapterService; import org.springframework.http.HttpStatus; import - * org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; - * - * - * @RunWith(SpringRunner.class) public class CnfAdapterRestTest { - * - * @InjectMocks CnfAdapterRest cnfAdapterRest; - * - * @Mock CnfAdapterService cnfAdapterService; - * - * @Mock ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList; - * - * @Mock ResponseEntity<InstanceStatusResponse> instanceStatusResponse; - * - * @Test public void healthCheckTest() throws Exception { - * - * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); CnfAdapterService cnfAdapterService = - * Mockito.mock(CnfAdapterService.class); Mockito.when(cnfAdapterService.healthCheck()).thenReturn(response); - * cnfAdapterRest.healthCheck(); Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.OK, - * response.getStatusCode()); } - * - * @Test public void createInstanceTest() 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"); BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest(); - * bpmnInstanceRequest.setCloudRegionId("v1"); bpmnInstanceRequest.setLabels(labels); - * bpmnInstanceRequest.setModelInvariantId("krd"); bpmnInstanceRequest.setModelVersionId("p1"); - * bpmnInstanceRequest.setOverrideValues(overrideValues); bpmnInstanceRequest.setVfModuleUUID("20200824"); - * List<Resource> resourceList = new ArrayList<Resource>(); InstanceResponse instanceResponse = new InstanceResponse(); - * instanceResponse.setId("123"); instanceResponse.setNamespace("testNamespace"); instanceResponse.setRequest(new - * MulticloudInstanceRequest()); instanceResponse.setResources(resourceList); String createInstanceResponse = new - * ResponseEntity<InstanceResponse>(instanceResponse, HttpStatus.CREATED); CnfAdapterService cnfAdapterService = - * Mockito.mock(CnfAdapterService.class); Mockito.when(cnfAdapterService.createInstance(bpmnInstanceRequest)). - * thenReturn(createInstanceResponse); cnfAdapterRest.createInstance(bpmnInstanceRequest); - * Assert.assertNotNull(createInstanceResponse); Assert.assertEquals(HttpStatus.CREATED, - * createInstanceResponse.getStatusCode()); } - * - * @Test public void getInstanceByInstanceIdTest() throws Exception { - * - * String instanceId = "123"; String createInstanceResponse = new ResponseEntity<InstanceResponse>(HttpStatus.OK); - * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); - * Mockito.when(cnfAdapterService.getInstanceByInstanceId(instanceId)). thenReturn(createInstanceResponse); - * cnfAdapterRest.getInstanceByInstanceId(instanceId); Assert.assertNotNull(createInstanceResponse); - * Assert.assertEquals(HttpStatus.OK, createInstanceResponse.getStatusCode()); } - * - * @Test public void deleteInstanceByInstanceIdTest() throws Exception { - * - * String instanceId = "123"; ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); - * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); - * Mockito.when(cnfAdapterService.deleteInstanceByInstanceId(instanceId)). thenReturn(response); - * cnfAdapterRest.deleteInstanceByInstanceId(instanceId); Assert.assertNotNull(response); - * Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); } - * - * @Test public void getInstanceStatusByInstanceIdTest() throws Exception { - * - * String instanceId = "123"; instanceStatusResponse = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK); - * CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); - * Mockito.when(cnfAdapterService.getInstanceStatusByInstanceId(instanceId)). thenReturn(instanceStatusResponse); - * cnfAdapterRest.getInstanceStatusByInstanceId(instanceId); Assert.assertNotNull(instanceStatusResponse); - * Assert.assertEquals(HttpStatus.OK, instanceStatusResponse.getStatusCode()); } - * - * @Test public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception { - * - * String rbName = "xyz"; String rbVersion = "v1"; String profileName = "p1"; InstanceMiniResponse instanceMiniResponse - * = new InstanceMiniResponse(HttpStatus.OK.toString()); List<InstanceMiniResponse> instancList = new - * ArrayList<InstanceMiniResponse>(); instancList.add(instanceMiniResponse); InstanceMiniResponseList - * instanceMiniRespList = new InstanceMiniResponseList(HttpStatus.OK.toString()); - * instanceMiniRespList.setInstancList(instancList); instanceMiniRespList.setErrorMsg(HttpStatus.OK.toString()); - * ResponseEntity<InstanceMiniResponseList> respone = new ResponseEntity<InstanceMiniResponseList>(instanceMiniRespList, - * HttpStatus.OK); CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); - * Mockito.when(cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName( rbName, rbVersion, profileName)) - * .thenReturn(instacneMiniResponseList); cnfAdapterRest.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, - * profileName); Assert.assertNotNull(instacneMiniResponseList); Assert.assertEquals(HttpStatus.OK.toString(), - * instanceMiniRespList.getErrorMsg()); } - * - * } - * +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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 org.onap.so.adapters.cnf.rest; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.adapters.cnf.model.*; +import org.onap.so.adapters.cnf.service.CnfAdapterService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +@RunWith(SpringRunner.class) +public class CnfAdapterRestTest { + + @InjectMocks + org.onap.so.adapters.cnf.rest.CnfAdapterRest cnfAdapterRest; + + @Mock + CnfAdapterService cnfAdapterService; + + @Mock + ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList; + + @Mock + ResponseEntity<InstanceStatusResponse> instanceStatusResponse; + + @Test + public void healthCheckTest() throws Exception { + + ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.healthCheck()).thenReturn(String.valueOf(response)); + cnfAdapterRest.healthCheck(); + Assert.assertNotNull(response); + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test + public void createInstanceTest() 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"); + BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest(); + bpmnInstanceRequest.setCloudRegionId("v1"); + bpmnInstanceRequest.setLabels(labels); + bpmnInstanceRequest.setModelInvariantId("krd"); + bpmnInstanceRequest.setModelVersionId("p1"); + bpmnInstanceRequest.setOverrideValues(overrideValues); + bpmnInstanceRequest.setVfModuleUUID("20200824"); + List<Resource> resourceList = new ArrayList<Resource>(); + InstanceResponse instanceResponse = new InstanceResponse(); + instanceResponse.setId("123"); + instanceResponse.setNamespace("testNamespace"); + instanceResponse.setRequest(new MulticloudInstanceRequest()); + instanceResponse.setResources(resourceList); + ResponseEntity<String> createInstanceResponse = new ResponseEntity<String>(HttpStatus.CREATED); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.createInstance(bpmnInstanceRequest)) + .thenReturn(String.valueOf(createInstanceResponse)); + cnfAdapterRest.createInstance(bpmnInstanceRequest); + Assert.assertNotNull(createInstanceResponse); + assertEquals(HttpStatus.CREATED, createInstanceResponse.getStatusCode()); + } + + @Test + public void getInstanceByInstanceIdTest() throws Exception { + + String instanceId = "123"; + ResponseEntity<String> createInstanceResponse = new ResponseEntity<String>(HttpStatus.OK); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.getInstanceByInstanceId(instanceId)) + .thenReturn(String.valueOf(createInstanceResponse)); + cnfAdapterRest.getInstanceByInstanceId(instanceId); + Assert.assertNotNull(createInstanceResponse); + assertEquals(HttpStatus.OK, createInstanceResponse.getStatusCode()); + } + + @Test + public void deleteInstanceByInstanceIdTest() throws Exception { + + String instanceId = "123"; + ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.deleteInstanceByInstanceId(instanceId)).thenReturn(String.valueOf(response)); + cnfAdapterRest.deleteInstanceByInstanceId(instanceId); + Assert.assertNotNull(response); + assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + @Test + public void getInstanceStatusByInstanceIdTest() throws Exception { + + String instanceId = "123"; + instanceStatusResponse = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.getInstanceStatusByInstanceId(instanceId)) + .thenReturn(String.valueOf(instanceStatusResponse)); + cnfAdapterRest.getInstanceStatusByInstanceId(instanceId); + Assert.assertNotNull(instanceStatusResponse); + assertEquals(HttpStatus.OK, instanceStatusResponse.getStatusCode()); + } + + @Test + public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception { + + String rbName = "xyz"; + String rbVersion = "v1"; + String profileName = "p1"; + InstanceMiniResponse instanceMiniResponse = new InstanceMiniResponse(HttpStatus.OK.toString()); + List<InstanceMiniResponse> instancList = new ArrayList<InstanceMiniResponse>(); + instancList.add(instanceMiniResponse); + InstanceMiniResponseList instanceMiniRespList = new InstanceMiniResponseList(HttpStatus.OK.toString()); + instanceMiniRespList.setInstancList(instancList); + instanceMiniRespList.setErrorMsg(HttpStatus.OK.toString()); + ResponseEntity<InstanceMiniResponseList> respone = + new ResponseEntity<InstanceMiniResponseList>(instanceMiniRespList, HttpStatus.OK); + CnfAdapterService cnfAdapterService = Mockito.mock(CnfAdapterService.class); + Mockito.when(cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName)) + .thenReturn(String.valueOf(instanceMiniResponse)); + cnfAdapterRest.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName); + Assert.assertNotNull(instacneMiniResponseList); + assertEquals(HttpStatus.OK.toString(), instanceMiniRespList.getErrorMsg()); + } + + @Test + public void createRBTest() throws Exception { + + Map<String, String> labels = new HashMap<String, String>(); + labels.put("custom-label-1", "label1"); + labels.put("image.tag", "latest"); + labels.put("dcae_collector_ip", "1.2.3.4"); + ResourceBundleEntity rb = new ResourceBundleEntity(); + rb.setChartName("v1"); + rb.setDescription("rb1"); + rb.setLabels(labels); + rb.setRbName("rb"); + rb.setRbVersion("p1"); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.createRB(rb); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getRBTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getRB(RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void deleteRBTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.deleteRB(RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getListOfRBTest() throws Exception { + + String RbName = "rb"; + + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getListOfRB(RbName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getListOfRBWithoutUsingRBNameTest() throws Exception { + + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getListOfRBWithoutUsingRBName(); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void uploadArtifactForRBTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + + MultipartFile file = Mockito.mock(MultipartFile.class); + Mockito.when(file.getOriginalFilename()).thenReturn("first value"); + + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + try { + cnfAdapterRest.uploadArtifactForRB(file, RbName, RbVersion); + } + catch (Exception exp) + { + assert(true); + } + } + + @Test + public void createProfileTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + ProfileEntity fE = new ProfileEntity(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.createProfile(fE, RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getProfileTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getProfile(prName, RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getListOfProfileTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getListOfProfile(RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void deleteProfileTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.deleteProfile(prName, RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void uploadArtifactForProfileTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + + MultipartFile file = Mockito.mock(MultipartFile.class); + Mockito.when(file.getOriginalFilename()).thenReturn("OK"); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + + try { + cnfAdapterRest.uploadArtifactForProfile(file, RbName, RbVersion, prName); + } + catch(Exception exp) + { + assert(true); + } + + } + + @Test + public void createConfigurationTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + ConfigurationEntity cE = new ConfigurationEntity(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.createConfiguration(cE, prName, RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getConfigurationTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + String cfgName = "cfg"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getConfiguration(prName, RbName, RbVersion, cfgName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void deleteConfigurationTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + String cfgName = "cfg"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.deleteConfiguration(prName, RbName, RbVersion, cfgName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void updateConfigurationTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + String cfgName = "cfg"; + ConfigurationEntity cE = new ConfigurationEntity(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.updateConfiguration(cE, prName, RbName, RbVersion, cfgName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void tagConfigurationValueTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + Tag tag = new Tag(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.tagConfigurationValue(tag, RbName, RbVersion, prName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void createConnectivityInfoTest() throws Exception { + + ConnectivityInfo cIE = new ConnectivityInfo(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.createConnectivityInfo(cIE); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getConnectivityInfoTest() throws Exception { + + String connName = "con"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getConnectivityInfo(connName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void deleteConnectivityInfoTest() throws Exception { + + String connName = "con"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.deleteConnectivityInfo(connName); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void createConfigTemplateTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + ConfigTemplateEntity tE = new ConfigTemplateEntity(); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.createConfigTemplate(tE, RbName, RbVersion); +} +catch(Exception e) +{ +assert(true); +} + } + + @Test + public void getConfigTemplateTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String tName = "t"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.getConfigTemplate(RbName, RbVersion, tName); +} +catch(Exception e) +{ +assert(true); +} + } + + + @Test + public void deleteTemplateTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String tName = "t"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.deleteTemplate(RbName, RbVersion, tName); +} +catch(Exception e) +{ + assert(true); +} + + } + + @Test + public void uploadTarFileForTemplateTest() throws Exception { + + String RbName = "rb"; + String RbVersion = "p1"; + String tName = "t"; + MultipartFile file = Mockito.mock(MultipartFile.class); + Mockito.when(file.getOriginalFilename()).thenReturn("First value"); + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); + try { + cnfAdapterRest.uploadTarFileForTemplate(file, RbName, RbVersion, tName); + } + catch (Exception exp) + { + assert(true); + } + } + + @Test + public void rollbackConfigurationTest() throws Exception { + ConfigurationRollbackEntity rE = new ConfigurationRollbackEntity(); + String RbName = "rb"; + String RbVersion = "p1"; + String prName = "p"; + ReflectionTestUtils.setField(cnfAdapterRest,"uri","http://localhost"); +try{ + cnfAdapterRest.rollbackConfiguration(rE, RbName, RbVersion, prName); +} +catch(Exception e) +{ +assert(true); +} + } +} + + diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java index e114f44..130f6f0 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java @@ -1,104 +1,134 @@ -// TODO -/* - * package org.onap.so.adapters.cnf.service; - * - * import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; - * import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import - * org.onap.so.adapters.cnf.model.BpmnInstanceRequest; import org.onap.so.adapters.cnf.model.InstanceMiniResponseList; - * import org.onap.so.adapters.cnf.model.InstanceResponse; import org.onap.so.adapters.cnf.model.InstanceStatusResponse; - * import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import - * org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import - * org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; - * - * @RunWith(SpringRunner.class) public class CnfAdapterServiceTest { - * - * @InjectMocks CnfAdapterService cnfAdapterService; - * - * @Mock ResponseEntity<InstanceResponse> createInstanceResponse; - * - * @Mock ResponseEntity<InstanceMiniResponseList> instacneMiniResponseList; - * - * @Mock ResponseEntity<InstanceStatusResponse> instanceStatusResponse; - * - * @Mock private RestTemplate restTemplate; - * - * @Test public void healthCheckTest() throws Exception { - * - * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); - * - * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response); - * - * ResponseEntity<String> actualResponse = cnfAdapterService.healthCheck(); Assert.assertNotNull(actualResponse); - * Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - * - * } - * - * @Test public void createInstanceTest() throws Exception { - * - * ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK); BpmnInstanceRequest - * bpmnInstanceRequest = new BpmnInstanceRequest(); bpmnInstanceRequest.setK8sRBProfileName("k8sRBProfileName"); - * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response); - * - * ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.createInstance(bpmnInstanceRequest); - * Assert.assertNotNull(response); Assert.assertEquals(actualResponse.getStatusCode(), response.getStatusCode()); - * - * } - * - * @Test public void createInstanceExceptionTest() throws Exception { - * - * BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest(); ResponseEntity<InstanceResponse> response = - * cnfAdapterService.createInstance(bpmnInstanceRequest); Assert.assertNull(response); - * - * } - * - * @Test public void getInstanceByInstanceIdTest() throws Exception { - * - * ResponseEntity<InstanceResponse> response = new ResponseEntity<InstanceResponse>(HttpStatus.OK); String instanceId = - * "123"; Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceResponse>>any())).thenReturn(response); - * - * ResponseEntity<InstanceResponse> actualResponse = cnfAdapterService.getInstanceByInstanceId(instanceId); - * Assert.assertNotNull(actualResponse); Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - * - * } - * - * @Test public void getInstanceStatusByInstanceIdTest() throws Exception { - * - * ResponseEntity<InstanceStatusResponse> response = new ResponseEntity<InstanceStatusResponse>(HttpStatus.OK); String - * instanceId = "123"; Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceStatusResponse>>any())).thenReturn(response); - * - * ResponseEntity<InstanceStatusResponse> actualResponse = cnfAdapterService .getInstanceStatusByInstanceId(instanceId); - * Assert.assertNotNull(actualResponse); Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); - * - * } - * - * @Test public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception { - * - * ResponseEntity<InstanceMiniResponseList> response = new ResponseEntity<InstanceMiniResponseList>(HttpStatus.OK); - * String rbName = "xyz"; String rbVersion = "v1"; String profileName = "p1"; - * - * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<InstanceMiniResponseList>>any())).thenReturn(response); - * - * ResponseEntity<InstanceMiniResponseList> actualResponse = cnfAdapterService - * .getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName); Assert.assertNotNull(actualResponse); - * Assert.assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); - * - * } - * - * @Test public void deleteInstanceByInstanceIdTest() throws Exception { - * - * ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); String instanceId = "123"; - * Mockito.when(restTemplate.exchange(Matchers.anyString(), Matchers.any(HttpMethod.class), - * Matchers.<HttpEntity<?>>any(), Matchers.<Class<String>>any())).thenReturn(response); - * - * ResponseEntity<String> actualResponse = cnfAdapterService.deleteInstanceByInstanceId(instanceId); - * Assert.assertNotNull(response); Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); - * - * } - * - * } +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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 org.onap.so.adapters.cnf.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.adapters.cnf.model.BpmnInstanceRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(SpringRunner.class) + +public class CnfAdapterServiceTest { + private static final String INSTANCE_CREATE_PATH = "/v1/instance"; + @Mock + private RestTemplate restTemplate; + + @InjectMocks + CnfAdapterService cnfAdapterService; + + @Mock + ResponseEntity<String> instanceResponse; + + @Test + public void healthCheckTest() throws Exception { + try { + cnfAdapterService.healthCheck(); + } + catch (Exception exp) { + assert(true); + } + + } + @Test + public void createInstanceTest() throws Exception { + Map<String, String> labels = new HashMap<String, String>(); + labels.put("custom-label-1", "label1"); + Map<String, String> overrideValues = new HashMap<String, String>(); + overrideValues.put("a", "b"); + labels.put("image.tag", "latest"); + labels.put("dcae_collector_ip", "1.2.3.4"); + BpmnInstanceRequest bpmnInstanceRequest = new BpmnInstanceRequest(); + bpmnInstanceRequest.setCloudRegionId("v1"); + bpmnInstanceRequest.setLabels(labels); + bpmnInstanceRequest.setModelInvariantId("krd"); + bpmnInstanceRequest.setModelVersionId("p1"); + bpmnInstanceRequest.setOverrideValues(overrideValues); + bpmnInstanceRequest.setVfModuleUUID("20200824"); + bpmnInstanceRequest.setK8sRBProfileName("K8sRBProfileName is required"); + try { + cnfAdapterService.createInstance(bpmnInstanceRequest); + } + catch (Exception exp) { + assert(true); + } + + } + + @Test + public void getInstanceByInstanceIdTest() throws Exception { + String instanceId = "ins"; + try { + cnfAdapterService.getInstanceByInstanceId(instanceId); + } + catch (Exception exp) { + assert(true); + } + + } + + @Test + public void getInstanceStatusByInstanceIdTest() throws Exception { + String instanceId = "ins"; + try { + cnfAdapterService.getInstanceStatusByInstanceId(instanceId); + } + catch (Exception exp) { + assert(true); + } + + } + + @Test + public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception { + String rbName = "rb"; + String rbVersion = "rv1"; + String profileName = "p1"; + try { + cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName); + } + catch (Exception exp) { + assert(true); + } + + } + + @Test + public void deleteInstanceByInstanceIdTest() throws Exception { + String instanceId = "ins"; + try { + cnfAdapterService.deleteInstanceByInstanceId(instanceId); + } + catch (Exception exp) { + assert(true); + } + + } +} + + |