Search in sources :

Example 1 with CsvParser

use of org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser in project openEHR_SDK by ehrbase.

the class TestQueryEngine method checkNumericQuery.

protected void checkNumericQuery(String dirPath, String csvPath) throws IOException {
    NumericExpressionSettings numericLongExpressionSettings = new NumericExpressionSettings();
    CsvParser csvParser = new CsvParser(numericLongExpressionSettings.settings());
    csvParser.parse(new FileReader(csvPath));
    List<NumericExpression> attributeDefinitions = numericLongExpressionSettings.getNumericExpressionRow().getBeans();
    for (NumericExpression numericExpression : attributeDefinitions) {
        if (numericExpression.getOptionalComment() == null) {
            String leftSide = "";
            if (numericExpression.getLeftSideExpression() != null)
                leftSide = Files.readString(Paths.get(dirPath + "/" + numericExpression.getLeftSideExpression()));
            String aql;
            if (!leftSide.isEmpty())
                aql = leftSide + " WHERE " + numericExpression.getRightSideExpression();
            else
                aql = numericExpression.getRightSideExpression();
            boolean shouldFail = false;
            if (numericExpression.getExpectedResult() != null)
                shouldFail = numericExpression.getExpectedResult().equals(-1L) ? true : false;
            QueryResponseData result = performAqlQuery(aql, shouldFail);
            if (shouldFail)
                continue;
            if (result.getRows().isEmpty()) {
                if (numericExpression.getExpectedResult() == null)
                    continue;
                else
                    fail(numericExpression.getRightSideExpression() + ": no result");
            }
            Object expectedResult = numericExpression.getExpectedResult();
            try {
                if (numericExpression.getJavaType() != null) {
                    Class clazz = Class.forName(numericExpression.getJavaType());
                    Method valueOf = clazz.getMethod("valueOf", String.class);
                    expectedResult = valueOf.invoke(null, numericExpression.getExpectedResult());
                }
            } catch (Exception e) {
                throw new IllegalArgumentException("Invalid data type:" + numericExpression.getJavaType());
            }
            // TODO: iterate on result
            List<Object> objectList = result.getRows().get(0);
            assertThat(valueObject(objectList.get(0))).as(numericExpression.getRightSideExpression()).isEqualTo(expectedResult);
        }
    }
}
Also used : NumericExpression(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.NumericExpression) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) Method(java.lang.reflect.Method) WrongStatusCodeException(org.ehrbase.client.exception.WrongStatusCodeException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NumericExpressionSettings(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.NumericExpressionSettings) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) FileReader(java.io.FileReader) RMObject(com.nedap.archie.rm.RMObject)

Example 2 with CsvParser

use of org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser in project openEHR_SDK by ehrbase.

the class TestQueryEngine method checkAutoWhereQuery.

protected void checkAutoWhereQuery(String csvPath, String rootPath, String contains, RMObject referenceNode) throws FileNotFoundException {
    SimplePathExpressionSettings simplePathExpressionSettings = new SimplePathExpressionSettings();
    CsvParser csvParser = new CsvParser(simplePathExpressionSettings.settings());
    csvParser.parse(new FileReader(csvPath));
    List<PathExpression> attributeDefinitions = simplePathExpressionSettings.getPathExpressionRow().getBeans();
    for (PathExpression pathExpression : attributeDefinitions) {
        if (pathExpression.getComment() == null) {
            // conventionally, if params[1] exists, this means skip the test
            String attributePath = pathExpression.getPath();
            QueryResponseData result = performQueryWithWhere(rootPath, attributePath, contains, new AutoWhereCondition(rootPath, attributePath, referenceNode).condition());
            if (result.getRows().isEmpty())
                fail(rootPath + "/" + attributePath + ": no result");
            List<Object> objectList = result.getRows().get(0);
            assertThat(valueObject(objectList.get(0))).as(rootPath + "/" + attributePath).isEqualTo(attributeValueAt(referenceNode, attributePath));
        }
    }
}
Also used : SimplePathExpressionSettings(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.SimplePathExpressionSettings) PathExpression(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.PathExpression) AutoWhereCondition(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.auto.AutoWhereCondition) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) FileReader(java.io.FileReader) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject)

Example 3 with CsvParser

use of org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser in project openEHR_SDK by ehrbase.

the class TestQueryEngine method checkAutoEhrStatusWhereQuery.

protected void checkAutoEhrStatusWhereQuery(String csvPath, String rootPath, RMObject referenceNode) throws FileNotFoundException {
    SimplePathExpressionSettings simplePathExpressionSettings = new SimplePathExpressionSettings();
    CsvParser csvParser = new CsvParser(simplePathExpressionSettings.settings());
    csvParser.parse(new FileReader(csvPath));
    List<PathExpression> attributeDefinitions = simplePathExpressionSettings.getPathExpressionRow().getBeans();
    for (PathExpression pathExpression : attributeDefinitions) {
        if (pathExpression.getComment() == null) {
            String attributePath = pathExpression.getPath();
            QueryResponseData result = performEhrStatusQueryWithAutoWhere(rootPath, attributePath, referenceNode);
            if (result.getRows().isEmpty())
                fail(rootPath + "/" + attributePath + ": no result");
            List<Object> objectList = result.getRows().get(0);
            assertThat(valueObject(objectList.get(0))).as(rootPath + "/" + attributePath).isEqualTo(attributeValueAt(referenceNode, attributePath));
        }
    }
}
Also used : SimplePathExpressionSettings(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.SimplePathExpressionSettings) PathExpression(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.PathExpression) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) FileReader(java.io.FileReader) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject)

