mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
Merge branch 'feature/CTLE-422-api-for-scripts' into integration/sprint-25
# Conflicts: # qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/QueryAction.java
This commit is contained in:
@ -26,6 +26,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
|
||||
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
@ -189,6 +190,77 @@ class QueryActionTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testQueryAssociationsWithPipe() throws QException
|
||||
{
|
||||
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS, true);
|
||||
insert2OrdersWith3Lines3LineExtrinsicsAnd4OrderExtrinsicAssociations();
|
||||
|
||||
RecordPipe pipe = new RecordPipe();
|
||||
QueryInput queryInput = new QueryInput();
|
||||
queryInput.setTableName(TestUtils.TABLE_NAME_ORDER);
|
||||
queryInput.setRecordPipe(pipe);
|
||||
queryInput.setIncludeAssociations(true);
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
assertNotNull(queryOutput);
|
||||
|
||||
List<QRecord> records = pipe.consumeAvailableRecords();
|
||||
assertThat(records).isNotEmpty();
|
||||
|
||||
QRecord order0 = records.get(0);
|
||||
assertEquals(2, order0.getAssociatedRecords().get("orderLine").size());
|
||||
assertEquals(3, order0.getAssociatedRecords().get("extrinsics").size());
|
||||
|
||||
QRecord orderLine00 = order0.getAssociatedRecords().get("orderLine").get(0);
|
||||
assertEquals(1, orderLine00.getAssociatedRecords().get("extrinsics").size());
|
||||
QRecord orderLine01 = order0.getAssociatedRecords().get("orderLine").get(1);
|
||||
assertEquals(2, orderLine01.getAssociatedRecords().get("extrinsics").size());
|
||||
|
||||
QRecord order1 = records.get(1);
|
||||
assertEquals(1, order1.getAssociatedRecords().get("orderLine").size());
|
||||
assertEquals(1, order1.getAssociatedRecords().get("extrinsics").size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testQueryManyRecordsAssociationsWithPipe() throws QException
|
||||
{
|
||||
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE_ALL_ACCESS, true);
|
||||
insertNOrdersWithAssociations(2500);
|
||||
|
||||
RecordPipe pipe = new RecordPipe(1000);
|
||||
QueryInput queryInput = new QueryInput();
|
||||
queryInput.setTableName(TestUtils.TABLE_NAME_ORDER);
|
||||
queryInput.setRecordPipe(pipe);
|
||||
queryInput.setIncludeAssociations(true);
|
||||
|
||||
int recordsConsumed = new AsyncRecordPipeLoop().run("Test", null, pipe, (callback) ->
|
||||
{
|
||||
new QueryAction().execute(queryInput);
|
||||
return (true);
|
||||
}, () ->
|
||||
{
|
||||
List<QRecord> records = pipe.consumeAvailableRecords();
|
||||
for(QRecord record : records)
|
||||
{
|
||||
assertEquals(1, record.getAssociatedRecords().get("orderLine").size());
|
||||
assertEquals(1, record.getAssociatedRecords().get("extrinsics").size());
|
||||
}
|
||||
return (records.size());
|
||||
});
|
||||
|
||||
assertEquals(2500, recordsConsumed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -345,4 +417,25 @@ class QueryActionTest extends BaseTest
|
||||
));
|
||||
new InsertAction().execute(insertInput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void insertNOrdersWithAssociations(int n) throws QException
|
||||
{
|
||||
List<QRecord> recordList = new ArrayList<>();
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
recordList.add(new QRecord().withValue("storeId", 1).withValue("orderNo", "ORD" + i)
|
||||
.withAssociatedRecord("orderLine", new QRecord().withValue("sku", "BASIC1").withValue("quantity", 3))
|
||||
.withAssociatedRecord("extrinsics", new QRecord().withValue("key", "YOUR-FIELD").withValue("value", "YOUR-VALUE")));
|
||||
}
|
||||
|
||||
InsertInput insertInput = new InsertInput();
|
||||
insertInput.setTableName(TestUtils.TABLE_NAME_ORDER);
|
||||
insertInput.setRecords(recordList);
|
||||
new InsertAction().execute(insertInput);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.adapters;
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.shared.mapping.QIndexBasedFieldMapping;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.shared.mapping.QKeyBasedFieldMapping;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
@ -48,7 +49,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_nullInput()
|
||||
public void test_buildRecordsFromCsv_nullInput() throws QException
|
||||
{
|
||||
testExpectedToThrow(null);
|
||||
}
|
||||
@ -59,7 +60,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_emptyStringInput()
|
||||
public void test_buildRecordsFromCsv_emptyStringInput() throws QException
|
||||
{
|
||||
testExpectedToThrow("");
|
||||
}
|
||||
@ -69,7 +70,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void testExpectedToThrow(String csv)
|
||||
private void testExpectedToThrow(String csv) throws QException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -92,7 +93,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_emptyList()
|
||||
public void test_buildRecordsFromCsv_emptyList() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
List<QRecord> qRecords = csvToQRecordAdapter.buildRecordsFromCsv(getPersonCsvHeader(), TestUtils.defineTablePerson(), null);
|
||||
@ -142,7 +143,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_oneRowStandardHeaderNoMapping()
|
||||
public void test_buildRecordsFromCsv_oneRowStandardHeaderNoMapping() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
List<QRecord> qRecords = csvToQRecordAdapter.buildRecordsFromCsv(getPersonCsvHeader() + getPersonCsvRow1(), TestUtils.defineTablePerson(), null);
|
||||
@ -159,7 +160,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_twoRowsStandardHeaderNoMapping()
|
||||
public void test_buildRecordsFromCsv_twoRowsStandardHeaderNoMapping() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
List<QRecord> qRecords = csvToQRecordAdapter.buildRecordsFromCsv(getPersonCsvHeader() + getPersonCsvRow1() + getPersonCsvRow2(), TestUtils.defineTablePerson(), null);
|
||||
@ -179,7 +180,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_oneRowCustomKeyBasedMapping()
|
||||
public void test_buildRecordsFromCsv_oneRowCustomKeyBasedMapping() throws QException
|
||||
{
|
||||
String csvCustomHeader = """
|
||||
"id","created","modified","first","last","birthday","email"\r
|
||||
@ -209,7 +210,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_buildRecordsFromCsv_twoRowsCustomIndexBasedMapping()
|
||||
public void test_buildRecordsFromCsv_twoRowsCustomIndexBasedMapping() throws QException
|
||||
{
|
||||
int index = 1;
|
||||
QIndexBasedFieldMapping mapping = new QIndexBasedFieldMapping()
|
||||
@ -241,7 +242,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
** header names on the RHS.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void test_duplicatedColumnHeaders()
|
||||
public void test_duplicatedColumnHeaders() throws QException
|
||||
{
|
||||
QKeyBasedFieldMapping mapping = new QKeyBasedFieldMapping()
|
||||
.withMapping("id", "id")
|
||||
@ -291,7 +292,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testByteOrderMarker()
|
||||
void testByteOrderMarker() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
|
||||
@ -313,7 +314,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
** Fix an IndexOutOfBounds that we used to throw.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testTooFewBodyColumns()
|
||||
void testTooFewBodyColumns() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
List<QRecord> records = csvToQRecordAdapter.buildRecordsFromCsv("""
|
||||
@ -331,7 +332,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void testTooFewColumnsIndexMapping()
|
||||
public void testTooFewColumnsIndexMapping() throws QException
|
||||
{
|
||||
int index = 1;
|
||||
QIndexBasedFieldMapping mapping = new QIndexBasedFieldMapping()
|
||||
@ -353,7 +354,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testCaseSensitiveHeaders()
|
||||
void testCaseSensitiveHeaders() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
csvToQRecordAdapter.buildRecordsFromCsv(new CsvToQRecordAdapter.InputWrapper()
|
||||
@ -376,7 +377,7 @@ class CsvToQRecordAdapterTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testCaseInsensitiveHeaders()
|
||||
void testCaseInsensitiveHeaders() throws QException
|
||||
{
|
||||
CsvToQRecordAdapter csvToQRecordAdapter = new CsvToQRecordAdapter();
|
||||
csvToQRecordAdapter.buildRecordsFromCsv(new CsvToQRecordAdapter.InputWrapper()
|
||||
|
@ -222,7 +222,10 @@ class TableSyncProcessTest extends BaseTest
|
||||
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||
{
|
||||
List<QRecord> qRecords = TestUtils.queryTable(QContext.getQInstance(), TestUtils.TABLE_NAME_PERSON_MEMORY);
|
||||
qRecords.forEach(r -> getRecordPipe().addRecord(r));
|
||||
for(QRecord qRecord : qRecords)
|
||||
{
|
||||
getRecordPipe().addRecord(qRecord);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// re-add records 1 and 5 to the pipe //
|
||||
|
Reference in New Issue
Block a user