added tests

This commit is contained in:
Tim Chamberlain
2025-07-19 09:38:20 -05:00
parent 90e702112a
commit eb48f9cc87
2 changed files with 156 additions and 7 deletions

View File

@ -115,4 +115,40 @@ class BulkInsertPrepareFileMappingStepTest extends BaseTest
assertEquals("1", homeStateId.get().getDefaultValue()); assertEquals("1", homeStateId.get().getDefaultValue());
} }
/*******************************************************************************
**
*******************************************************************************/
@Test
void testUpdateWithFile() 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("isBulkEdit", "true");
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());
}
} }

View File

@ -0,0 +1,113 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.processes.implementations.bulk.insert;
import com.kingsrook.qqq.backend.core.BaseTest;
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.processes.implementations.bulk.insert.model.BulkLoadTableStructure;
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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
** Unit test for BulkInsertPrepareFileUploadStepTest
*******************************************************************************/
public class BulkInsertPrepareFileUploadStepTest extends BaseTest
{
private BulkInsertPrepareFileUploadStep step;
private RunBackendStepInput input;
private RunBackendStepOutput output;
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
void setup()
{
step = new BulkInsertPrepareFileUploadStep();
input = new RunBackendStepInput();
output = new RunBackendStepOutput();
input.setProcessName("person.bulkInsertWithFile");
input.addValue("tableName", "person");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testRun_bulkInsert_setsExpectedOutput() throws QException
{
step.run(input, output);
assertNotNull(output.getValue("tableStructure"));
assertTrue(output.getValue("tableStructure") instanceof BulkLoadTableStructure);
assertEquals(false, output.getValue("isBulkEdit"));
assertNotNull(output.getValue("upload.html"));
assertTrue(output.getValue("upload.html").toString().contains("File Upload Instructions"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testRun_bulkEdit_setsExpectedOutput() throws QException
{
input.setProcessName("person.bulkEditWithFile");
step.run(input, output);
assertEquals(true, output.getValue("isBulkEdit"));
assertNotNull(output.getValue("upload.html"));
String html = output.getValue("upload.html").toString();
assertTrue(html.contains("edit in the"));
assertTrue(html.contains("Person.csv"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testRun_stepBackClearsFile() throws QException
{
output.getProcessState().setIsStepBack(true);
output.addValue("theFile", "something");
step.run(input, output);
assertNull(output.getValue("theFile"));
}
}