CE-1955 - more flexible handling of inbound types for looking up possible values

This commit is contained in:
2024-12-16 08:27:21 -06:00
parent 000226c30a
commit db526009d2
2 changed files with 80 additions and 9 deletions

View File

@ -23,6 +23,7 @@ package com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.map
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.kingsrook.qqq.backend.core.BaseTest;
@ -36,6 +37,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
@ -113,6 +115,47 @@ class BulkLoadValueMapperTest extends BaseTest
/***************************************************************************
**
***************************************************************************/
void testPossibleValue(Serializable inputValue, Serializable expectedValue, boolean expectErrors) throws QException
{
QRecord inputRecord = new QRecord().withValue("homeStateId", inputValue);
BulkLoadValueMapper.valueMapping(List.of(inputRecord), new BulkInsertMapping(), QContext.getQInstance().getTable(TestUtils.TABLE_NAME_PERSON_MEMORY));
assertEquals(expectedValue, inputRecord.getValue("homeStateId"));
if(expectErrors)
{
assertThat(inputRecord.getErrors().get(0)).isInstanceOf(BulkLoadPossibleValueError.class);
}
else
{
assertThat(inputRecord.getErrors()).isNullOrEmpty();
}
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testPossibleValues() throws QException
{
testPossibleValue(1, 1, false);
testPossibleValue("1", 1, false);
testPossibleValue("1.0", 1, false);
testPossibleValue(new BigDecimal("1.0"), 1, false);
testPossibleValue("IL", 1, false);
testPossibleValue(512, 512, true); // an id, but not in the PVS
testPossibleValue("USA", "USA", true);
testPossibleValue(true, true, true);
testPossibleValue(new BigDecimal("4.7"), new BigDecimal("4.7"), true);
}
/***************************************************************************
**
***************************************************************************/