mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 21:20:45 +00:00
CE-1402 New CaseChangeBehavior, and adding field behaviors to read operations (mostly) and filters and frontend if so specified
This commit is contained in:
@ -22,15 +22,28 @@
|
||||
package com.kingsrook.qqq.backend.core.actions.tables;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
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.tables.get.GetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
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.metadata.fields.CaseChangeBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.UniqueKey;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -71,4 +84,40 @@ class GetActionTest extends BaseTest
|
||||
assertNotNull(result.getRecord());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFilterFieldBehaviors() throws QException
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// insert one shape with a mixed-case name, one with an all-lower name //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_SHAPE).withRecords(List.of(
|
||||
new QRecord().withValue("name", "Triangle"),
|
||||
new QRecord().withValue("name", "square")
|
||||
)));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// now set the shape table's name field to have a to-lower-case behavior //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_SHAPE);
|
||||
table.withUniqueKey(new UniqueKey("name"));
|
||||
QFieldMetaData field = table.getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// confirm that if we query for "Triangle", we can't find it (because query will to-lower-case the criteria) //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
assertNull(GetAction.execute(TestUtils.TABLE_NAME_SHAPE, Map.of("name", "Triangle")));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// confirm that if we query for "SQUARE", we do find it (because query will to-lower-case the criteria) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
assertNotNull(GetAction.execute(TestUtils.TABLE_NAME_SHAPE, Map.of("name", "sQuArE")));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.actions.tables;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.async.AsyncRecordPipeLoop;
|
||||
import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe;
|
||||
@ -32,13 +33,18 @@ import com.kingsrook.qqq.backend.core.actions.tables.helpers.QueryStatManager;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||
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.metadata.fields.CaseChangeBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.querystats.QueryStat;
|
||||
import com.kingsrook.qqq.backend.core.model.querystats.QueryStatMetaDataProvider;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
@ -499,4 +505,40 @@ class QueryActionTest extends BaseTest
|
||||
insertInput.setRecords(recordList);
|
||||
new InsertAction().execute(insertInput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFilterFieldBehaviors() throws QException
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// insert one shape with a mixed-case name, one with an all-lower name //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_SHAPE).withRecords(List.of(
|
||||
new QRecord().withValue("name", "Triangle"),
|
||||
new QRecord().withValue("name", "square")
|
||||
)));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// now set the shape table's name field to have a to-lower-case behavior //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_SHAPE);
|
||||
QFieldMetaData field = table.getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// confirm that if we query for "Triangle", we can't find it (because query will to-lower-case the criteria) //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
assertEquals(0, QueryAction.execute(TestUtils.TABLE_NAME_SHAPE, new QQueryFilter(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Triangle"))).size());
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// confirm that if we query for "SQUARE", we do find it (because query will to-lower-case the criteria) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
assertEquals(1, QueryAction.execute(TestUtils.TABLE_NAME_SHAPE, new QQueryFilter(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "SqUaRe"))).size());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,11 +27,15 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
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.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.CaseChangeBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldDisplayBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.ValueTooLongBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
@ -39,7 +43,9 @@ import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
@ -255,4 +261,64 @@ class ValueBehaviorApplierTest extends BaseTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFilters()
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_SHAPE);
|
||||
QFieldMetaData field = table.getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
|
||||
assertNull(ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, null, null));
|
||||
|
||||
QQueryFilter emptyFilter = new QQueryFilter();
|
||||
assertSame(emptyFilter, ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, emptyFilter, null));
|
||||
|
||||
QQueryFilter hasCriteriaButNotUpdated = new QQueryFilter().withCriteria(new QFilterCriteria("id", QCriteriaOperator.EQUALS, 1));
|
||||
assertSame(hasCriteriaButNotUpdated, ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasCriteriaButNotUpdated, null));
|
||||
|
||||
QQueryFilter hasSubFiltersButNotUpdated = new QQueryFilter().withSubFilters(List.of(new QQueryFilter().withCriteria(new QFilterCriteria("id", QCriteriaOperator.EQUALS, 1))));
|
||||
assertSame(hasSubFiltersButNotUpdated, ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasSubFiltersButNotUpdated, null));
|
||||
|
||||
QQueryFilter hasCriteriaWithoutValues = new QQueryFilter().withSubFilters(List.of(new QQueryFilter().withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS))));
|
||||
assertSame(hasCriteriaWithoutValues, ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasCriteriaWithoutValues, null));
|
||||
|
||||
QQueryFilter hasCriteriaAndSubFiltersButNotUpdated = new QQueryFilter()
|
||||
.withCriteria(new QFilterCriteria("id", QCriteriaOperator.EQUALS, 1))
|
||||
.withSubFilters(List.of(new QQueryFilter().withCriteria(new QFilterCriteria("id", QCriteriaOperator.EQUALS, 1))));
|
||||
assertSame(hasCriteriaAndSubFiltersButNotUpdated, ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasCriteriaAndSubFiltersButNotUpdated, null));
|
||||
|
||||
QQueryFilter hasCriteriaToUpdate = new QQueryFilter().withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Triangle"));
|
||||
QQueryFilter hasCriteriaUpdated = ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasCriteriaToUpdate, null);
|
||||
assertNotSame(hasCriteriaToUpdate, hasCriteriaUpdated);
|
||||
assertEquals("triangle", hasCriteriaUpdated.getCriteria().get(0).getValues().get(0));
|
||||
assertEquals(hasCriteriaToUpdate.getSubFilters(), hasCriteriaUpdated.getSubFilters());
|
||||
|
||||
QQueryFilter hasSubFilterToUpdate = new QQueryFilter().withSubFilter(new QQueryFilter().withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Oval")));
|
||||
QQueryFilter hasSubFilterUpdated = ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasSubFilterToUpdate, null);
|
||||
assertNotSame(hasSubFilterToUpdate, hasSubFilterUpdated);
|
||||
assertEquals("oval", hasSubFilterUpdated.getSubFilters().get(0).getCriteria().get(0).getValues().get(0));
|
||||
assertEquals(hasSubFilterToUpdate.getCriteria(), hasSubFilterUpdated.getCriteria());
|
||||
|
||||
QQueryFilter hasCriteriaAndSubFilterToUpdate = new QQueryFilter()
|
||||
.withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Square"))
|
||||
.withSubFilter(new QQueryFilter().withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Circle")));
|
||||
QQueryFilter hasCriteriaAndSubFilterUpdated = ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasCriteriaAndSubFilterToUpdate, null);
|
||||
assertNotSame(hasCriteriaAndSubFilterToUpdate, hasCriteriaAndSubFilterUpdated);
|
||||
assertEquals("square", hasCriteriaAndSubFilterUpdated.getCriteria().get(0).getValues().get(0));
|
||||
assertEquals("circle", hasCriteriaAndSubFilterUpdated.getSubFilters().get(0).getCriteria().get(0).getValues().get(0));
|
||||
|
||||
QQueryFilter hasMultiValueCriteriaToUpdate = new QQueryFilter().withCriteria(new QFilterCriteria("name", QCriteriaOperator.EQUALS, "Triangle", "Square"));
|
||||
QQueryFilter hasMultiValueCriteriaUpdated = ValueBehaviorApplier.applyFieldBehaviorsToFilter(qInstance, table, hasMultiValueCriteriaToUpdate, null);
|
||||
assertNotSame(hasMultiValueCriteriaToUpdate, hasMultiValueCriteriaUpdated);
|
||||
assertEquals(List.of("triangle", "square"), hasMultiValueCriteriaUpdated.getCriteria().get(0).getValues());
|
||||
assertEquals(hasMultiValueCriteriaToUpdate.getSubFilters(), hasMultiValueCriteriaUpdated.getSubFilters());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* 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.model.metadata.fields;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.values.ValueBehaviorApplier;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
||||
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.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.ListBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for CaseChangeBehavior
|
||||
*******************************************************************************/
|
||||
class CaseChangeBehaviorTest extends BaseTest
|
||||
{
|
||||
public static final String FIELD = "firstName" ;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testNone()
|
||||
{
|
||||
assertNull(applyToRecord(CaseChangeBehavior.NONE, new QRecord(), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertNull(applyToRecord(CaseChangeBehavior.NONE, new QRecord().withValue(FIELD, null), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertEquals("John", applyToRecord(CaseChangeBehavior.NONE, new QRecord().withValue(FIELD, "John"), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
|
||||
assertEquals(ListBuilder.of("John", null, "Jane"), applyToRecords(CaseChangeBehavior.NONE, List.of(
|
||||
new QRecord().withValue(FIELD, "John"),
|
||||
new QRecord(),
|
||||
new QRecord().withValue(FIELD, "Jane")),
|
||||
ValueBehaviorApplier.Action.INSERT).stream().map(r -> r.getValueString(FIELD)).toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testToUpperCase()
|
||||
{
|
||||
assertNull(applyToRecord(CaseChangeBehavior.TO_UPPER_CASE, new QRecord(), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertNull(applyToRecord(CaseChangeBehavior.TO_UPPER_CASE, new QRecord().withValue(FIELD, null), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertEquals("JOHN", applyToRecord(CaseChangeBehavior.TO_UPPER_CASE, new QRecord().withValue(FIELD, "John"), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
|
||||
assertEquals(ListBuilder.of("JOHN", null, "JANE"), applyToRecords(CaseChangeBehavior.TO_UPPER_CASE, List.of(
|
||||
new QRecord().withValue(FIELD, "John"),
|
||||
new QRecord(),
|
||||
new QRecord().withValue(FIELD, "Jane")),
|
||||
ValueBehaviorApplier.Action.INSERT).stream().map(r -> r.getValueString(FIELD)).toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testToLowerCase()
|
||||
{
|
||||
assertNull(applyToRecord(CaseChangeBehavior.TO_LOWER_CASE, new QRecord(), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertNull(applyToRecord(CaseChangeBehavior.TO_LOWER_CASE, new QRecord().withValue(FIELD, null), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
assertEquals("john", applyToRecord(CaseChangeBehavior.TO_LOWER_CASE, new QRecord().withValue(FIELD, "John"), ValueBehaviorApplier.Action.INSERT).getValue(FIELD));
|
||||
|
||||
assertEquals(ListBuilder.of("john", null, "jane"), applyToRecords(CaseChangeBehavior.TO_LOWER_CASE, List.of(
|
||||
new QRecord().withValue(FIELD, "John"),
|
||||
new QRecord(),
|
||||
new QRecord().withValue(FIELD, "Jane")),
|
||||
ValueBehaviorApplier.Action.INSERT).stream().map(r -> r.getValueString(FIELD)).toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private QRecord applyToRecord(CaseChangeBehavior behavior, QRecord record, ValueBehaviorApplier.Action action)
|
||||
{
|
||||
return (applyToRecords(behavior, List.of(record), action).get(0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private List<QRecord> applyToRecords(CaseChangeBehavior behavior, List<QRecord> records, ValueBehaviorApplier.Action action)
|
||||
{
|
||||
QTableMetaData table = QContext.getQInstance().getTable(TestUtils.TABLE_NAME_PERSON_MEMORY);
|
||||
behavior.apply(action, records, QContext.getQInstance(), table, table.getField(FIELD));
|
||||
return (records);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testReads() throws QException
|
||||
{
|
||||
TestUtils.insertDefaultShapes(QContext.getQInstance());
|
||||
|
||||
List<QRecord> records = QueryAction.execute(TestUtils.TABLE_NAME_SHAPE, null);
|
||||
assertEquals(Set.of("Triangle", "Square", "Circle"), records.stream().map(r -> r.getValueString("name")).collect(Collectors.toSet()));
|
||||
|
||||
QFieldMetaData field = QContext.getQInstance().getTable(TestUtils.TABLE_NAME_SHAPE).getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_UPPER_CASE));
|
||||
|
||||
records = QueryAction.execute(TestUtils.TABLE_NAME_SHAPE, null);
|
||||
assertEquals(Set.of("TRIANGLE", "SQUARE", "CIRCLE"), records.stream().map(r -> r.getValueString("name")).collect(Collectors.toSet()));
|
||||
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
assertEquals("triangle", GetAction.execute(TestUtils.TABLE_NAME_SHAPE, 1).getValueString("name"));
|
||||
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.NONE));
|
||||
assertEquals("Triangle", GetAction.execute(TestUtils.TABLE_NAME_SHAPE, 1).getValueString("name"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testWrites() throws QException
|
||||
{
|
||||
Integer id = 100;
|
||||
|
||||
QFieldMetaData field = QContext.getQInstance().getTable(TestUtils.TABLE_NAME_SHAPE).getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_UPPER_CASE));
|
||||
new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_SHAPE).withRecord(new QRecord().withValue("id", id).withValue("name", "Octagon")));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// turn off the to-upper-case behavior, so we'll see what was actually inserted //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
field.setBehaviors(Collections.emptySet());
|
||||
assertEquals("OCTAGON", GetAction.execute(TestUtils.TABLE_NAME_SHAPE, id).getValueString("name"));
|
||||
|
||||
////////////////////////////////////////////
|
||||
// change to toLowerCase and do an update //
|
||||
////////////////////////////////////////////
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
new UpdateAction().execute(new UpdateInput(TestUtils.TABLE_NAME_SHAPE).withRecord(new QRecord().withValue("id", id).withValue("name", "Octagon")));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// turn off the to-lower-case behavior, so we'll see what was actually udpated to //
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
field.setBehaviors(Collections.emptySet());
|
||||
assertEquals("octagon", GetAction.execute(TestUtils.TABLE_NAME_SHAPE, id).getValueString("name"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testFilter()
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
QTableMetaData table = qInstance.getTable(TestUtils.TABLE_NAME_SHAPE);
|
||||
QFieldMetaData field = table.getField("name");
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_UPPER_CASE));
|
||||
assertEquals("SQUARE", CaseChangeBehavior.TO_UPPER_CASE.applyToFilterCriteriaValue("square", qInstance, table, field));
|
||||
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.TO_LOWER_CASE));
|
||||
assertEquals("triangle", CaseChangeBehavior.TO_LOWER_CASE.applyToFilterCriteriaValue("Triangle", qInstance, table, field));
|
||||
|
||||
field.setBehaviors(Set.of(CaseChangeBehavior.NONE));
|
||||
assertEquals("Circle", CaseChangeBehavior.NONE.applyToFilterCriteriaValue("Circle", qInstance, table, field));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user