diff options
author | krishnaa96 <krishna.moorthy6@wipro.com> | 2021-04-21 13:06:06 +0530 |
---|---|---|
committer | krishnaa96 <krishna.moorthy6@wipro.com> | 2021-04-22 15:37:44 +0530 |
commit | 60c9a8e05d329d53a7bd7321a52c83a7272f641c (patch) | |
tree | 3b8504bcd802f8f182457da2ca863ac187c92402 /cps-tbdmt-service/src/test | |
parent | 88d908b7031c305bf6f249ec64e7258e9dd14b08 (diff) |
Add support for query api
Issue-ID: CPS-349
Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com>
Change-Id: Ib68b7163e3e457378208e72f3566191f7c36d714
Diffstat (limited to 'cps-tbdmt-service/src/test')
3 files changed, 56 insertions, 15 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 f69d4ad..9742bb1 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 @@ -22,6 +22,7 @@ package org.onap.cps.tbdmt.client; import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -68,18 +69,30 @@ public class CpsRestClientTest { @Rule public ExpectedException exception = ExpectedException.none(); - @Test - public void testFetchNode() throws Exception { - final HttpHeaders responseHeaders = new HttpHeaders(); + private HttpHeaders responseHeaders; + private ResponseEntity<String> response; + + /** + * Setup variables before test. + * + */ + @Before + public void setUp() { + responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.APPLICATION_JSON); - final ResponseEntity<String> response = new ResponseEntity<>("sample response", responseHeaders, + response = new ResponseEntity<>("sample response", responseHeaders, HttpStatus.OK); - Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(), + } + + @Test + public void testFetchNode() throws Exception { + final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes?cpsPath=sample"; + Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri), ArgumentMatchers.any(HttpMethod.class), ArgumentMatchers.any(), ArgumentMatchers.<Class<String>>any())) .thenReturn(response); - assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample")); + assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "get")); final ResponseEntity<String> errorResponse = new ResponseEntity<>("sample response", responseHeaders, HttpStatus.NOT_FOUND); @@ -90,11 +103,22 @@ public class CpsRestClientTest { .thenReturn(errorResponse); exception.expect(CpsClientException.class); exception.expectMessage("Response code from CPS other than 200: 404"); - cpsRestClient.fetchNode("coverage-area-onap", "sample"); + cpsRestClient.fetchNode("coverage-area-onap", "sample", "get"); } @Test + public void testQueryApi() throws Exception { + final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes/query?cpsPath=sample"; + Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri), + ArgumentMatchers.any(HttpMethod.class), + ArgumentMatchers.any(), + ArgumentMatchers.<Class<String>>any())) + .thenReturn(response); + assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "query")); + } + + @Test public void testFetchNodeException() throws Exception { Mockito.when(restTemplate.exchange(ArgumentMatchers.anyString(), ArgumentMatchers.any(HttpMethod.class), @@ -103,6 +127,6 @@ public class CpsRestClientTest { .thenThrow(new RestClientException("Connection refused")); exception.expect(CpsClientException.class); exception.expectMessage("Connection refused"); - cpsRestClient.fetchNode("coverage-area-onap", "sample"); + cpsRestClient.fetchNode("coverage-area-onap", "sample", "get"); } } 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 28a7a49..32dbc27 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 @@ -78,6 +78,8 @@ public class ExecutionBusinessLogicTest { private Template template; + private Template queryTemplate; + /** * Setup variables before test. * @@ -89,7 +91,8 @@ public class ExecutionBusinessLogicTest { request = new ExecutionRequest(input); final String xpathTemplate = "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']" + "/coverage-area[@coverageArea='{{coverageArea}}']"; - template = new Template("getNbr", "ran-network", xpathTemplate); + template = new Template("getNbr", "ran-network", xpathTemplate, "get"); + queryTemplate = new Template("getNbr", "ran-network", xpathTemplate, "query"); } @Test @@ -97,7 +100,7 @@ public class ExecutionBusinessLogicTest { final String resultString = "[{\"key\": \"value\"}]"; Mockito.when(cpsRestClient .fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']" - + "/coverage-area[@coverageArea='Zone 1']")) + + "/coverage-area[@coverageArea='Zone 1']", "get")) .thenReturn(resultString); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template)); @@ -117,7 +120,7 @@ public class ExecutionBusinessLogicTest { final String exceptionMessage = "Response from CPS other than 200: 404"; Mockito.when(cpsRestClient .fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']" - + "/coverage-area[@coverageArea='Zone 1']")) + + "/coverage-area[@coverageArea='Zone 1']", "get")) .thenThrow(new CpsClientException(exceptionMessage)); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template)); @@ -125,7 +128,7 @@ public class ExecutionBusinessLogicTest { exception.expectMessage(exceptionMessage); executionBusinessLogic.executeTemplate("ran-network", "getNbr", request); - final Template template1 = new Template("getNbr", "ran-net", "sample"); + final Template template1 = new Template("getNbr", "ran-net", "sample", "get"); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template1)); exception.expect(ExecuteException.class); @@ -136,7 +139,7 @@ public class ExecutionBusinessLogicTest { @Test public void testExecuteTemplateNoAnchor() { - final Template template = new Template("getNbr", "ran-net", "sample"); + final Template template = new Template("getNbr", "ran-net", "sample", "get"); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template)); exception.expect(ExecuteException.class); @@ -144,4 +147,18 @@ public class ExecutionBusinessLogicTest { executionBusinessLogic.executeTemplate("ran-net", "getNbr", request); } + @Test + public void testExecuteTemplateQueryApi() throws Exception { + final String resultString = "[{\"key\": \"value\"}]"; + Mockito.when(cpsRestClient + .fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']" + + "/coverage-area[@coverageArea='Zone 1']", "query")) + .thenReturn(resultString); + Mockito.when(templateRepository.findById(ArgumentMatchers.any())) + .thenReturn(Optional.of(queryTemplate)); + assertEquals(resultString, + executionBusinessLogic.executeTemplate("ran-network", "getNbr", request)); + + } + } diff --git a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/TemplateBusinessLogicTest.java b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/TemplateBusinessLogicTest.java index 5cf9fc1..aa7e28a 100644 --- a/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/TemplateBusinessLogicTest.java +++ b/cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/TemplateBusinessLogicTest.java @@ -71,13 +71,13 @@ public class TemplateBusinessLogicTest { @Before public void setup() { - template = new Template("getNbr", "ran-network", "sample"); + template = new Template("getNbr", "ran-network", "sample", "get"); final TemplateKey templateKey = new TemplateKey("getNbr", "ran-network"); } @Test public void testCreateTemplate() throws Exception { - final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample"); + final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get"); Mockito.when(templateRepository.save(ArgumentMatchers.any())).thenReturn(template); assertEquals(template, templateBusinessLogic.createTemplate(templateRequest)); } |