mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-21 06:28:44 +00:00
passing tests w/ scriptId everywhere
This commit is contained in:
@ -47,6 +47,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.Script;
|
||||
import com.kingsrook.qqq.backend.core.model.tables.QQQTableAccessor;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
@ -83,7 +84,7 @@ public class RecordScriptTestInterface implements TestScriptActionInterface
|
||||
//////////////////////////////////////////////
|
||||
// look up the records being tested against //
|
||||
//////////////////////////////////////////////
|
||||
String tableName = script.getValueString("tableName");
|
||||
String tableName = QQQTableAccessor.getQQQTableName(script.getValueInteger("qqqTableId"));
|
||||
QTableMetaData table = QContext.getQInstance().getTable(tableName);
|
||||
if(table == null)
|
||||
{
|
||||
|
@ -37,7 +37,9 @@ import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** One-liner we can use to get a QQQTable record, or just its id (which we often want).
|
||||
** Will insert the record if it wasn't already there.
|
||||
** Also uses in-memory cache table, so rather cheap for normal use-case.
|
||||
*******************************************************************************/
|
||||
public class QQQTableAccessor
|
||||
{
|
||||
@ -80,6 +82,40 @@ public class QQQTableAccessor
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static QRecord getQQQTableRecord(Integer id) throws QException
|
||||
{
|
||||
/////////////////////////////
|
||||
// look in the cache table //
|
||||
/////////////////////////////
|
||||
GetInput getInput = new GetInput();
|
||||
getInput.setTableName(QQQTablesMetaDataProvider.QQQ_TABLE_CACHE_TABLE_NAME);
|
||||
getInput.setPrimaryKey(id);
|
||||
GetOutput getOutput = new GetAction().execute(getInput);
|
||||
|
||||
////////////////////////
|
||||
// upon cache miss... //
|
||||
////////////////////////
|
||||
if(getOutput.getRecord() == null)
|
||||
{
|
||||
GetInput sourceGetInput = new GetInput();
|
||||
sourceGetInput.setTableName(QQQTable.TABLE_NAME);
|
||||
sourceGetInput.setPrimaryKey(id);
|
||||
GetOutput sourceGetOutput = new GetAction().execute(sourceGetInput);
|
||||
|
||||
///////////////////////////////////
|
||||
// repeat the get from the cache //
|
||||
///////////////////////////////////
|
||||
getOutput = new GetAction().execute(sourceGetInput);
|
||||
}
|
||||
|
||||
return getOutput.getRecord();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -88,4 +124,14 @@ public class QQQTableAccessor
|
||||
return (getQQQTableRecord(tableName).getValueInteger("id"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static String getQQQTableName(Integer id) throws QException
|
||||
{
|
||||
return (getQQQTableRecord(id).getValueString("name"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
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.savedfilters.SavedFiltersMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.tables.QQQTablesMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -56,6 +57,8 @@ class SavedFilterProcessTests extends BaseTest
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
new SavedFiltersMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
new QQQTablesMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
String tableName = TestUtils.TABLE_NAME_PERSON_MEMORY;
|
||||
|
||||
{
|
||||
|
@ -35,6 +35,7 @@ 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.scripts.Script;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.tables.QQQTablesMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -55,6 +56,7 @@ class RunRecordScriptTest extends BaseTest
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
new QQQTablesMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
TestUtils.insertRecords(qInstance, qInstance.getTable(TestUtils.TABLE_NAME_PERSON_MEMORY), List.of(new QRecord().withValue("id", 1)));
|
||||
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", 1).withTableName(TestUtils.TABLE_NAME_PERSON_MEMORY)));
|
||||
|
@ -37,6 +37,8 @@ import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.Script;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptType;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.tables.QQQTableAccessor;
|
||||
import com.kingsrook.qqq.backend.core.model.tables.QQQTablesMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -58,6 +60,8 @@ class TestScriptProcessStepTest extends BaseTest
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
new QQQTablesMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
InsertInput insertInput = new InsertInput();
|
||||
insertInput.setTableName(ScriptType.TABLE_NAME);
|
||||
insertInput.setRecords(List.of(new ScriptType()
|
||||
@ -71,7 +75,7 @@ class TestScriptProcessStepTest extends BaseTest
|
||||
insertInput.setRecords(List.of(new Script()
|
||||
.withName("TestScript")
|
||||
.withScriptTypeId(insertOutput.getRecords().get(0).getValueInteger("id"))
|
||||
.withQqqTableId(1)
|
||||
.withQqqTableId(QQQTableAccessor.getQQQTableId(TestUtils.TABLE_NAME_SHAPE))
|
||||
.toQRecord()));
|
||||
insertOutput = new InsertAction().execute(insertInput);
|
||||
|
||||
@ -89,7 +93,10 @@ class TestScriptProcessStepTest extends BaseTest
|
||||
// expect an error because the javascript module isn't available //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
assertNotNull(output.getValue("exception"));
|
||||
assertThat((Exception) output.getValue("exception")).hasRootCauseInstanceOf(ClassNotFoundException.class);
|
||||
assertThat((Exception) output.getValue("exception"))
|
||||
.hasRootCauseInstanceOf(ClassNotFoundException.class)
|
||||
.rootCause()
|
||||
.hasMessageContaining("QJavaScriptExecutor");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user