Cleanup from code review

This commit is contained in:
2022-11-01 16:12:32 -05:00
parent 165583cd98
commit 683b3c658d
46 changed files with 1662 additions and 165 deletions

View File

@ -26,10 +26,10 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import com.kingsrook.qqq.backend.core.actions.scripts.logging.HeaderAndDetailTableCodeExecutionLogger;
import com.kingsrook.qqq.backend.core.actions.scripts.logging.Log4jCodeExecutionLogger;
import com.kingsrook.qqq.backend.core.actions.scripts.logging.NoopCodeExecutionLogger;
import com.kingsrook.qqq.backend.core.actions.scripts.logging.QCodeExecutionLoggerInterface;
import com.kingsrook.qqq.backend.core.actions.scripts.logging.StoreScriptLogAndScriptLogLineExecutionLogger;
import com.kingsrook.qqq.backend.core.exceptions.QCodeException;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.scripts.ExecuteCodeInput;
@ -120,9 +120,9 @@ class ExecuteCodeActionTest
void testTableLogger() throws QException
{
QInstance qInstance = TestUtils.defineInstance();
new ScriptsMetaDataProvider().defineStandardScriptsTables(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
ExecuteCodeInput executeCodeInput = setupInput(qInstance, Map.of("x", 4), new HeaderAndDetailTableCodeExecutionLogger(1701, 1702));
ExecuteCodeInput executeCodeInput = setupInput(qInstance, Map.of("x", 4), new StoreScriptLogAndScriptLogLineExecutionLogger(1701, 1702));
ExecuteCodeOutput executeCodeOutput = new ExecuteCodeOutput();
new ExecuteCodeAction().run(executeCodeInput, executeCodeOutput);
assertEquals(16, executeCodeOutput.getOutput());

View File

@ -25,11 +25,17 @@ package com.kingsrook.qqq.backend.core.actions.scripts;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
import com.kingsrook.qqq.backend.core.model.actions.scripts.RunAssociatedScriptInput;
import com.kingsrook.qqq.backend.core.model.actions.scripts.RunAssociatedScriptOutput;
import com.kingsrook.qqq.backend.core.model.actions.scripts.StoreAssociatedScriptInput;
import com.kingsrook.qqq.backend.core.model.actions.scripts.StoreAssociatedScriptOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
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.code.AssociatedScriptCodeReference;
@ -56,24 +62,7 @@ class RunAssociatedScriptActionTest
@Test
void test() throws QException
{
QInstance instance = TestUtils.defineInstance();
QTableMetaData table = instance.getTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withField(new QFieldMetaData("testScriptId", QFieldType.INTEGER))
.withAssociatedScript(new AssociatedScript()
.withScriptTypeId(1)
.withFieldName("testScriptId")
);
new ScriptsMetaDataProvider().defineStandardScriptsTables(instance, TestUtils.MEMORY_BACKEND_NAME, null);
TestUtils.insertRecords(instance, table, List.of(
new QRecord().withValue("id", 1),
new QRecord().withValue("id", 2)
));
TestUtils.insertRecords(instance, instance.getTable("scriptType"), List.of(
new QRecord().withValue("id", 1).withValue("name", "Test Script Type")
));
QInstance instance = setupInstance();
insertScript(instance, 1, """
return "Hello";
@ -90,6 +79,9 @@ class RunAssociatedScriptActionTest
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ok - since the core module doesn't have the javascript language support module as a dep, this action will fail - but at least we can confirm it fails with this specific exception! //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QException.class)
.hasRootCauseInstanceOf(ClassNotFoundException.class)
@ -98,6 +90,204 @@ class RunAssociatedScriptActionTest
/*******************************************************************************
**
*******************************************************************************/
private QInstance setupInstance() throws QException
{
QInstance instance = TestUtils.defineInstance();
QTableMetaData table = instance.getTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withField(new QFieldMetaData("testScriptId", QFieldType.INTEGER))
.withAssociatedScript(new AssociatedScript()
.withScriptTypeId(1)
.withFieldName("testScriptId")
);
new ScriptsMetaDataProvider().defineAll(instance, TestUtils.MEMORY_BACKEND_NAME, null);
TestUtils.insertRecords(instance, table, List.of(
new QRecord().withValue("id", 1),
new QRecord().withValue("id", 2)
));
TestUtils.insertRecords(instance, instance.getTable("scriptType"), List.of(
new QRecord().withValue("id", 1).withValue("name", "Test Script Type")
));
return instance;
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testRecordNotFound() throws QException
{
QInstance instance = setupInstance();
RunAssociatedScriptInput runAssociatedScriptInput = new RunAssociatedScriptInput(instance);
runAssociatedScriptInput.setSession(new QSession());
runAssociatedScriptInput.setInputValues(Map.of());
runAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
runAssociatedScriptInput.setCodeReference(new AssociatedScriptCodeReference()
.withRecordTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withRecordPrimaryKey(-9999)
.withFieldName("testScriptId")
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QNotFoundException.class)
.hasMessageMatching("The requested record.*was not found.*");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testNoScriptInRecord() throws QException
{
QInstance instance = setupInstance();
RunAssociatedScriptInput runAssociatedScriptInput = new RunAssociatedScriptInput(instance);
runAssociatedScriptInput.setSession(new QSession());
runAssociatedScriptInput.setInputValues(Map.of());
runAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
runAssociatedScriptInput.setCodeReference(new AssociatedScriptCodeReference()
.withRecordTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withRecordPrimaryKey(1)
.withFieldName("testScriptId")
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QNotFoundException.class)
.hasMessageMatching("The input record.*does not have a script specified for.*");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testBadScriptIdInRecord() throws QException
{
QInstance instance = setupInstance();
UpdateInput updateInput = new UpdateInput(instance);
updateInput.setSession(new QSession());
updateInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
updateInput.setRecords(List.of(new QRecord().withValue("id", 1).withValue("testScriptId", -9998)));
new UpdateAction().execute(updateInput);
RunAssociatedScriptInput runAssociatedScriptInput = new RunAssociatedScriptInput(instance);
runAssociatedScriptInput.setSession(new QSession());
runAssociatedScriptInput.setInputValues(Map.of());
runAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
runAssociatedScriptInput.setCodeReference(new AssociatedScriptCodeReference()
.withRecordTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withRecordPrimaryKey(1)
.withFieldName("testScriptId")
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QNotFoundException.class)
.hasMessageMatching("The script for record .* was not found.*");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testNoCurrentScriptRevisionOnScript() throws QException
{
QInstance instance = setupInstance();
insertScript(instance, 1, """
return "Hello";
""");
GetInput getInput = new GetInput(instance);
getInput.setSession(new QSession());
getInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
getInput.setPrimaryKey(1);
GetOutput getOutput = new GetAction().execute(getInput);
Integer scriptId = getOutput.getRecord().getValueInteger("testScriptId");
UpdateInput updateInput = new UpdateInput(instance);
updateInput.setSession(new QSession());
updateInput.setTableName("script");
updateInput.setRecords(List.of(new QRecord().withValue("id", scriptId).withValue("currentScriptRevisionId", null)));
new UpdateAction().execute(updateInput);
RunAssociatedScriptInput runAssociatedScriptInput = new RunAssociatedScriptInput(instance);
runAssociatedScriptInput.setSession(new QSession());
runAssociatedScriptInput.setInputValues(Map.of());
runAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
runAssociatedScriptInput.setCodeReference(new AssociatedScriptCodeReference()
.withRecordTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withRecordPrimaryKey(1)
.withFieldName("testScriptId")
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QNotFoundException.class)
.hasMessageMatching("The script for record .* does not have a current version.*");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testBadCurrentScriptRevisionOnScript() throws QException
{
QInstance instance = setupInstance();
insertScript(instance, 1, """
return "Hello";
""");
GetInput getInput = new GetInput(instance);
getInput.setSession(new QSession());
getInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
getInput.setPrimaryKey(1);
GetOutput getOutput = new GetAction().execute(getInput);
Integer scriptId = getOutput.getRecord().getValueInteger("testScriptId");
UpdateInput updateInput = new UpdateInput(instance);
updateInput.setSession(new QSession());
updateInput.setTableName("script");
updateInput.setRecords(List.of(new QRecord().withValue("id", scriptId).withValue("currentScriptRevisionId", 9997)));
new UpdateAction().execute(updateInput);
RunAssociatedScriptInput runAssociatedScriptInput = new RunAssociatedScriptInput(instance);
runAssociatedScriptInput.setSession(new QSession());
runAssociatedScriptInput.setInputValues(Map.of());
runAssociatedScriptInput.setTableName(TestUtils.TABLE_NAME_PERSON_MEMORY);
runAssociatedScriptInput.setCodeReference(new AssociatedScriptCodeReference()
.withRecordTable(TestUtils.TABLE_NAME_PERSON_MEMORY)
.withRecordPrimaryKey(1)
.withFieldName("testScriptId")
);
RunAssociatedScriptOutput runAssociatedScriptOutput = new RunAssociatedScriptOutput();
assertThatThrownBy(() -> new RunAssociatedScriptAction().run(runAssociatedScriptInput, runAssociatedScriptOutput))
.isInstanceOf(QNotFoundException.class)
.hasMessageMatching("The current revision of the script for record .* was not found.*");
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -24,15 +24,12 @@ package com.kingsrook.qqq.backend.core.actions.scripts;
import java.io.Serializable;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.scripts.StoreAssociatedScriptInput;
import com.kingsrook.qqq.backend.core.model.actions.scripts.StoreAssociatedScriptOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
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.QueryOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput;
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;
@ -47,6 +44,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/*******************************************************************************
@ -85,7 +83,7 @@ class StoreAssociatedScriptActionTest
.withFieldName("otherScriptId")
);
new ScriptsMetaDataProvider().defineStandardScriptsTables(instance, TestUtils.MEMORY_BACKEND_NAME, null);
new ScriptsMetaDataProvider().defineAll(instance, TestUtils.MEMORY_BACKEND_NAME, null);
TestUtils.insertRecords(instance, table, List.of(
new QRecord().withValue("id", 1),
@ -149,7 +147,6 @@ class StoreAssociatedScriptActionTest
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "testScriptId", 1);
assertValueInField(instance, TestUtils.TABLE_NAME_PERSON_MEMORY, 1, "otherScriptId", 3);
assertValueInField(instance, "script", 3, "currentScriptRevisionId", 4);
}
@ -157,16 +154,19 @@ class StoreAssociatedScriptActionTest
/*******************************************************************************
**
*******************************************************************************/
private Serializable assertValueInField(QInstance instance, String tableName, Serializable recordId, String fieldName, Serializable value) throws QException
private void assertValueInField(QInstance instance, String tableName, Serializable recordId, String fieldName, Serializable value) throws QException
{
QueryInput queryInput = new QueryInput(instance);
queryInput.setSession(new QSession());
queryInput.setTableName(tableName);
queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria("id", QCriteriaOperator.EQUALS, List.of(recordId))));
QueryOutput queryOutput = new QueryAction().execute(queryInput);
Serializable actual = queryOutput.getRecords().get(0).getValue(fieldName);
assertEquals(value, actual);
return (actual);
GetInput getInput = new GetInput(instance);
getInput.setSession(new QSession());
getInput.setTableName(tableName);
getInput.setPrimaryKey(recordId);
GetOutput getOutput = new GetAction().execute(getInput);
if(getOutput.getRecord() == null)
{
fail("Expected value [" + value + "] in field [" + fieldName + "], record [" + tableName + "][" + recordId + "], but the record wasn't found...");
}
Serializable actual = getOutput.getRecord().getValue(fieldName);
assertEquals(value, actual, "Expected value in field [" + fieldName + "], record [" + tableName + "][" + recordId + "]");
}
}

View File

@ -27,6 +27,7 @@ import com.kingsrook.qqq.backend.core.model.actions.scripts.TestScriptInput;
import com.kingsrook.qqq.backend.core.model.actions.scripts.TestScriptOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -39,6 +40,7 @@ class TestScriptActionTest
**
*******************************************************************************/
@Test
@Disabled("Not yet done.")
void test() throws QException
{
QInstance instance = TestUtils.defineInstance();

View File

@ -0,0 +1,85 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.actions.scripts.logging;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.scripts.ExecuteCodeInput;
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.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/*******************************************************************************
** Unit test for BuildScriptLogAndScriptLogLineExecutionLogger
*******************************************************************************/
class BuildScriptLogAndScriptLogLineExecutionLoggerTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
QInstance instance = TestUtils.defineInstance();
new ScriptsMetaDataProvider().defineAll(instance, TestUtils.MEMORY_BACKEND_NAME, null);
ExecuteCodeInput executeCodeInput = new ExecuteCodeInput(instance);
executeCodeInput.setSession(new QSession());
executeCodeInput.setInput(Map.of("a", 1));
BuildScriptLogAndScriptLogLineExecutionLogger logger = new BuildScriptLogAndScriptLogLineExecutionLogger(9999, 8888);
logger.acceptExecutionStart(executeCodeInput);
logger.acceptLogLine("This is a log");
logger.acceptLogLine("This is also a log");
logger.acceptExecutionEnd(true);
QRecord scriptLog = logger.getScriptLog();
assertNull(scriptLog.getValueInteger("id"));
assertNotNull(scriptLog.getValue("startTimestamp"));
assertNotNull(scriptLog.getValue("endTimestamp"));
assertNotNull(scriptLog.getValue("runTimeMillis"));
assertEquals(9999, scriptLog.getValueInteger("scriptId"));
assertEquals(8888, scriptLog.getValueInteger("scriptRevisionId"));
assertEquals("{a=1}", scriptLog.getValueString("input"));
assertEquals("true", scriptLog.getValueString("output"));
assertNull(scriptLog.getValueString("exception"));
assertFalse(scriptLog.getValueBoolean("hadError"));
List<QRecord> scriptLogLineRecords = logger.getScriptLogLines();
assertEquals(2, scriptLogLineRecords.size());
QRecord scriptLogLine = scriptLogLineRecords.get(0);
assertNull(scriptLogLine.getValueInteger("scriptLogId"));
assertNotNull(scriptLogLine.getValue("timestamp"));
assertEquals("This is a log", scriptLogLine.getValueString("text"));
scriptLogLine = scriptLogLineRecords.get(1);
assertEquals("This is also a log", scriptLogLine.getValueString("text"));
}
}

View File

@ -0,0 +1,103 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.actions.scripts.logging;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.scripts.ExecuteCodeInput;
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.ScriptsMetaDataProvider;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
/*******************************************************************************
** Unit test for StoreScriptLogAndScriptLogLineExecutionLogger
*******************************************************************************/
class StoreScriptLogAndScriptLogLineExecutionLoggerTest
{
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
@AfterEach
void beforeAndAfterEach()
{
MemoryRecordStore.getInstance().reset();
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
QInstance instance = TestUtils.defineInstance();
new ScriptsMetaDataProvider().defineAll(instance, TestUtils.MEMORY_BACKEND_NAME, null);
ExecuteCodeInput executeCodeInput = new ExecuteCodeInput(instance);
executeCodeInput.setSession(new QSession());
executeCodeInput.setInput(Map.of("a", 1));
StoreScriptLogAndScriptLogLineExecutionLogger logger = new StoreScriptLogAndScriptLogLineExecutionLogger(9999, 8888);
logger.acceptExecutionStart(executeCodeInput);
logger.acceptLogLine("This is a log");
logger.acceptLogLine("This is also a log");
logger.acceptExecutionEnd(true);
List<QRecord> scriptLogRecords = TestUtils.queryTable(instance, "scriptLog");
assertEquals(1, scriptLogRecords.size());
QRecord scriptLog = scriptLogRecords.get(0);
assertNotNull(scriptLog.getValueInteger("id"));
assertNotNull(scriptLog.getValue("startTimestamp"));
assertNotNull(scriptLog.getValue("endTimestamp"));
assertNotNull(scriptLog.getValue("runTimeMillis"));
assertEquals(9999, scriptLog.getValueInteger("scriptId"));
assertEquals(8888, scriptLog.getValueInteger("scriptRevisionId"));
assertEquals("{a=1}", scriptLog.getValueString("input"));
assertEquals("true", scriptLog.getValueString("output"));
assertNull(scriptLog.getValueString("exception"));
assertFalse(scriptLog.getValueBoolean("hadError"));
List<QRecord> scriptLogLineRecords = TestUtils.queryTable(instance, "scriptLogLine");
assertEquals(2, scriptLogLineRecords.size());
QRecord scriptLogLine = scriptLogLineRecords.get(0);
assertEquals(scriptLog.getValueInteger("id"), scriptLogLine.getValueInteger("scriptLogId"));
assertNotNull(scriptLogLine.getValue("timestamp"));
assertEquals("This is a log", scriptLogLine.getValueString("text"));
scriptLogLine = scriptLogLineRecords.get(1);
assertEquals("This is also a log", scriptLogLine.getValueString("text"));
}
}

View File

@ -51,6 +51,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppSection;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.queues.SQSQueueProviderMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
@ -805,6 +806,7 @@ class QInstanceValidatorTest
possibleValueSource.setOrderByFields(List.of(new QFilterOrderBy("id")));
possibleValueSource.setCustomCodeReference(new QCodeReference());
possibleValueSource.setEnumValues(null);
possibleValueSource.setType(QPossibleValueSourceType.ENUM);
},
"should not have a tableName",
"should not have searchFields",
@ -831,6 +833,7 @@ class QInstanceValidatorTest
possibleValueSource.setOrderByFields(new ArrayList<>());
possibleValueSource.setCustomCodeReference(new QCodeReference());
possibleValueSource.setEnumValues(List.of(new QPossibleValue<>("test")));
possibleValueSource.setType(QPossibleValueSourceType.TABLE);
},
"should not have enum values",
"should not have a customCodeReference",
@ -860,6 +863,7 @@ class QInstanceValidatorTest
possibleValueSource.setOrderByFields(List.of(new QFilterOrderBy("id")));
possibleValueSource.setCustomCodeReference(null);
possibleValueSource.setEnumValues(List.of(new QPossibleValue<>("test")));
possibleValueSource.setType(QPossibleValueSourceType.CUSTOM);
},
"should not have enum values",
"should not have a tableName",