Skip to content

Commit

Permalink
[MODEXPW-528] Update failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Dec 9, 2024
1 parent 816a40e commit 52a7465
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.folio.dew.batch.acquisitions.edifact.jobs;

import static org.folio.dew.utils.QueryUtils.combineCqlExpressions;
import static org.folio.dew.utils.QueryUtils.convertFieldListToCqlQuery;
import static org.folio.dew.utils.QueryUtils.convertFieldListToEnclosedCqlQuery;
import static org.folio.dew.utils.QueryUtils.getCqlExpressionForFieldNullValue;
import static org.folio.dew.utils.QueryUtils.negateQuery;

Expand Down Expand Up @@ -64,7 +64,7 @@ protected String getPoLineQuery(VendorEdiOrdersExportConfig ediConfig) {
// Order line filters
"automaticExport==true", // line with automatic export
getCqlExpressionForFieldNullValue("lastEDIExportDate"), // has not been exported yet
convertFieldListToCqlQuery(acqMethods, "acquisitionMethod", true), // acquisitionMethod in default list
convertFieldListToEnclosedCqlQuery(acqMethods, "acquisitionMethod", true), // acquisitionMethod in default list
getVendorAccountFilter(ediConfig) // vendor account no filter
);
log.info("getPoLineQuery:: Fetching purchase order lines with query: {}", resultQuery);
Expand All @@ -76,10 +76,10 @@ private String getVendorAccountFilter(VendorEdiOrdersExportConfig ediConfig) {
var configQuery = "configName==%s_%s*".formatted(ExportType.EDIFACT_ORDERS_EXPORT, ediConfig.getVendorId());
var configs = dataExportSpringClient.getExportConfigs(configQuery);
return configs.getTotalRecords() > 1
? negateQuery(convertFieldListToCqlQuery(extractAllAccountNoLists(configs), "vendorDetail.vendorAccount", true))
: null;
? negateQuery(convertFieldListToEnclosedCqlQuery(extractAllAccountNoLists(configs), "vendorDetail.vendorAccount", true))
: "";
}
return convertFieldListToCqlQuery(ediConfig.getEdiConfig().getAccountNoList(), "vendorDetail.vendorAccount", true);
return convertFieldListToEnclosedCqlQuery(ediConfig.getEdiConfig().getAccountNoList(), "vendorDetail.vendorAccount", true);
}

