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);
}
}
}
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));
}
}
}
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));
}
}
}
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()));
}
}
}
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));
}
}
}
Aggregations