mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Allow a map of prepopulatedValues to be provided as an input value, to set defaultValues for fields
This commit is contained in:
@ -22,8 +22,22 @@
|
||||
package com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert;
|
||||
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.StorageAction;
|
||||
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.processes.RunProcessInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.storage.StorageInput;
|
||||
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.model.BulkLoadProfile;
|
||||
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.model.BulkLoadProfileField;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
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;
|
||||
|
||||
|
||||
@ -66,4 +80,39 @@ class BulkInsertPrepareFileMappingStepTest extends BaseTest
|
||||
assertEquals("BAA", BulkInsertPrepareFileMappingStep.toHeaderLetter(2 * 26 * 26 + 26 + 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws Exception
|
||||
{
|
||||
String fileName = "personFile.csv";
|
||||
|
||||
StorageInput storageInput = new StorageInput(TestUtils.TABLE_NAME_MEMORY_STORAGE).withReference(fileName);
|
||||
OutputStream outputStream = new StorageAction().createOutputStream(storageInput);
|
||||
outputStream.write("""
|
||||
name,noOfShoes
|
||||
John,2
|
||||
Jane,4
|
||||
""".getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.close();
|
||||
|
||||
RunProcessInput runProcessInput = new RunProcessInput();
|
||||
BulkInsertStepUtils.setStorageInputForTheFile(runProcessInput, storageInput);
|
||||
runProcessInput.addValue("tableName", TestUtils.TABLE_NAME_PERSON_MEMORY);
|
||||
runProcessInput.addValue("prepopulatedValues", JsonUtils.toJson(Map.of("homeStateId", 1)));
|
||||
|
||||
RunBackendStepInput runBackendStepInput = new RunBackendStepInput(runProcessInput.getProcessState());
|
||||
RunBackendStepOutput runBackendStepOutput = new RunBackendStepOutput();
|
||||
|
||||
new BulkInsertPrepareFileMappingStep().run(runBackendStepInput, runBackendStepOutput);
|
||||
|
||||
BulkLoadProfile bulkLoadProfile = (BulkLoadProfile) runBackendStepOutput.getValue("suggestedBulkLoadProfile");
|
||||
Optional<BulkLoadProfileField> homeStateId = bulkLoadProfile.getFieldList().stream().filter(f -> f.getFieldName().equals("homeStateId")).findFirst();
|
||||
assertThat(homeStateId).isPresent();
|
||||
assertEquals("1", homeStateId.get().getDefaultValue());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user