Implementation of QContext everywhere, instead of passing QInstance and QSession in all ActionInputs

This commit is contained in:
2023-01-15 19:30:57 -06:00
parent 69a6104393
commit d3fa1df56f
219 changed files with 1955 additions and 1581 deletions

View File

@ -0,0 +1,60 @@
/*
* Copyright © 2022-2023. Nutrifresh Services <contact@nutrifreshservices.com>. All Rights Reserved.
*/
package com.kingsrook.qqq.languages.javascript;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
/*******************************************************************************
**
*******************************************************************************/
public class BaseTest
{
private static final Logger LOG = LogManager.getLogger(BaseTest.class);
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
void baseBeforeEach()
{
QContext.init(TestUtils.defineInstance(), new QSession());
}
/*******************************************************************************
**
*******************************************************************************/
@AfterEach
void baseAfterEach()
{
QContext.clear();
}
/*******************************************************************************
**
*******************************************************************************/
protected static void reInitInstanceInContext(QInstance qInstance)
{
if(qInstance.equals(QContext.getQInstance()))
{
LOG.warn("Unexpected condition - the same qInstance that is already in the QContext was passed into reInit. You probably want a new QInstance object instance.");
}
QContext.init(qInstance, new QSession());
}
}

View File

@ -32,7 +32,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@ -44,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
** Unit test for ExecuteCodeAction
*******************************************************************************/
class ExecuteCodeActionTest
class ExecuteCodeActionTest extends BaseTest
{
/*******************************************************************************
@ -53,7 +52,7 @@ class ExecuteCodeActionTest
@Test
void testHelloWorld() throws QException
{
ExecuteCodeInput input = new ExecuteCodeInput(TestUtils.defineInstance())
ExecuteCodeInput input = new ExecuteCodeInput()
.withCodeReference(new QCodeReference("helloWorld.js", QCodeType.JAVA_SCRIPT, QCodeUsage.CUSTOMIZER)
.withInlineCode("""
return "Hello, " + input"""))
@ -256,8 +255,7 @@ class ExecuteCodeActionTest
TestOutput testOutput = new TestOutput();
ExecuteCodeInput input = new ExecuteCodeInput(instance);
input.setSession(new QSession());
ExecuteCodeInput input = new ExecuteCodeInput();
input.setCodeReference(new QCodeReference("test.js", QCodeType.JAVA_SCRIPT, QCodeUsage.CUSTOMIZER).withInlineCode(code));
input.withContext("input", testInput);
input.withContext("output", testOutput);