mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
Adding scriptType fileModes, with multi-files under a script Revision.
This commit is contained in:
@ -30,10 +30,10 @@ import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.templates.ConvertHtmlToPdfInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.ConvertHtmlToPdfInput;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateInput;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.TemplateType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -25,8 +25,8 @@ package com.kingsrook.qqq.backend.core.actions.templates;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateInput;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.RenderTemplateOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.templates.RenderTemplateOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.templates.TemplateType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -119,6 +119,29 @@ class QRecordEntityTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testQRecordFromJoinToItem() throws QException
|
||||
{
|
||||
QRecord qRecord = new QRecord()
|
||||
.withValue("item.sku", "WXYZ-9876")
|
||||
.withValue("item.description", "Items are cool")
|
||||
.withValue("item.quantity", 42)
|
||||
.withValue("item.price", new BigDecimal("3.50"))
|
||||
.withValue("item.featured", false);
|
||||
|
||||
Item item = QRecordEntity.fromQRecord(Item.class, qRecord, "item.");
|
||||
assertEquals("WXYZ-9876", item.getSku());
|
||||
assertEquals("Items are cool", item.getDescription());
|
||||
assertEquals(42, item.getQuantity());
|
||||
assertEquals(new BigDecimal("3.50"), item.getPrice());
|
||||
assertFalse(item.getFeatured());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -22,6 +22,7 @@
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.scripts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
@ -33,10 +34,12 @@ 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.ScriptRevision;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptRevisionFile;
|
||||
import com.kingsrook.qqq.backend.core.model.scripts.ScriptsMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
@ -51,7 +54,7 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws QException
|
||||
void testSingleFileScriptType() throws QException
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
@ -59,7 +62,7 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
|
||||
Integer scriptId = 1701;
|
||||
String scriptContents = "logger.log('Hi');";
|
||||
|
||||
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", 1701)));
|
||||
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", scriptId)));
|
||||
List<QRecord> scripts = TestUtils.queryTable(Script.TABLE_NAME);
|
||||
assertNull(scripts.get(0).getValueInteger("currentScriptRevisionId"));
|
||||
|
||||
@ -73,7 +76,7 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
|
||||
|
||||
List<QRecord> scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME);
|
||||
QRecord scriptRevision = scriptRevisions.get(0);
|
||||
assertEquals(1701, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(1, scriptRevision.getValueInteger("sequenceNo"));
|
||||
assertEquals("Initial version", scriptRevision.getValueString("commitMessage"));
|
||||
assertEquals(scriptContents, scriptRevision.getValueString("contents"));
|
||||
@ -88,10 +91,94 @@ class StoreScriptRevisionProcessStepTest extends BaseTest
|
||||
|
||||
scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME).stream().filter(r -> r.getValueInteger("id").equals(2)).collect(Collectors.toList());
|
||||
scriptRevision = scriptRevisions.get(0);
|
||||
assertEquals(1701, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(2, scriptRevision.getValueInteger("sequenceNo"));
|
||||
assertEquals("No commit message given", scriptRevision.getValueString("commitMessage"));
|
||||
assertEquals(scriptContents, scriptRevision.getValueString("contents"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testMultiFileScriptType() throws QException
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
new ScriptsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||
|
||||
Integer scriptId = 1701;
|
||||
String scriptContents = "logger.log('Hi');";
|
||||
String templateContents = "<h1>Hey</h1>";
|
||||
|
||||
TestUtils.insertRecords(qInstance, qInstance.getTable(Script.TABLE_NAME), List.of(new QRecord().withValue("id", scriptId)));
|
||||
List<QRecord> scripts = TestUtils.queryTable(Script.TABLE_NAME);
|
||||
assertNull(scripts.get(0).getValueInteger("currentScriptRevisionId"));
|
||||
|
||||
ArrayList<QRecord> fileContents = new ArrayList<>();
|
||||
fileContents.add(new QRecord().withValue("fileName", "script").withValue("contents", scriptContents));
|
||||
fileContents.add(new QRecord().withValue("fileName", "template").withValue("contents", templateContents));
|
||||
|
||||
RunBackendStepInput runBackendStepInput = new RunBackendStepInput();
|
||||
runBackendStepInput.addValue("scriptId", scriptId);
|
||||
runBackendStepInput.addValue("fileContents", fileContents);
|
||||
new StoreScriptRevisionProcessStep().run(runBackendStepInput, new RunBackendStepOutput());
|
||||
|
||||
scripts = TestUtils.queryTable(Script.TABLE_NAME);
|
||||
assertEquals(1, scripts.get(0).getValueInteger("currentScriptRevisionId"));
|
||||
|
||||
List<QRecord> scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME);
|
||||
QRecord scriptRevision = scriptRevisions.get(0);
|
||||
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(1, scriptRevision.getValueInteger("sequenceNo"));
|
||||
assertEquals("Initial version", scriptRevision.getValueString("commitMessage"));
|
||||
assertNull(scriptRevision.getValueString("contents"));
|
||||
|
||||
List<QRecord> scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
|
||||
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("script")).findFirst())
|
||||
.isPresent().get()
|
||||
.matches(r -> r.getValueString("contents").equals(scriptContents));
|
||||
|
||||
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("template")).findFirst())
|
||||
.isPresent().get()
|
||||
.matches(r -> r.getValueString("contents").equals(templateContents));
|
||||
|
||||
////////////////////////////
|
||||
// now add a new revision //
|
||||
////////////////////////////
|
||||
String updatedScriptContents = "logger.log('Really, Hi');";
|
||||
String updatedTemplateContents = "<h1>Hey, what's up</h1>";
|
||||
|
||||
fileContents = new ArrayList<>();
|
||||
fileContents.add(new QRecord().withValue("fileName", "script").withValue("contents", updatedScriptContents));
|
||||
fileContents.add(new QRecord().withValue("fileName", "template").withValue("contents", updatedTemplateContents));
|
||||
|
||||
runBackendStepInput = new RunBackendStepInput();
|
||||
runBackendStepInput.addValue("scriptId", scriptId);
|
||||
runBackendStepInput.addValue("fileContents", fileContents);
|
||||
runBackendStepInput.addValue("commitMessage", "Updated files");
|
||||
new StoreScriptRevisionProcessStep().run(runBackendStepInput, new RunBackendStepOutput());
|
||||
|
||||
scripts = TestUtils.queryTable(Script.TABLE_NAME);
|
||||
assertEquals(2, scripts.get(0).getValueInteger("currentScriptRevisionId"));
|
||||
|
||||
scriptRevisions = TestUtils.queryTable(ScriptRevision.TABLE_NAME).stream().filter(r -> r.getValueInteger("id").equals(2)).collect(Collectors.toList());
|
||||
scriptRevision = scriptRevisions.get(0);
|
||||
assertEquals(scriptId, scriptRevision.getValueInteger("scriptId"));
|
||||
assertEquals(2, scriptRevision.getValueInteger("id"));
|
||||
assertEquals(2, scriptRevision.getValueInteger("sequenceNo"));
|
||||
assertEquals("Updated files", scriptRevision.getValueString("commitMessage"));
|
||||
assertNull(scriptRevision.getValueString("contents"));
|
||||
|
||||
scriptRevisionFiles = TestUtils.queryTable(ScriptRevisionFile.TABLE_NAME);
|
||||
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("script") && srf.getValueInteger("scriptRevisionId").equals(2)).findFirst())
|
||||
.isPresent().get()
|
||||
.matches(r -> r.getValueString("contents").equals(updatedScriptContents));
|
||||
|
||||
assertThat(scriptRevisionFiles.stream().filter(srf -> srf.getValueString("fileName").equals("template") && srf.getValueInteger("scriptRevisionId").equals(2)).findFirst())
|
||||
.isPresent().get()
|
||||
.matches(r -> r.getValueString("contents").equals(updatedTemplateContents));
|
||||
}
|
||||
|
||||
}
|
@ -25,15 +25,21 @@ package com.kingsrook.qqq.backend.core.utils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ -544,4 +550,44 @@ class CollectionUtilsTest extends BaseTest
|
||||
assertEquals(List.of(1, 2, 3), CollectionUtils.mergeLists(null, List.of(1, 2, 3), null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testUseOrWrap()
|
||||
{
|
||||
{
|
||||
List<String> originalList = new ArrayList<>(List.of("A", "B", "C"));
|
||||
ArrayList<String> reallyArrayList = CollectionUtils.useOrWrap(originalList, new TypeToken<>() {});
|
||||
assertSame(originalList, reallyArrayList);
|
||||
}
|
||||
|
||||
{
|
||||
List<String> originalList = new LinkedList<>(List.of("A", "B", "C"));
|
||||
ArrayList<String> reallyArrayList = CollectionUtils.useOrWrap(originalList, new TypeToken<>() {});
|
||||
assertNotSame(originalList, reallyArrayList);
|
||||
assertEquals(ArrayList.class, reallyArrayList.getClass());
|
||||
}
|
||||
|
||||
assertEquals(ArrayList.class, CollectionUtils.useOrWrap(new LinkedList<>(), TypeToken.get(ArrayList.class)).getClass());
|
||||
|
||||
{
|
||||
Map<String, Integer> originalMap = new HashMap<>(Map.of("A", 1, "B", 2));
|
||||
HashMap<String, Integer> reallyHashMap = CollectionUtils.useOrWrap(originalMap, new TypeToken<>() {});
|
||||
assertSame(originalMap, reallyHashMap);
|
||||
}
|
||||
|
||||
{
|
||||
Map<String, Integer> originalMap = new TreeMap<>(Map.of("A", 1, "B", 2));
|
||||
HashMap<String, Integer> reallyHashMap = CollectionUtils.useOrWrap(originalMap, new TypeToken<>() {});
|
||||
assertNotSame(originalMap, reallyHashMap);
|
||||
assertEquals(HashMap.class, reallyHashMap.getClass());
|
||||
}
|
||||
|
||||
assertEquals(TreeMap.class, CollectionUtils.useOrWrap(new Hashtable<>(), TypeToken.get(TreeMap.class)).getClass());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user