diff options
author | Niranjana <niranjana.y60@wipro.com> | 2021-09-14 10:59:23 +0000 |
---|---|---|
committer | Niranjana Y <niranjana.y60@wipro.com> | 2021-09-17 10:50:01 +0000 |
commit | b2e2c6688737230608c3dd8e14e1c09d2b54c86d (patch) | |
tree | 8a5e82f74ed7dfef5e5044f23a6039586f5e38f4 /cps-tbdmt-service/src/test/java | |
parent | 76344df7812bfc4feed27d218743448c35373992 (diff) |
Support delete query and dynamic anchor
Issue-ID: CPS-661
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: I720c348d49c53573ef8897d02d641e53232fc941
Diffstat (limited to 'cps-tbdmt-service/src/test/java')
-rw-r--r-- | cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java | 36 | ||||
-rw-r--r-- | cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java | 33 |
2 files changed, 69 insertions, 0 deletions
diff --git a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java index 4697479..76033c9 100644 --- a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java +++ b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java @@ -164,4 +164,40 @@ public class CpsRestClientTest { assertEquals("sample response", cpsRestClient.addData("coverage-area-onap", "NearRTRIC", "patch", payload)); } + + @Test + public void testAddDataForPostListNodesRequest() throws Exception { + final String uri = "http://localhost:8000/anchors/coverage-area-onap/list-nodes?xpath=NearRTRIC"; + Mockito.when(restTemplate.postForEntity(ArgumentMatchers.eq(uri), ArgumentMatchers.any(), + ArgumentMatchers.<Class<String>>any())).thenReturn(response); + final Map<String, Object> payload = new HashMap<String, Object>(); + payload.put("idNearRTRIC", 11); + assertEquals("sample response", cpsRestClient.addData("coverage-area-onap", "NearRTRIC", + "post-list-node", payload)); + + } + + @Test + public void deleteListNodeData() throws Exception { + final String uri = "http://localhost:8000/anchors/coverage-area-onap/list-nodes?xpath=sample"; + response = new ResponseEntity<String>(HttpStatus.NO_CONTENT); + Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.any(), + ArgumentMatchers.<Class<String>>any())) + .thenReturn(response); + assertEquals("Success", cpsRestClient.deleteData("coverage-area-onap", "sample", "delete-list-node")); + } + + @Test + public void deleteNodeData() throws Exception { + final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes?xpath=sample"; + response = new ResponseEntity<String>(HttpStatus.NO_CONTENT); + Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.any(), + ArgumentMatchers.<Class<String>>any())) + .thenReturn(response); + assertEquals("Success", cpsRestClient.deleteData("coverage-area-onap", "sample", "delete")); + } } diff --git a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java index 60f0050..56c55c0 100644 --- a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java +++ b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java @@ -221,6 +221,39 @@ public class ExecutionBusinessLogicTest { } } + @Test + public void testDeleteDataRequest() { + final Map<String, String> input = new HashMap<>(); + input.put("idNearRTRIC", "11"); + final String transformParam = "GNBDUFunction, NRCellDU, attributes, cellLocalId"; + final Template template = new Template("delete-snssai", "ran-network", + "/NearRTRIC/[@idNearRTRIC='11']/attributes/" + + "pLMNInfoList[@mcc='370' and '@mnc='410']/sNSSAIList[@sNssai='111-1111']", + "delete-list-node", true, null, null); + try { + final String result = "Success"; + Mockito.when(cpsRestClient.deleteData("ran-network", "/NearRTRIC/[@idNearRTRIC='11']/attributes/" + + "pLMNInfoList[@mcc='370' and '@mnc='410']/sNSSAIList[@sNssai='111-1111']", "delete-list-node")) + .thenReturn(result); + Mockito.when(templateRepository.findById(ArgumentMatchers.any())).thenReturn(Optional.of(template)); + assertEquals("Success", + executionBusinessLogic.executeTemplate("ran-network", "delete-snssai", request)); + } catch (final Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testDeleteDataFailRequest() throws Exception { + final Template template = new Template("deleteNbr", "ran-network", "sample", "delete-list-node", true, "", ""); + Mockito.when(cpsRestClient.deleteData("ran-network", "sample", "delete-list-node")) + .thenThrow(new ExecuteException("Response code from CPS other than 200: 401")); + Mockito.when(templateRepository.findById(ArgumentMatchers.any())) + .thenReturn(Optional.of(template)); + exception.expect(ExecuteException.class); + executionBusinessLogic.executeTemplate("ran-net", "deleteNbr", request); + } + /** * Reads a file from classpath. * |