Improving query test coverage

This commit is contained in:
2022-08-23 11:15:43 -05:00
parent b9d498b57e
commit ffec68b3ef
3 changed files with 71 additions and 24 deletions

View File

@ -22,6 +22,8 @@
package com.kingsrook.qqq.backend.core.actions.tables;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
@ -76,4 +78,50 @@ class QueryActionTest
assertThat(record.getDisplayValues()).isNotEmpty();
}
}
/*******************************************************************************
** Test running with a recordPipe - using the shape table, which uses the memory
** backend, which is known to do an addAll to the query output.
**
*******************************************************************************/
@Test
public void testRecordPipeShapeTable() throws QException
{
TestUtils.insertDefaultShapes(TestUtils.defineInstance());
RecordPipe pipe = new RecordPipe();
QueryInput queryInput = new QueryInput(TestUtils.defineInstance());
queryInput.setSession(TestUtils.getMockSession());
queryInput.setTableName(TestUtils.TABLE_NAME_SHAPE);
queryInput.setRecordPipe(pipe);
QueryOutput queryOutput = new QueryAction().execute(queryInput);
assertNotNull(queryOutput);
List<QRecord> records = pipe.consumeAvailableRecords();
assertThat(records).isNotEmpty();
}
/*******************************************************************************
** Test running with a recordPipe - using the person table, which uses the mock
** backend, which is known to do a single-add (not addAll) to the query output.
**
*******************************************************************************/
@Test
public void testRecordPipePersonTable() throws QException
{
RecordPipe pipe = new RecordPipe();
QueryInput queryInput = new QueryInput(TestUtils.defineInstance());
queryInput.setSession(TestUtils.getMockSession());
queryInput.setTableName(TestUtils.TABLE_NAME_PERSON);
queryInput.setRecordPipe(pipe);
QueryOutput queryOutput = new QueryAction().execute(queryInput);
assertNotNull(queryOutput);
List<QRecord> records = pipe.consumeAvailableRecords();
assertThat(records).isNotEmpty();
}
}

View File

@ -25,9 +25,7 @@ package com.kingsrook.qqq.backend.core.actions.values;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
@ -135,16 +133,7 @@ public class QPossibleValueTranslatorTest
QFieldMetaData shapeField = qInstance.getTable(TestUtils.TABLE_NAME_PERSON).getField("favoriteShapeId");
QPossibleValueSource possibleValueSource = qInstance.getPossibleValueSource(shapeField.getPossibleValueSourceName());
List<QRecord> shapeRecords = List.of(
new QRecord().withTableName(shapeTable.getName()).withValue("id", 1).withValue("name", "Triangle"),
new QRecord().withTableName(shapeTable.getName()).withValue("id", 2).withValue("name", "Square"),
new QRecord().withTableName(shapeTable.getName()).withValue("id", 3).withValue("name", "Circle"));
InsertInput insertInput = new InsertInput(qInstance);
insertInput.setSession(new QSession());
insertInput.setTableName(shapeTable.getName());
insertInput.setRecords(shapeRecords);
new InsertAction().execute(insertInput);
TestUtils.insertDefaultShapes(qInstance);
//////////////////////////////////////////////////////////////////////////
// assert the default formatting for a not-found value is a null string //
@ -235,18 +224,7 @@ public class QPossibleValueTranslatorTest
.withPossibleValueSourceName("shapeV2")
);
///////////////////////////////
// insert the list of shapes //
///////////////////////////////
List<QRecord> shapeRecords = List.of(
new QRecord().withTableName(shapeTable.getName()).withValue("id", 1).withValue("name", "Triangle"),
new QRecord().withTableName(shapeTable.getName()).withValue("id", 2).withValue("name", "Square"),
new QRecord().withTableName(shapeTable.getName()).withValue("id", 3).withValue("name", "Circle"));
InsertInput insertInput = new InsertInput(qInstance);
insertInput.setSession(new QSession());
insertInput.setTableName(shapeTable.getName());
insertInput.setRecords(shapeRecords);
new InsertAction().execute(insertInput);
TestUtils.insertDefaultShapes(qInstance);
///////////////////////////////////////////////////////
// define a list of persons pointing at those shapes //

View File

@ -26,9 +26,11 @@ import java.io.Serializable;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.processes.person.addtopeoplesage.AddAge;
import com.kingsrook.qqq.backend.core.actions.processes.person.addtopeoplesage.GetAgeStatistics;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
@ -447,6 +449,25 @@ public class TestUtils
/*******************************************************************************
**
*******************************************************************************/
public static void insertDefaultShapes(QInstance qInstance) throws QException
{
List<QRecord> shapeRecords = List.of(
new QRecord().withTableName(TABLE_NAME_SHAPE).withValue("id", 1).withValue("name", "Triangle"),
new QRecord().withTableName(TABLE_NAME_SHAPE).withValue("id", 2).withValue("name", "Square"),
new QRecord().withTableName(TABLE_NAME_SHAPE).withValue("id", 3).withValue("name", "Circle"));
InsertInput insertInput = new InsertInput(qInstance);
insertInput.setSession(new QSession());
insertInput.setTableName(TABLE_NAME_SHAPE);
insertInput.setRecords(shapeRecords);
new InsertAction().execute(insertInput);
}
/*******************************************************************************
**
*******************************************************************************/