Example 4 with CsvParser

use of org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser in project openEHR_SDK by ehrbase.

the class TestQueryEngine method checkArbitraryQuery.

protected void checkArbitraryQuery(String dirPath, String csvPath) throws IOException {
    ArbitraryExpressionSettings arbitraryExpressionSettings = new ArbitraryExpressionSettings();
    CsvParser csvParser = new CsvParser(arbitraryExpressionSettings.settings());
    csvParser.parse(new FileReader(csvPath));
    List<ArbitraryExpression> attributeDefinitions = arbitraryExpressionSettings.getArbitraryExpressionRow().getBeans();
    for (ArbitraryExpression arbitraryExpression : attributeDefinitions) {
        if (arbitraryExpression.getOptionalComment() == null) {
            String aql = arbitraryExpression.getRightSideExpression();
            if (arbitraryExpression.getLeftSideExpressionPath() != null) {
                String leftSide = Files.readString(Paths.get(dirPath + "/" + arbitraryExpression.getLeftSideExpressionPath()));
                aql = leftSide + " WHERE " + aql;
            }
            boolean shouldFail = false;
            if (arbitraryExpression.getExpectedResult() != null)
                shouldFail = arbitraryExpression.getExpectedResult().equals(FAIL_EXPECTED) ? true : false;
            QueryResponseData result = performAqlQuery(aql, shouldFail);
            if (shouldFail)
                continue;
            if (result.getRows().isEmpty()) {
                if (arbitraryExpression.getExpectedResult() == null)
                    continue;
                else
                    fail(arbitraryExpression.getRightSideExpression() + ": no result");
            }
            // //TODO: iterate on result
            List<Object> objectList = result.getRows().get(0);
            Object resultingObject = objectList.get(0);
            if (resultingObject instanceof List)
                resultingObject = ((List<?>) resultingObject).get(0);
            assertThat(valueObject(resultingObject)).as(arbitraryExpression.getRightSideExpression()).isEqualTo(valueObject(arbitraryExpression.getExpectedResult()));
        }
    }
}
Also used : ArbitraryExpression(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.ArbitraryExpression) ArbitraryExpressionSettings(org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.ArbitraryExpressionSettings) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) FileReader(java.io.FileReader) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject) List(java.util.List)

Example 5 with CsvParser

use of org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser in project openEHR_SDK by ehrbase.

the class SelectRMIT method testCompositionAttributeQuery.

@Test
public void testCompositionAttributeQuery() throws IOException {
    String rootPath = "c";
    RMObject referenceNode = aComposition;
    // reads in the test set
    BufferedReader inputCSVSetReader = new BufferedReader(new FileReader("src/test/resources/testsets/testCompositionAttributeQuery.csv"));
    String csvParams;
    CsvParser csvParser = new CsvParser(new CsvParserSettings());
    while ((csvParams = inputCSVSetReader.readLine()) != null) {
        String[] params = csvParser.parseLine(csvParams);
        String attributePath = params[0];
        if (params.length == 1) {
            // conventionally, if params[1] exists, this means skip the test
            QueryResponseData result = simpleSelectQueryEngine.performQuery(rootPath, attributePath, "composition c[openEHR-EHR-COMPOSITION.test_all_types.v1]");
            List<Object> objectList = result.getRows().get(0);
            // null value
            if (attributePath.contains("uid")) {
                assertThat(objectList.get(0)).isNotNull();
            } else
                assertThat(valueObject(objectList.get(0))).as(rootPath + "/" + attributePath).isEqualTo(attributeValueAt(referenceNode, attributePath));
        }
    }
}
Also used : CsvParserSettings(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParserSettings) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CsvParser(org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser) QueryResponseData(org.ehrbase.response.openehr.QueryResponseData) RMObject(com.nedap.archie.rm.RMObject) RMObject(com.nedap.archie.rm.RMObject) Test(org.junit.Test)

Aggregations

RMObject (com.nedap.archie.rm.RMObject)6 FileReader (java.io.FileReader)6 QueryResponseData (org.ehrbase.response.openehr.QueryResponseData)6 CsvParser (org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParser)6 PathExpression (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.PathExpression)3 SimplePathExpressionSettings (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.simple.SimplePathExpressionSettings)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 List (java.util.List)2 WrongStatusCodeException (org.ehrbase.client.exception.WrongStatusCodeException)2 BufferedReader (java.io.BufferedReader)1 Method (java.lang.reflect.Method)1 ArbitraryExpression (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.ArbitraryExpression)1 ArbitraryExpressionSettings (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.ArbitraryExpressionSettings)1 NumericExpression (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.NumericExpression)1 NumericExpressionSettings (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.arbitrary.NumericExpressionSettings)1 AutoWhereCondition (org.ehrbase.client.openehrclient.defaultrestclient.systematic.compositionquery.queries.auto.AutoWhereCondition)1 Test (org.junit.Test)1 CsvParserSettings (org.junit.jupiter.params.shadow.com.univocity.parsers.csv.CsvParserSettings)1