diff options
author | Niranjana <niranjana.y60@wipro.com> | 2021-07-23 05:27:44 +0000 |
---|---|---|
committer | Niranjana Y <niranjana.y60@wipro.com> | 2021-07-30 11:33:18 +0000 |
commit | 3e5957464b6b4fa18bcae18bcfdce5fc9bace787 (patch) | |
tree | 398c1115de5f66b60d12d98f4106245ab7f64c9b | |
parent | e1216505db39f033c8460ca835eb352e27737b9f (diff) |
Support for Multiple xpath queries in single api query
Issue-ID: CPS-510
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: I79c41d8028355a205d6d1e7808f64447dd94a28b
16 files changed, 420 insertions, 36 deletions
diff --git a/cps-tbdmt-rest/src/main/java/org/onap/cps/tbdmt/rest/TemplateController.java b/cps-tbdmt-rest/src/main/java/org/onap/cps/tbdmt/rest/TemplateController.java index 15efdc5..a17130f 100644 --- a/cps-tbdmt-rest/src/main/java/org/onap/cps/tbdmt/rest/TemplateController.java +++ b/cps-tbdmt-rest/src/main/java/org/onap/cps/tbdmt/rest/TemplateController.java @@ -64,29 +64,26 @@ public class TemplateController { } /** - * Get Template by model and templateId. + * Get Template by templateId. * * @param templateId Id to find the template - * @param model schema set to find the template * @return template */ - @GetMapping(path = "/templates/{model}/{templateId}") - public ResponseEntity<Template> getTemplate(@PathVariable final String templateId, - @PathVariable final String model) { + @GetMapping(path = "/templates/{templateId}") + public ResponseEntity<Template> getTemplate(@PathVariable final String templateId) { return new ResponseEntity<>( - templateBusinessLogic.getTemplate(new TemplateKey(templateId, model)), + templateBusinessLogic.getTemplate(new TemplateKey(templateId)), HttpStatus.OK); } /** - * Delete Template by model and templateId. + * Delete Template by templateId. * * @param templateId Id to find the template - * @param model schema set to find the template */ - @DeleteMapping(path = "/templates/{model}/{templateId}") - public void deleteTemplate(@PathVariable final String templateId, @PathVariable final String model) { - templateBusinessLogic.deleteTemplate(new TemplateKey(templateId, model)); + @DeleteMapping(path = "/templates/{templateId}") + public void deleteTemplate(@PathVariable final String templateId) { + templateBusinessLogic.deleteTemplate(new TemplateKey(templateId)); } } diff --git a/cps-tbdmt-rest/src/test/java/org/onap/cps/tbdmt/rest/TemplateControllerTest.java b/cps-tbdmt-rest/src/test/java/org/onap/cps/tbdmt/rest/TemplateControllerTest.java index bb8c872..f68c724 100644 --- a/cps-tbdmt-rest/src/test/java/org/onap/cps/tbdmt/rest/TemplateControllerTest.java +++ b/cps-tbdmt-rest/src/test/java/org/onap/cps/tbdmt/rest/TemplateControllerTest.java @@ -65,12 +65,13 @@ public class TemplateControllerTest { @Before public void setup() { objectMapper = new ObjectMapper(); - template = new Template("getNbr", "ran-network", "sample", "get", true); + template = new Template("getNbr", "ran-network", "sample", "get", true, "sample", "getRIC"); } @Test public void testCreateTemplate() throws Exception { - final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", true); + final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", + true, "sample", "getRIC"); final String templateJson = objectMapper.writeValueAsString(templateRequest); Mockito.when(templateBusinessLogic.createTemplate(ArgumentMatchers.any())) .thenReturn(template); @@ -116,7 +117,7 @@ public class TemplateControllerTest { final String templateJson = objectMapper.writeValueAsString(template); Mockito.when(templateBusinessLogic.getTemplate(ArgumentMatchers.any())) .thenReturn(template); - mockMvc.perform(get("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(get("/templates/getNbr").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().json(templateJson)); } @@ -125,20 +126,20 @@ public class TemplateControllerTest { public void testGetTemplateNotFound() throws Exception { Mockito.when(templateBusinessLogic.getTemplate(ArgumentMatchers.any())) .thenThrow(new TemplateNotFoundException("Template not found")); - mockMvc.perform(get("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(get("/templates/getNbr").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); } @Test public void testDeleteTemplate() throws Exception { Mockito.doNothing().when(templateBusinessLogic).deleteTemplate(ArgumentMatchers.any()); - mockMvc.perform(delete("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/templates/getNbr").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); Mockito.doThrow(new TemplateNotFoundException("Template not found")) .when(templateBusinessLogic) .deleteTemplate(ArgumentMatchers.any()); - mockMvc.perform(delete("/templates/ran-network/getNbr").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(delete("/templates/getNbr").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); } diff --git a/cps-tbdmt-service/pom.xml b/cps-tbdmt-service/pom.xml index 3291e8d..d9181c5 100644 --- a/cps-tbdmt-service/pom.xml +++ b/cps-tbdmt-service/pom.xml @@ -77,6 +77,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> <!--Test dependencies--> <dependency> <groupId>com.openpojo</groupId> diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/OutputTransformationException.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/OutputTransformationException.java new file mode 100644 index 0000000..f3d8e05 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/OutputTransformationException.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * 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.cps.tbdmt.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class OutputTransformationException extends RuntimeException { + + public OutputTransformationException(final String exception) { + super(exception); + } +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java index 00ad134..fe8f528 100644 --- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java @@ -53,4 +53,8 @@ public class Template implements Serializable { private Boolean includeDescendants; + private String multipleQueryTemplateId; + + private String transformParam; + } diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java index ab465b9..3e8353b 100644 --- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java @@ -38,6 +38,4 @@ public class TemplateKey implements Serializable { private String templateId; - private String model; - } diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java index 6b08ad8..b7873cf 100644 --- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java @@ -48,4 +48,8 @@ public class TemplateRequest implements Serializable { private String requestType; private Boolean includeDescendants; + + private String multipleQueryTemplateId; + + private String transformParam; } diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java index b7dd42a..05aed38 100644 --- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java @@ -20,13 +20,24 @@ package org.onap.cps.tbdmt.service; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.hubspot.jinjava.Jinjava; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.onap.cps.tbdmt.client.CpsRestClient; import org.onap.cps.tbdmt.db.TemplateRepository; import org.onap.cps.tbdmt.exception.CpsClientException; import org.onap.cps.tbdmt.exception.ExecuteException; +import org.onap.cps.tbdmt.exception.OutputTransformationException; import org.onap.cps.tbdmt.exception.TemplateNotFoundException; import org.onap.cps.tbdmt.model.AppConfiguration; import org.onap.cps.tbdmt.model.ExecutionRequest; @@ -51,19 +62,68 @@ public class ExecutionBusinessLogic { * Execute a template stored in the database. * * @param schemaSet schema set - * @param id id + * @param templateId templateId * @param executionRequest inputs to be applied to the templates * @return result response from the execution of template */ - public String executeTemplate(final String schemaSet, final String id, final ExecutionRequest executionRequest) { + public String executeTemplate(final String schemaSet, final String templateId, + final ExecutionRequest executionRequest) { - final Optional<Template> templateOptional = templateRepository.findById(new TemplateKey(id, schemaSet)); + final Optional<Template> templateOptional = templateRepository.findById(new TemplateKey(templateId)); if (templateOptional.isPresent()) { - return execute(templateOptional.get(), executionRequest.getInputParameters()); + if (!StringUtils.isBlank(templateOptional.get().getMultipleQueryTemplateId())) { + return executeMultipleQuery(templateOptional.get(), executionRequest.getInputParameters()); + } else { + return execute(templateOptional.get(), executionRequest.getInputParameters()); + } } throw new TemplateNotFoundException("Template does not exist"); } + private String executeMultipleQuery(final Template template, final Map<String, String> inputParameters) + throws OutputTransformationException { + + final List<Object> processedQueryOutput = new ArrayList<Object>(); + final String multipleQuerytemplateId = template.getMultipleQueryTemplateId(); + final Optional<Template> multipleQueryTemplate = + templateRepository.findById(new TemplateKey(multipleQuerytemplateId)); + if (!multipleQueryTemplate.isPresent()) { + throw new TemplateNotFoundException("Multiple query template does not exist"); + } else { + if (StringUtils.isBlank(multipleQueryTemplate.get().getTransformParam())) { + throw new OutputTransformationException("Error executing multiple query: " + + "Template must have atleast one transformParameter"); + } + final List<String> transformParamList = new ArrayList<String>( + Arrays.asList(multipleQueryTemplate.get().getTransformParam().split("\\s*,\\s*"))); + final String inputKey = transformParamList.get(transformParamList.size() - 1); + final String queryParamString = execute(multipleQueryTemplate.get(), inputParameters); + final List<String> queryParamList = new ArrayList<String>(); + final JsonParser jsonParser = new JsonParser(); + final Gson gson = new Gson(); + try { + if (jsonParser.parse(queryParamString).isJsonArray()) { + final JsonArray array = jsonParser.parse(queryParamString).getAsJsonArray(); + + for (final JsonElement jsonElement : array) { + queryParamList.add(gson.fromJson(jsonElement, String.class)); + } + } else { + queryParamList.add(queryParamString); + } + queryParamList.forEach(queryParam -> { + final Map<String, String> inputParameter = new HashMap<String, String>(); + inputParameter.put(inputKey, queryParam); + final Object result = execute(template, inputParameter); + processedQueryOutput.add(result); + }); + } catch (final Exception e) { + throw new OutputTransformationException(e.getLocalizedMessage()); + } + return processedQueryOutput.toString(); + } + } + private String execute(final Template template, final Map<String, String> inputParameters) { final String anchor = appConfiguration.getSchemaToAnchor().get(template.getModel()); if (anchor == null) { @@ -72,12 +132,70 @@ public class ExecutionBusinessLogic { final String xpath = generateXpath(template.getXpathTemplate(), inputParameters); try { - return cpsRestClient.fetchNode(anchor, xpath, template.getRequestType(), template.getIncludeDescendants()); + final String result = cpsRestClient.fetchNode(anchor, xpath, template.getRequestType(), + template.getIncludeDescendants()); + if (StringUtils.isBlank(template.getTransformParam())) { + return result; + } else { + final List<JsonElement> json = transform(template, result); + return new Gson().toJson(json); + } } catch (final CpsClientException e) { throw new ExecuteException(e.getLocalizedMessage()); } } + private List<JsonElement> transform(final Template template, final String result) { + + final JsonElement transformJsonElement = new Gson().fromJson(result, JsonElement.class); + List<JsonElement> transformedResult; + List<JsonElement> temp; + List<JsonElement> processedOutput = new ArrayList<JsonElement>(); + final List<String> transformParamList = + new ArrayList<String>(Arrays.asList(template.getTransformParam().split("\\s*,\\s*"))); + try { + if (transformParamList.size() > 0) { + processedOutput = find(transformParamList.get(0), transformJsonElement, new ArrayList<JsonElement>()); + transformParamList.remove(0); + for (final String param : transformParamList) { + transformedResult = new ArrayList<JsonElement>(); + + for (final JsonElement json : processedOutput) { + temp = find(param, json, new ArrayList<JsonElement>()); + transformedResult.addAll(temp); + } + processedOutput.clear(); + processedOutput.addAll(transformedResult); + } + } + } catch (final Exception e) { + throw new OutputTransformationException(e.getLocalizedMessage()); + } + + return processedOutput; + + } + + private static List<JsonElement> find(final String param, final JsonElement jsonElement, + final List<JsonElement> output) { + + if (jsonElement.isJsonArray()) { + for (final JsonElement je : jsonElement.getAsJsonArray()) { + find(param, je, output); + } + } else { + if (jsonElement.isJsonObject()) { + final JsonObject jsonObject = jsonElement.getAsJsonObject(); + if (jsonObject.has(param)) { + output.add(jsonObject.getAsJsonObject().get(param)); + + } + } + } + return output; + + } + private String generateXpath(final String xpathTemplate, final Map<String, String> templateParameters) { return new Jinjava().render(xpathTemplate, templateParameters); } diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java index ae179d3..a8597f1 100644 --- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java @@ -46,9 +46,10 @@ public class TemplateBusinessLogic { * @return template */ public Template createTemplate(final TemplateRequest templateRequest) { - final Template template = new Template(templateRequest.getTemplateId(), - templateRequest.getModel(), templateRequest.getXpathTemplate(), - templateRequest.getRequestType(), templateRequest.getIncludeDescendants()); + final Template template = new Template(templateRequest.getTemplateId(), templateRequest.getModel(), + templateRequest.getXpathTemplate(), templateRequest.getRequestType(), + templateRequest.getIncludeDescendants(), templateRequest.getMultipleQueryTemplateId(), + templateRequest.getTransformParam()); return templateRepository.save(template); } 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 46f28cb..6e0ae4b 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 @@ -129,4 +129,5 @@ public class CpsRestClientTest { exception.expectMessage("Connection refused"); cpsRestClient.fetchNode("coverage-area-onap", "sample", "get", true); } + } 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 c3be423..e8689a9 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 @@ -22,6 +22,8 @@ package org.onap.cps.tbdmt.service; import static org.junit.Assert.assertEquals; +import java.io.File; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -40,11 +42,13 @@ import org.onap.cps.tbdmt.exception.TemplateNotFoundException; import org.onap.cps.tbdmt.model.AppConfiguration; import org.onap.cps.tbdmt.model.ExecutionRequest; import org.onap.cps.tbdmt.model.Template; +import org.onap.cps.tbdmt.model.TemplateKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; +import org.springframework.core.io.ClassPathResource; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -91,8 +95,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, "get", true); - queryTemplate = new Template("getNbr", "ran-network", xpathTemplate, "query", true); + template = new Template("getNbr", "ran-network", xpathTemplate, "get", true, "", ""); + queryTemplate = new Template("getNbr", "ran-network", xpathTemplate, "query", true, "", ""); } @Test @@ -128,7 +132,7 @@ public class ExecutionBusinessLogicTest { exception.expectMessage(exceptionMessage); executionBusinessLogic.executeTemplate("ran-network", "getNbr", request); - final Template template1 = new Template("getNbr", "ran-net", "sample", "get", true); + final Template template1 = new Template("getNbr", "ran-net", "sample", "get", true, "", ""); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template1)); exception.expect(ExecuteException.class); @@ -139,7 +143,7 @@ public class ExecutionBusinessLogicTest { @Test public void testExecuteTemplateNoAnchor() { - final Template template = new Template("getNbr", "ran-net", "sample", "get", true); + final Template template = new Template("getNbr", "ran-net", "sample", "get", true, "", ""); Mockito.when(templateRepository.findById(ArgumentMatchers.any())) .thenReturn(Optional.of(template)); exception.expect(ExecuteException.class); @@ -161,4 +165,77 @@ public class ExecutionBusinessLogicTest { } + @Test + public void testOutputTransform() { + final Map<String, String> input = new HashMap<>(); + input.put("idNearRTRIC", "11"); + final String transformParam = "GNBDUFunction, NRCellDU, attributes, cellLocalId"; + final Template template = new Template("get-nrcelldu-id", "ran-network", "/NearRTRIC/[@idNearRTRIC='11']", + "get", true, null, transformParam); + final String transformedResult = "[15299,15277]"; + try { + final String result = readFromFile("sample_transform_query_data.json"); + Mockito.when(cpsRestClient.fetchNode("ran-network", "/NearRTRIC/[@idNearRTRIC='11']", "get", true)) + .thenReturn(result); + Mockito.when(templateRepository.findById(ArgumentMatchers.any())).thenReturn(Optional.of(template)); + assertEquals(transformedResult, + executionBusinessLogic.executeTemplate("ran-network", "get-nrcelldu-id", request)); + } catch (final Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testMultipleQuery() { + final Map<String, String> input = new HashMap<>(); + input.put("idNearRTRIC", "11"); + final String transformParam1 = "branch, name"; + final String transformParam2 = "name"; + final Template template1 = + new Template("get-tree", "ran-network", "/test-tree", "get", true, null, transformParam1); + final Template template2 = new Template("get-branch", "ran-network", "/test-tree/branch[@name='{{name}}']/nest", + "get", true, "get-tree", transformParam2); + final String transformedResult = "[[\"Big\"], [\"Small\"]]"; + + try { + final String result1 = readFromFile("sample_multiple_query_data_1.json"); + final String result2 = readFromFile("sample_multiple_query_data_2.json"); + final String result3 = readFromFile("sample_multiple_query_data_3.json"); + Mockito.when(cpsRestClient.fetchNode("ran-network", "/test-tree", "get", true)).thenReturn(result1); + Mockito.when(templateRepository.findById(ArgumentMatchers.any())).thenReturn(Optional.of(template1)); + + Mockito.when(cpsRestClient.fetchNode("ran-network", "/test-tree/branch[@name='Right']/nest", "get", true)) + .thenReturn(result2); + Mockito.when(cpsRestClient.fetchNode("ran-network", "/test-tree/branch[@name='Left']/nest", "get", true)) + .thenReturn(result3); + final TemplateKey key = new TemplateKey("get-branch"); + Mockito.when(templateRepository.findById(key)).thenReturn(Optional.of(template2)); + + assertEquals(transformedResult, + executionBusinessLogic.executeTemplate("ran-network", "get-branch", request)); + } catch (final CpsClientException e) { + e.printStackTrace(); + } catch (final Exception e) { + e.printStackTrace(); + } + } + + /** + * Reads a file from classpath. + * + * @param fileName name of the file to be read + * @return result contents of the file + */ + private String readFromFile(final String fileName) { + String content = new String(); + try { + final File resource = new ClassPathResource(fileName).getFile(); + content = new String(Files.readAllBytes(resource.toPath())); + } catch (final Exception e) { + e.printStackTrace(); + content = null; + } + return content; + } + } 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 d0bdf47..948b2c3 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,14 @@ public class TemplateBusinessLogicTest { @Before public void setup() { - template = new Template("getNbr", "ran-network", "sample", "get", true); - final TemplateKey templateKey = new TemplateKey("getNbr", "ran-network"); + template = new Template("getNbr", "ran-network", "sample", "get", true, "sample", "getRIC"); + final TemplateKey templateKey = new TemplateKey("getNbr"); } @Test public void testCreateTemplate() throws Exception { - final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", true); + final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", + true, "sample", "getRIC"); Mockito.when(templateRepository.save(ArgumentMatchers.any())).thenReturn(template); assertEquals(template, templateBusinessLogic.createTemplate(templateRequest)); } @@ -99,7 +100,7 @@ public class TemplateBusinessLogicTest { .thenReturn(Optional.empty()); exception.expect(TemplateNotFoundException.class); exception.expectMessage("Template not found for given id: getNbr"); - templateBusinessLogic.getTemplate(new TemplateKey("getNbr", "empty-schema")); + templateBusinessLogic.getTemplate(new TemplateKey("getNbr")); } @Test @@ -111,6 +112,6 @@ public class TemplateBusinessLogicTest { Mockito.when(templateRepository.existsById(ArgumentMatchers.any())).thenReturn(false); exception.expect(TemplateNotFoundException.class); exception.expectMessage("Template not found for given id: getNbr"); - templateBusinessLogic.deleteTemplate(new TemplateKey("getNbr", "empty-schema")); + templateBusinessLogic.deleteTemplate(new TemplateKey("getNbr")); } } diff --git a/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_1.json b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_1.json new file mode 100644 index 0000000..9cef3ea --- /dev/null +++ b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_1.json @@ -0,0 +1,26 @@ +{ + "branch":[ + { + "name":"Right", + "nest":{ + "name":"Big", + "birds":[ + "Owl", + "Raven", + "Crow" + ] + } + }, + { + "name":"Left", + "nest":{ + "name":"Small", + "birds":[ + "Robin", + "Sparrow", + "Finch" + ] + } + } + ] +} diff --git a/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_2.json b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_2.json new file mode 100644 index 0000000..8a4e509 --- /dev/null +++ b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_2.json @@ -0,0 +1,8 @@ +{ + "name":"Big", + "birds":[ + "Owl", + "Raven", + "Crow" + ] +} diff --git a/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_3.json b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_3.json new file mode 100644 index 0000000..b5770ab --- /dev/null +++ b/cps-tbdmt-service/src/test/resources/sample_multiple_query_data_3.json @@ -0,0 +1,8 @@ +{ + "name":"Small", + "birds":[ + "Robin", + "Sparrow", + "Finch" + ] +} diff --git a/cps-tbdmt-service/src/test/resources/sample_transform_query_data.json b/cps-tbdmt-service/src/test/resources/sample_transform_query_data.json new file mode 100644 index 0000000..d30b899 --- /dev/null +++ b/cps-tbdmt-service/src/test/resources/sample_transform_query_data.json @@ -0,0 +1,104 @@ +{ + "attributes":{ + "near-rt-ric-url":"10.165.160.47:6080", + "trackingArea":"Kingston", + "rANNFNSSIList":[ + "e893-e93r-c0f2-kj76", + "m93ed-e93e-c0f2-9i7y" + ] + }, + "GNBDUFunction":[ + { + "idGNBDUFunction":"22", + "attributes":{ + "gNBDUFunction-url":"10.165.160.13:6080", + "gNBIdLength":23, + "gNBDUName":"gnbdu1", + "gNBDUId":22, + "userLabel":"user", + "sAP":[ + { + "host":"localhost", + "port":8080 + } + ] + }, + "NRCellDU":[ + { + "idNRCellDU":"15299", + "attributes":{ + "nRCellDU-url":"10.165.160.15:8083", + "cellLocalId":15299, + "pLMNInfoList":[ + { + "mcc":"211", + "mnc":"211", + "sNSSAIList":[ + { + "sNssai":"202", + "status":"active", + "configData":[ + { + "configParameter":"maxNumberOfConns", + "configValue":20 + } + ] + } + ] + } + ], + "nRPCI":11, + "nRTAC":14777, + "nRSectorCarrierRef":[ + "OU=Sales" + ], + "userLabel":"user", + "sAP":[ + { + "host":"localhost", + "port":8080 + } + ] + } + } + ] + }, + { + "idGNBDUFunction":"33", + "attributes":{ + "gNBDUFunction-url":"10.165.160.13:6080", + "gNBIdLength":23, + "gNBDUName":"gnbdu1", + "gNBDUId":22, + "userLabel":"user", + "sAP":[ + { + "host":"localhost", + "port":8080 + } + ] + }, + "NRCellDU":[ + { + "idNRCellDU":"15277", + "attributes":{ + "nRCellDU-url":"10.165.160.15:8083", + "cellLocalId":15277, + "nRPCI":11, + "nRTAC":14777, + "nRSectorCarrierRef":[ + "OU=Sales" + ], + "userLabel":"user", + "sAP":[ + { + "host":"localhost", + "port":8080 + } + ] + } + } + ] + } + ] +} |