Better testing on join reports, possible value translations; renamed left & right in QueryJoin (now joinTable, baseTable)

This commit is contained in:
2022-12-22 13:39:37 -06:00
parent 799b695e14
commit 428f48602b
19 changed files with 851 additions and 120 deletions

View File

@ -554,4 +554,33 @@ public class GenerateReportActionTest
assertThat(row).containsOnlyKeys("Birth Date");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testReportWithPossibleValueColumns() throws QException
{
QInstance qInstance = TestUtils.defineInstance();
insertPersonRecords(qInstance);
ReportInput reportInput = new ReportInput(qInstance);
reportInput.setSession(new QSession());
reportInput.setReportName(TestUtils.REPORT_NAME_PERSON_SIMPLE);
reportInput.setReportFormat(ReportFormat.LIST_OF_MAPS);
reportInput.setReportOutputStream(new ByteArrayOutputStream());
new GenerateReportAction().execute(reportInput);
List<Map<String, String>> list = ListOfMapsExportStreamer.getList("Simple Report");
Iterator<Map<String, String>> iterator = list.iterator();
Map<String, String> row = iterator.next();
assertThat(row).containsKeys("Id", "First Name", "Last Name", "Home State Id", "Home State Name");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Name")).isEqualTo("IL");
}
}

View File

@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.actions.values;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
@ -188,7 +189,7 @@ public class QPossibleValueTranslatorTest
);
QTableMetaData personTable = qInstance.getTable(TestUtils.TABLE_NAME_PERSON);
MemoryRecordStore.resetStatistics();
possibleValueTranslator.primePvsCache(personTable, personRecords, null); // todo - test non-null queryJoins
possibleValueTranslator.primePvsCache(personTable, personRecords, null, null); // todo - test non-null queryJoins
assertEquals(1, MemoryRecordStore.getStatistics().get(MemoryRecordStore.STAT_QUERIES_RAN), "Should only run 1 query");
possibleValueTranslator.translatePossibleValue(shapeField, 1);
possibleValueTranslator.translatePossibleValue(shapeField, 2);
@ -360,4 +361,101 @@ public class QPossibleValueTranslatorTest
assertEquals("MO", records.get(1).getDisplayValue("homeStateId"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testPossibleValueWithSecondaryPossibleValueLabel() throws QException
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.addTable(new QTableMetaData()
.withName("city")
.withBackendName(TestUtils.MEMORY_BACKEND_NAME)
.withPrimaryKeyField("id")
.withField(new QFieldMetaData("id", QFieldType.INTEGER))
.withField(new QFieldMetaData("name", QFieldType.STRING))
.withField(new QFieldMetaData("regionId", QFieldType.INTEGER).withPossibleValueSourceName("region")));
qInstance.addTable(new QTableMetaData()
.withName("region")
.withBackendName(TestUtils.MEMORY_BACKEND_NAME)
.withPrimaryKeyField("id")
.withRecordLabelFormat("%s of %s")
.withRecordLabelFields("name", "countryId")
.withField(new QFieldMetaData("id", QFieldType.INTEGER))
.withField(new QFieldMetaData("name", QFieldType.STRING))
.withField(new QFieldMetaData("countryId", QFieldType.INTEGER).withPossibleValueSourceName("country")));
qInstance.addTable(new QTableMetaData()
.withName("country")
.withBackendName(TestUtils.MEMORY_BACKEND_NAME)
.withPrimaryKeyField("id")
.withRecordLabelFormat("%s")
.withRecordLabelFields("name")
.withField(new QFieldMetaData("id", QFieldType.INTEGER))
.withField(new QFieldMetaData("name", QFieldType.STRING)));
qInstance.addPossibleValueSource(new QPossibleValueSource()
.withName("region")
.withType(QPossibleValueSourceType.TABLE)
.withTableName("region")
.withValueFormatAndFields(PVSValueFormatAndFields.LABEL_ONLY));
qInstance.addPossibleValueSource(new QPossibleValueSource()
.withName("country")
.withType(QPossibleValueSourceType.TABLE)
.withTableName("country")
.withValueFormatAndFields(PVSValueFormatAndFields.LABEL_ONLY));
List<QRecord> regions = List.of(new QRecord().withValue("id", 11).withValue("name", "Missouri").withValue("countryId", 111));
List<QRecord> countries = List.of(new QRecord().withValue("id", 111).withValue("name", "U.S.A"));
TestUtils.insertRecords(qInstance, qInstance.getTable("region"), regions);
TestUtils.insertRecords(qInstance, qInstance.getTable("country"), countries);
MemoryRecordStore.resetStatistics();
MemoryRecordStore.setCollectStatistics(true);
QPossibleValueTranslator possibleValueTranslator = new QPossibleValueTranslator(qInstance, new QSession());
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// verify that if we run w/ an empty set for the param limitedToFieldNames, that we do NOT translate the regionId //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
List<QRecord> cities = List.of(new QRecord().withValue("id", 1).withValue("name", "St. Louis").withValue("regionId", 11));
possibleValueTranslator.translatePossibleValuesInRecords(qInstance.getTable("city"), cities, null, Set.of());
assertNull(cities.get(0).getDisplayValue("regionId"));
}
////////////////////////////////////////////////////////////////////////
// ditto a set that contains something, but not the field in question //
////////////////////////////////////////////////////////////////////////
{
List<QRecord> cities = List.of(new QRecord().withValue("id", 1).withValue("name", "St. Louis").withValue("regionId", 11));
possibleValueTranslator.translatePossibleValuesInRecords(qInstance.getTable("city"), cities, null, Set.of("foobar"));
assertNull(cities.get(0).getDisplayValue("regionId"));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// now re-run, w/ regionId - and we should see it get translated - and - the possible-value that it uses (countryId) as part of its label also gets translated. //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
List<QRecord> cities = List.of(new QRecord().withValue("id", 1).withValue("name", "St. Louis").withValue("regionId", 11));
possibleValueTranslator.translatePossibleValuesInRecords(qInstance.getTable("city"), cities, null, Set.of("regionId"));
assertEquals("Missouri of U.S.A", cities.get(0).getDisplayValue("regionId"));
}
/////////////////////////////////////////////////////////////////////////////////
// finally, verify that a null limitedToFieldNames means to translate them all //
/////////////////////////////////////////////////////////////////////////////////
{
List<QRecord> cities = List.of(new QRecord().withValue("id", 1).withValue("name", "St. Louis").withValue("regionId", 11));
possibleValueTranslator.translatePossibleValuesInRecords(qInstance.getTable("city"), cities, null, null);
assertEquals("Missouri of U.S.A", cities.get(0).getDisplayValue("regionId"));
}
}
}