private Set<String> extractAllAccountNoLists(ExportConfigCollection configs) {
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/org/folio/dew/utils/QueryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static String combineCqlExpressions(String operator, String... expression
* @return A CQL query string representing the IDs.
*/
public static String convertIdsToCqlQuery(Collection<String> ids, String idField) {
return convertFieldListToCqlQuery(ids, idField, true);
return convertFieldListToCqlQuery(ids, idField, true, false);
}

/**
Expand All @@ -73,7 +73,19 @@ public static String convertIdsToCqlQuery(Collection<String> ids, String idField
* @return A CQL query string representing the IDs.
*/
public static String convertIdsToCqlQuery(Collection<String> ids) {
return convertFieldListToCqlQuery(ids, ID, true);
return convertFieldListToCqlQuery(ids, ID, true, false);
}

/**
* Transform list of values for some property to CQL query using 'or' operation and enclosing values with quotes
*
* @param values list of field values
* @param fieldName the property name to search by
* @param strictMatch indicates whether strict match mode (i.e. ==) should be used or not (i.e. =)
* @return String representing CQL query to get records by some property enclosed values
*/
public static String convertFieldListToEnclosedCqlQuery(Collection<?> values, String fieldName, boolean strictMatch) {
return convertFieldListToCqlQuery(values, fieldName, strictMatch, true);
}

/**
Expand All @@ -82,13 +94,15 @@ public static String convertIdsToCqlQuery(Collection<String> ids) {
* @param values list of field values
* @param fieldName the property name to search by
* @param strictMatch indicates whether strict match mode (i.e. ==) should be used or not (i.e. =)
* @param enclosed indicates whether values should be enclosed with quotes (i.e. asd) or not (i.e. "asd")
* @return String representing CQL query to get records by some property values
*/
public static String convertFieldListToCqlQuery(Collection<?> values, String fieldName, boolean strictMatch) {
public static String convertFieldListToCqlQuery(Collection<?> values, String fieldName, boolean strictMatch, boolean enclosed) {
var prefix = String.format(strictMatch ? CQL_MATCH_STRICT : CQL_MATCH, fieldName, CQL_PREFIX);
var enclose = enclosed ? "\"%s\"" : "%s";
return StreamEx.of(values)
.map(Object::toString)
.map("\"%s\""::formatted)
.map(enclose::formatted)
.joining(" or ", prefix, CQL_SUFFIX);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ protected void setUp() {
@Test
void testEdifactOrdersExport() throws Exception {
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob);
String cqlString = "purchaseOrder.workflowStatus==Open" +
" AND purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1" +
String cqlString = "(purchaseOrder.workflowStatus==Open)" +
" AND (purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1)" +
" AND (cql.allRecords=1 NOT purchaseOrder.manualPo==true)" +
" AND automaticExport==true" +
" AND (automaticExport==true)" +
" AND (cql.allRecords=1 NOT lastEDIExportDate=\"\")" +
" AND acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\")" +
" AND vendorDetail.vendorAccount==(\"BRXXXXX-01\")";
" AND (acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\"))" +
" AND (vendorDetail.vendorAccount==(\"BRXXXXX-01\"))";
doReturn(poLines).when(ordersService).getPoLinesByQuery(cqlString);
doReturn(orders).when(ordersService).getPurchaseOrdersByIds(anyList());
doReturn("test1").when(purchaseOrdersToEdifactMapper).convertOrdersToEdifact(any(), any(), anyString());
Expand All @@ -73,12 +73,12 @@ void testEdifactOrdersExport() throws Exception {
@Test
void testEdifactOrdersExportDefaultConfig() throws Exception {
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob);
String cqlString = "purchaseOrder.workflowStatus==Open" +
" AND purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1" +
String cqlString = "(purchaseOrder.workflowStatus==Open)" +
" AND (purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1)" +
" AND (cql.allRecords=1 NOT purchaseOrder.manualPo==true)" +
" AND automaticExport==true" +
" AND (automaticExport==true)" +
" AND (cql.allRecords=1 NOT lastEDIExportDate=\"\")" +
" AND acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\")";
" AND (acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\"))";
String configSql = "configName==EDIFACT_ORDERS_EXPORT_d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1*";
ExportConfigCollection exportConfigCollection = new ExportConfigCollection();
exportConfigCollection.setTotalRecords(1);
Expand All @@ -99,13 +99,13 @@ void testEdifactOrdersExportDefaultConfig() throws Exception {
@Test
void testEdifactOrdersExportDefaultConfigWithTwoExportConfigs() throws Exception {
JobLauncherTestUtils testLauncher = createTestLauncher(edifactExportJob);
String cqlString = "purchaseOrder.workflowStatus==Open" +
" AND purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1" +
String cqlString = "(purchaseOrder.workflowStatus==Open)" +
" AND (purchaseOrder.vendor==d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1)" +
" AND (cql.allRecords=1 NOT purchaseOrder.manualPo==true)" +
" AND automaticExport==true" +
" AND (automaticExport==true)" +
" AND (cql.allRecords=1 NOT lastEDIExportDate=\"\")" +
" AND acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\")" +
" AND cql.allRecords=1 NOT vendorDetail.vendorAccount==(\"org1\" OR \"org2\")";
" AND (acquisitionMethod==(\"306489dd-0053-49ee-a068-c316444a8f55\"))" +
" AND (cql.allRecords=1 NOT vendorDetail.vendorAccount==(\"org1\" or \"org2\"))";
String configSql = "configName==EDIFACT_ORDERS_EXPORT_d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1*";
ExportConfigCollection exportConfigCollection = objectMapper.readValue(getMockData(DATA_EXPORT_CONFIGS_PATH), ExportConfigCollection.class);
poLines.get(0).getVendorDetail().setVendorAccount(null);
Expand Down

0 comments on commit 52a7465

Please sign in to comment.