diff options
Diffstat (limited to 'cps-tbdmt-service/src/test')
7 files changed, 234 insertions, 9 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 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 + } + ] + } + } + ] + } + ] +} |