View File

@ -47,7 +47,6 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.automation.RecordAutomationInput;
@ -141,7 +140,8 @@ public class TestUtils
public static final String TABLE_NAME_ID_AND_NAME_ONLY = "idAndNameOnly";
public static final String TABLE_NAME_BASEPULL = "basepullTest";
public static final String REPORT_NAME_SHAPES_PERSON = "shapesPersonReport";
public static final String REPORT_NAME_PERSON_JOIN_SHAPE = "simplePersonReport";
public static final String REPORT_NAME_PERSON_SIMPLE = "simplePersonReport";
public static final String REPORT_NAME_PERSON_JOIN_SHAPE = "personJoinShapeReport";
public static final String POSSIBLE_VALUE_SOURCE_STATE = "state"; // enum-type
public static final String POSSIBLE_VALUE_SOURCE_SHAPE = "shape"; // table-type
@ -195,6 +195,7 @@ public class TestUtils
qInstance.addReport(defineShapesPersonsReport());
qInstance.addProcess(defineShapesPersonReportProcess());
qInstance.addReport(definePersonJoinShapeReport());
qInstance.addReport(definePersonSimpleReport());
qInstance.addAutomationProvider(definePollingAutomationProvider());
@ -1113,6 +1114,32 @@ public class TestUtils
/*******************************************************************************
**
*******************************************************************************/
private static QReportMetaData definePersonSimpleReport()
{
return new QReportMetaData()
.withName(REPORT_NAME_PERSON_SIMPLE)
.withDataSource(
new QReportDataSource()
.withSourceTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
)
.withView(new QReportView()
.withType(ReportType.TABLE)
.withLabel("Simple Report")
.withColumns(List.of(
new QReportField("id"),
new QReportField("firstName"),
new QReportField("lastName"),
new QReportField("homeStateId").withLabel("Home State Id"),
new QReportField("homeStateName").withSourceFieldName("homeStateId").withShowPossibleValueLabel(true).withLabel("Home State Name")
))
);
}
/*******************************************************************************
**
*******************************************************************************/