mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 13:40:44 +00:00
Merge branch 'dev' into feature/join-enhancements
This commit is contained in:
@ -40,7 +40,7 @@ public class RDBMSActionTest extends BaseTest
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
private void afterEachRDBMSActionTest()
|
||||
void afterEachRDBMSActionTest()
|
||||
{
|
||||
QueryManager.resetPageSize();
|
||||
QueryManager.resetStatistics();
|
||||
|
@ -196,7 +196,7 @@ public class RDBMSCountActionTest extends RDBMSActionTest
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_STORE_ALL_ACCESS, true));
|
||||
assertThat(new CountAction().execute(countInput).getCount()).isEqualTo(8);
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(2, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 2).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new CountAction().execute(countInput).getCount()).isEqualTo(5);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
|
||||
{
|
||||
InsertInput insertInput = initInsertRequest();
|
||||
insertInput.setRecords(null);
|
||||
InsertOutput insertOutput = new RDBMSInsertAction().execute(insertInput);
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
assertEquals(0, insertOutput.getRecords().size());
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
|
||||
{
|
||||
InsertInput insertInput = initInsertRequest();
|
||||
insertInput.setRecords(Collections.emptyList());
|
||||
InsertOutput insertOutput = new RDBMSInsertAction().execute(insertInput);
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
assertEquals(0, insertOutput.getRecords().size());
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
|
||||
.withValue("email", "jamestk@starfleet.net")
|
||||
.withValue("birthDate", "2210-05-20");
|
||||
insertInput.setRecords(List.of(record));
|
||||
InsertOutput insertOutput = new RDBMSInsertAction().execute(insertInput);
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
assertEquals(1, insertOutput.getRecords().size(), "Should return 1 row");
|
||||
assertNotNull(insertOutput.getRecords().get(0).getValue("id"), "Should have an id in the row");
|
||||
// todo - add errors to QRecord? assertTrue(insertResult.getRecords().stream().noneMatch(qrs -> CollectionUtils.nullSafeHasContents(qrs.getErrors())), "There should be no errors");
|
||||
@ -132,7 +132,7 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
|
||||
.withValue("email", "doctor@starfleet.net")
|
||||
.withValue("birthDate", "2320-06-26");
|
||||
insertInput.setRecords(List.of(record1, record2, record3));
|
||||
InsertOutput insertOutput = new RDBMSInsertAction().execute(insertInput);
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
assertEquals(3, insertOutput.getRecords().size(), "Should return right # of rows");
|
||||
assertEquals(6, insertOutput.getRecords().get(0).getValue("id"), "Should have next id in the row");
|
||||
assertEquals(7, insertOutput.getRecords().get(1).getValue("id"), "Should have next id in the row");
|
||||
|
@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.module.rdbms.actions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.CountAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||
@ -642,13 +643,13 @@ public class RDBMSQueryActionJoinsTest extends RDBMSActionTest
|
||||
QContext.setQSession(new QSession());
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, null));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, null));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, Collections.emptyList()));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(Collections.emptyMap()));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 1).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(2)
|
||||
.anyMatch(r -> r.getValueInteger("id").equals(1))
|
||||
@ -686,13 +687,13 @@ public class RDBMSQueryActionJoinsTest extends RDBMSActionTest
|
||||
QContext.setQSession(new QSession());
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, null));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(Collections.emptyMap()));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, Collections.emptyList()));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(Map.of(TestUtils.TABLE_NAME_STORE, Collections.emptyList())));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 1).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(6)
|
||||
.allMatch(r -> r.getValueInteger("storeId").equals(1) || r.getValueInteger("storeId").equals(3));
|
||||
@ -752,19 +753,19 @@ public class RDBMSQueryActionJoinsTest extends RDBMSActionTest
|
||||
////////////////////////////////////////////////
|
||||
// with null security key value, 0 rows found //
|
||||
////////////////////////////////////////////////
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, null));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(Collections.emptyMap()));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// with empty-list security key value, 0 rows found //
|
||||
//////////////////////////////////////////////////////
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, Collections.emptyList()));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(Map.of(TestUtils.TABLE_NAME_STORE, Collections.emptyList())));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
////////////////////////////////
|
||||
// with 2 values, find 2 rows //
|
||||
////////////////////////////////
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 1).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(2)
|
||||
.allMatch(r -> r.getValueInteger("storeId").equals(1) || r.getValueInteger("storeId").equals(3));
|
||||
@ -800,7 +801,7 @@ public class RDBMSQueryActionJoinsTest extends RDBMSActionTest
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
queryInput.setFilter(new QQueryFilter(new QFilterCriteria("storeId", QCriteriaOperator.IN, List.of(1, 2))));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 1).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(3)
|
||||
.allMatch(r -> r.getValueInteger("storeId").equals(1));
|
||||
@ -880,7 +881,7 @@ public class RDBMSQueryActionJoinsTest extends RDBMSActionTest
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
queryInput.setFilter(new QQueryFilter(new QFilterCriteria("storeId", QCriteriaOperator.IN, List.of(1, 2))));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 3)));
|
||||
QContext.setQSession(new QSession().withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 1).withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, 3));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(3)
|
||||
.allMatch(r -> r.getValueInteger("storeId").equals(1));
|
||||
|
@ -627,7 +627,7 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
insertInput.setTableName(TestUtils.TABLE_NAME_PERSON);
|
||||
|
||||
InsertAction insertAction = new InsertAction();
|
||||
QBackendTransaction transaction = insertAction.openTransaction(insertInput);
|
||||
QBackendTransaction transaction = QBackendTransaction.openFor(insertInput);
|
||||
|
||||
insertInput.setTransaction(transaction);
|
||||
insertInput.setRecords(List.of(
|
||||
@ -879,10 +879,17 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// user with list of all ids shouldn't see the nulls (given that default null-behavior on this key type is DENY) //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 2, 3, 4, 5)));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(8)
|
||||
.noneMatch(hasNullStoreId);
|
||||
{
|
||||
QSession qSession = new QSession();
|
||||
for(Integer i : List.of(1, 2, 3, 4, 5))
|
||||
{
|
||||
qSession.withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, i);
|
||||
}
|
||||
QContext.setQSession(qSession);
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(8)
|
||||
.noneMatch(hasNullStoreId);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// specifically set the null behavior to deny - repeat the last 2 tests //
|
||||
@ -892,10 +899,17 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
QContext.setQSession(new QSession());
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords()).isEmpty();
|
||||
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 2, 3, 4, 5)));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(8)
|
||||
.noneMatch(hasNullStoreId);
|
||||
{
|
||||
QSession qSession = new QSession();
|
||||
for(Integer i : List.of(1, 2, 3, 4, 5))
|
||||
{
|
||||
qSession.withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, i);
|
||||
}
|
||||
QContext.setQSession(qSession);
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(8)
|
||||
.noneMatch(hasNullStoreId);
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// change null behavior to ALLOW //
|
||||
@ -921,10 +935,17 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
////////////////////////////////////////////////////
|
||||
// user with list of all ids should see the nulls //
|
||||
////////////////////////////////////////////////////
|
||||
QContext.setQSession(new QSession().withSecurityKeyValues(TestUtils.TABLE_NAME_STORE, List.of(1, 2, 3, 4, 5)));
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(10)
|
||||
.anyMatch(hasNullStoreId);
|
||||
{
|
||||
QSession qSession = new QSession();
|
||||
for(Integer i : List.of(1, 2, 3, 4, 5))
|
||||
{
|
||||
qSession.withSecurityKeyValue(TestUtils.TABLE_NAME_STORE, i);
|
||||
}
|
||||
QContext.setQSession(qSession);
|
||||
assertThat(new QueryAction().execute(queryInput).getRecords())
|
||||
.hasSize(10)
|
||||
.anyMatch(hasNullStoreId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ import java.time.OffsetDateTime;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.actions.automation.AutomationStatus;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.BaseTest;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.TestUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@ -126,6 +127,7 @@ class QueryManagerTest extends BaseTest
|
||||
QueryManager.bindParamObject(ps, 1, LocalDate.now());
|
||||
QueryManager.bindParamObject(ps, 1, OffsetDateTime.now());
|
||||
QueryManager.bindParamObject(ps, 1, LocalDateTime.now());
|
||||
QueryManager.bindParamObject(ps, 1, AutomationStatus.PENDING_INSERT_AUTOMATIONS);
|
||||
|
||||
assertThrows(SQLException.class, () ->
|
||||
{
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.module.rdbms.model.metadata;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.BaseTest;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.TestUtils;
|
||||
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;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for RDBMSTableMetaDataBuilder
|
||||
*******************************************************************************/
|
||||
class RDBMSTableMetaDataBuilderTest extends BaseTest
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception
|
||||
{
|
||||
TestUtils.primeTestDatabase("prime-test-database.sql");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void test() throws QException
|
||||
{
|
||||
QBackendMetaData backend = QContext.getQInstance().getBackend(TestUtils.DEFAULT_BACKEND_NAME);
|
||||
QTableMetaData table = new RDBMSTableMetaDataBuilder().buildTableMetaData((RDBMSBackendMetaData) backend, "order");
|
||||
|
||||
assertNotNull(table);
|
||||
assertEquals("order", table.getName());
|
||||
assertEquals("id", table.getPrimaryKeyField());
|
||||
assertEquals(QFieldType.INTEGER, table.getField(table.getPrimaryKeyField()).getType());
|
||||
assertNotNull(table.getField("storeId"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user