From ed22ab59172e206c031002fac8b81a694194e347 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 27 Jun 2023 08:45:46 -0500 Subject: [PATCH] More test coverage on new script processes --- .../scripts/TestScriptProcessStep.java | 5 + .../LoadScriptTestDetailsProcessStepTest.java | 81 ++++++++++++++++ .../scripts/TestScriptProcessStepTest.java | 92 +++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/LoadScriptTestDetailsProcessStepTest.java create mode 100644 qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStepTest.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java index f66c1278..63eebac8 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStep.java @@ -129,6 +129,11 @@ public class TestScriptProcessStep implements BackendStep output.addValue("scriptLogLines", new ArrayList<>(executionLogger.getScriptLogLines())); output.addValue("outputObject", testScriptOutput.getOutputObject()); + + if(testScriptOutput.getException() != null) + { + output.addValue("exception", testScriptOutput.getException()); + } } catch(Exception e) { diff --git a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/LoadScriptTestDetailsProcessStepTest.java b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/LoadScriptTestDetailsProcessStepTest.java new file mode 100644 index 00000000..9e1be9bd --- /dev/null +++ b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/LoadScriptTestDetailsProcessStepTest.java @@ -0,0 +1,81 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. 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 . + */ + +package com.kingsrook.qqq.backend.core.processes.implementations.scripts; + + +import java.io.Serializable; +import java.util.List; +import com.kingsrook.qqq.backend.core.BaseTest; +import com.kingsrook.qqq.backend.core.actions.scripts.RecordScriptTestInterface; +import com.kingsrook.qqq.backend.core.actions.tables.InsertAction; +import com.kingsrook.qqq.backend.core.context.QContext; +import com.kingsrook.qqq.backend.core.exceptions.QException; +import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput; +import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput; +import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput; +import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput; +import com.kingsrook.qqq.backend.core.model.metadata.QInstance; +import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData; +import com.kingsrook.qqq.backend.core.model.scripts.ScriptType; +import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider; +import com.kingsrook.qqq.backend.core.utils.TestUtils; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + + +/******************************************************************************* + ** Unit test for LoadScriptTestDetailsProcessStep + *******************************************************************************/ +class LoadScriptTestDetailsProcessStepTest extends BaseTest +{ + + + /******************************************************************************* + ** + *******************************************************************************/ + @Test + void test() throws QException + { + QInstance qInstance = QContext.getQInstance(); + new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null); + InsertInput insertInput = new InsertInput(); + insertInput.setTableName(ScriptType.TABLE_NAME); + insertInput.setRecords(List.of(new ScriptType() + .withName("TestScriptType") + .withTestScriptInterfaceName(RecordScriptTestInterface.class.getName()) + .toQRecord())); + InsertOutput insertOutput = new InsertAction().execute(insertInput); + + RunBackendStepInput input = new RunBackendStepInput(); + input.addValue("scriptTypeId", insertOutput.getRecords().get(0).getValueInteger("id")); + RunBackendStepOutput output = new RunBackendStepOutput(); + new LoadScriptTestDetailsProcessStep().run(input, output); + + Serializable inputFields = output.getValue("testInputFields"); + assertThat(inputFields).isInstanceOf(List.class); + List inputFieldsList = (List) inputFields; + assertEquals(1, inputFieldsList.size()); + assertEquals("recordPrimaryKeyList", inputFieldsList.get(0).getName()); + } + +} \ No newline at end of file diff --git a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStepTest.java b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStepTest.java new file mode 100644 index 00000000..25e1680a --- /dev/null +++ b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/processes/implementations/scripts/TestScriptProcessStepTest.java @@ -0,0 +1,92 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. 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 . + */ + +package com.kingsrook.qqq.backend.core.processes.implementations.scripts; + + +import java.util.ArrayList; +import java.util.List; +import com.kingsrook.qqq.backend.core.BaseTest; +import com.kingsrook.qqq.backend.core.actions.scripts.RecordScriptTestInterface; +import com.kingsrook.qqq.backend.core.actions.tables.InsertAction; +import com.kingsrook.qqq.backend.core.context.QContext; +import com.kingsrook.qqq.backend.core.exceptions.QException; +import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput; +import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput; +import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput; +import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput; +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.utils.TestUtils; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; + + +/******************************************************************************* + ** Unit test for TestScriptProcessStep + *******************************************************************************/ +class TestScriptProcessStepTest extends BaseTest +{ + + + /******************************************************************************* + ** + *******************************************************************************/ + @Test + void test() throws QException + { + QInstance qInstance = QContext.getQInstance(); + new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null); + InsertInput insertInput = new InsertInput(); + insertInput.setTableName(ScriptType.TABLE_NAME); + insertInput.setRecords(List.of(new ScriptType() + .withName("TestScriptType") + .withTestScriptInterfaceName(RecordScriptTestInterface.class.getName()) + .toQRecord())); + InsertOutput insertOutput = new InsertAction().execute(insertInput); + + insertInput = new InsertInput(); + insertInput.setTableName(Script.TABLE_NAME); + insertInput.setRecords(List.of(new Script() + .withName("TestScript") + .withScriptTypeId(insertOutput.getRecords().get(0).getValueInteger("id")) + .toQRecord())); + insertOutput = new InsertAction().execute(insertInput); + + RunBackendStepInput input = new RunBackendStepInput(); + input.addValue("scriptId", insertOutput.getRecords().get(0).getValueInteger("id")); + input.addValue("fileNames", new ArrayList<>(List.of("script.js"))); + input.addValue("fileContents:script.js", "logger.log('oh my.')"); + + RunBackendStepOutput output = new RunBackendStepOutput(); + new TestScriptProcessStep().run(input, output); + + ////////////////////////////////////////////////////////////////// + // expect an error because the javascript module isn't available // + ////////////////////////////////////////////////////////////////// + assertNotNull(output.getValue("exception")); + assertThat((Exception) output.getValue("exception")).hasRootCauseInstanceOf(ClassNotFoundException.class); + } + +} \ No newline at end of file