Merge branch 'feature/ONE-68-frontend-fixes-spike' into feature/sprint-8

This commit is contained in:
2022-08-04 18:39:16 -05:00
27 changed files with 1591 additions and 183 deletions

View File

@ -22,13 +22,18 @@
package com.kingsrook.qqq.backend.core.actions.metadata;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.metadata.MetaDataInput;
import com.kingsrook.qqq.backend.core.model.actions.metadata.MetaDataOutput;
import com.kingsrook.qqq.backend.core.model.metadata.frontend.QFrontendAppMetaData;
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;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -51,11 +56,17 @@ class MetaDataActionTest
MetaDataOutput result = new MetaDataAction().execute(request);
assertNotNull(result);
///////////////////////////////////
// assert against the tables map //
///////////////////////////////////
assertNotNull(result.getTables());
assertNotNull(result.getTables().get("person"));
assertEquals("person", result.getTables().get("person").getName());
assertEquals("Person", result.getTables().get("person").getLabel());
//////////////////////////////////////
// assert against the processes map //
//////////////////////////////////////
assertNotNull(result.getProcesses().get("greet"));
assertNotNull(result.getProcesses().get("greetInteractive"));
assertNotNull(result.getProcesses().get("etl.basic"));
@ -63,5 +74,47 @@ class MetaDataActionTest
assertNotNull(result.getProcesses().get("person.bulkEdit"));
assertNotNull(result.getProcesses().get("person.bulkDelete"));
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// assert against the apps map - which is appName to app - but not fully hierarchical - that's appTree //
/////////////////////////////////////////////////////////////////////////////////////////////////////////
Map<String, QFrontendAppMetaData> apps = result.getApps();
assertNotNull(apps.get(TestUtils.APP_NAME_GREETINGS));
assertNotNull(apps.get(TestUtils.APP_NAME_PEOPLE));
assertNotNull(apps.get(TestUtils.APP_NAME_MISCELLANEOUS));
QFrontendAppMetaData peopleApp = apps.get(TestUtils.APP_NAME_PEOPLE);
assertThat(peopleApp.getChildren()).isNotEmpty();
Optional<QFrontendAppMetaData> greetingsAppUnderPeopleFromMapOptional = peopleApp.getChildren().stream()
.filter(e -> e.getName().equals(TestUtils.APP_NAME_GREETINGS)).findFirst();
assertThat(greetingsAppUnderPeopleFromMapOptional).isPresent();
//////////////////////////////////////////////////////////////////////////////
// we want to show that in the appMap (e.g., "apps"), that the apps are not //
// hierarchical - that is - that a sub-app doesn't list ITS children here. //
//////////////////////////////////////////////////////////////////////////////
assertThat(greetingsAppUnderPeopleFromMapOptional.get().getChildren()).isNullOrEmpty();
///////////////////////////////////////////////
// assert against the hierarchical apps tree //
///////////////////////////////////////////////
List<QFrontendAppMetaData> appTree = result.getAppTree();
Set<String> appNamesInTopOfTree = appTree.stream().map(QFrontendAppMetaData::getName).collect(Collectors.toSet());
assertThat(appNamesInTopOfTree).contains(TestUtils.APP_NAME_PEOPLE);
assertThat(appNamesInTopOfTree).contains(TestUtils.APP_NAME_MISCELLANEOUS);
assertThat(appNamesInTopOfTree).doesNotContain(TestUtils.APP_NAME_GREETINGS);
Optional<QFrontendAppMetaData> peopleAppOptional = appTree.stream()
.filter(e -> e.getName().equals(TestUtils.APP_NAME_PEOPLE)).findFirst();
assertThat(peopleAppOptional).isPresent();
assertThat(peopleAppOptional.get().getChildren()).isNotEmpty();
Optional<QFrontendAppMetaData> greetingsAppUnderPeopleFromTree = peopleAppOptional.get().getChildren().stream()
.filter(e -> e.getName().equals(TestUtils.APP_NAME_GREETINGS)).findFirst();
assertThat(greetingsAppUnderPeopleFromTree).isPresent();
/////////////////////////////////////////////////////////////////////////////////
// but here, when this app comes from the tree, then it DOES have its children //
/////////////////////////////////////////////////////////////////////////////////
assertThat(greetingsAppUnderPeopleFromTree.get().getChildren()).isNotEmpty();
}
}

View File

@ -25,8 +25,10 @@ package com.kingsrook.qqq.backend.core.actions.tables;
import com.kingsrook.qqq.backend.core.exceptions.QException;
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.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -50,5 +52,13 @@ class QueryActionTest
request.setTableName("person");
QueryOutput result = new QueryAction().execute(request);
assertNotNull(result);
assertThat(result.getRecords()).isNotEmpty();
for(QRecord record : result.getRecords())
{
assertThat(record.getValues()).isNotEmpty();
assertThat(record.getDisplayValues()).isNotEmpty();
assertThat(record.getErrors()).isEmpty();
}
}
}

View File

@ -22,13 +22,17 @@
package com.kingsrook.qqq.backend.core.instances;
import java.util.Collections;
import java.util.HashMap;
import java.util.function.Consumer;
import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
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;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -51,6 +55,21 @@ class QInstanceValidatorTest
/*******************************************************************************
** make sure we don't re-validate if already validated
**
*******************************************************************************/
@Test
public void test_doNotReValidate() throws QInstanceValidationException
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.setHasBeenValidated(new QInstanceValidationKey());
qInstance.setBackends(null);
new QInstanceValidator().validate(qInstance);
}
/*******************************************************************************
** Test an instance with null backends - should throw.
**
@ -58,17 +77,8 @@ class QInstanceValidatorTest
@Test
public void test_validateNullBackends()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.setBackends(null);
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 backend must be defined", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.setBackends(null),
"At least 1 backend must be defined");
}
@ -80,17 +90,8 @@ class QInstanceValidatorTest
@Test
public void test_validateEmptyBackends()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.setBackends(new HashMap<>());
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 backend must be defined", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.setBackends(new HashMap<>()),
"At least 1 backend must be defined");
}
@ -102,17 +103,12 @@ class QInstanceValidatorTest
@Test
public void test_validateNullTables()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.setTables(null);
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 table must be defined", e);
}
assertValidationFailureReasons((qInstance) ->
{
qInstance.setTables(null);
qInstance.setProcesses(null);
},
"At least 1 table must be defined");
}
@ -124,17 +120,12 @@ class QInstanceValidatorTest
@Test
public void test_validateEmptyTables()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.setTables(new HashMap<>());
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 table must be defined", e);
}
assertValidationFailureReasons((qInstance) ->
{
qInstance.setTables(new HashMap<>());
qInstance.setProcesses(new HashMap<>());
},
"At least 1 table must be defined");
}
@ -147,19 +138,15 @@ class QInstanceValidatorTest
@Test
public void test_validateInconsistentNames()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").setName("notPerson");
qInstance.getBackend("default").setName("notDefault");
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("Inconsistent naming for table", e);
assertReason("Inconsistent naming for backend", e);
}
assertValidationFailureReasonsAllowingExtraReasons((qInstance) ->
{
qInstance.getTable("person").setName("notPerson");
qInstance.getBackend("default").setName("notDefault");
qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).setName("notGreetPeople");
},
"Inconsistent naming for table",
"Inconsistent naming for backend",
"Inconsistent naming for process");
}
@ -171,17 +158,8 @@ class QInstanceValidatorTest
@Test
public void test_validateTableWithoutBackend()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").setBackendName(null);
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("Missing backend name for table", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.getTable("person").setBackendName(null),
"Missing backend name for table");
}
@ -193,17 +171,53 @@ class QInstanceValidatorTest
@Test
public void test_validateTableWithMissingBackend()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").setBackendName("notARealBackend");
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("Unrecognized backend", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.getTable("person").setBackendName("notARealBackend"),
"Unrecognized backend");
}
/*******************************************************************************
** Test that if a process specifies a table that doesn't exist, that it fails.
**
*******************************************************************************/
@Test
public void test_validateProcessWithMissingTable()
{
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).setTableName("notATableName"),
"Unrecognized table");
}
/*******************************************************************************
** Test that a process with no steps fails
**
*******************************************************************************/
@Test
public void test_validateProcessWithNoSteps()
{
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).setStepList(Collections.emptyList()),
"At least 1 step");
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).setStepList(null),
"At least 1 step");
}
/*******************************************************************************
** Test that a process step with an empty string name fails
**
*******************************************************************************/
@Test
public void test_validateProcessStepWithEmptyName()
{
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).getStepList().get(0).setName(""),
"Missing name for a step");
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE_INTERACTIVE).getStepList().get(1).setName(null),
"Missing name for a step");
}
@ -215,29 +229,11 @@ class QInstanceValidatorTest
@Test
public void test_validateTableWithNoFields()
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").setFields(null);
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 field", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.getTable("person").setFields(null),
"At least 1 field");
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").setFields(new HashMap<>());
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("At least 1 field", e);
}
assertValidationFailureReasons((qInstance) -> qInstance.getTable("person").setFields(new HashMap<>()),
"At least 1 field");
}
@ -248,17 +244,92 @@ class QInstanceValidatorTest
*******************************************************************************/
@Test
public void test_validateFieldWithMissingPossibleValueSource()
{
assertValidationFailureReasons((qInstance) -> qInstance.getTable("person").getField("homeState").setPossibleValueSourceName("not a real possible value source"),
"Unrecognized possibleValueSourceName");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testChildrenWithBadParentAppName()
{
String[] reasons = new String[] { "Unrecognized parent app", "does not have its parent app properly set" };
assertValidationFailureReasons((qInstance) -> qInstance.getTable(TestUtils.TABLE_NAME_PERSON).setParentAppName("notAnApp"), reasons);
assertValidationFailureReasons((qInstance) -> qInstance.getProcess(TestUtils.PROCESS_NAME_GREET_PEOPLE).setParentAppName("notAnApp"), reasons);
assertValidationFailureReasons((qInstance) -> qInstance.getApp(TestUtils.APP_NAME_GREETINGS).setParentAppName("notAnApp"), reasons);
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testAppCircularReferences()
{
assertValidationFailureReasonsAllowingExtraReasons((qInstance) ->
{
QAppMetaData miscApp = qInstance.getApp(TestUtils.APP_NAME_MISCELLANEOUS);
QAppMetaData greetingsApp = qInstance.getApp(TestUtils.APP_NAME_GREETINGS);
miscApp.withChild(greetingsApp);
greetingsApp.withChild(miscApp);
}, "Circular app reference");
}
/*******************************************************************************
** Run a little setup code on a qInstance; then validate it, and assert that it
** failed validation with reasons that match the supplied vararg-reasons (but allow
** more reasons - e.g., helpful when one thing we're testing causes other errors).
*******************************************************************************/
private void assertValidationFailureReasonsAllowingExtraReasons(Consumer<QInstance> setup, String... reasons)
{
assertValidationFailureReasons(setup, true, reasons);
}
/*******************************************************************************
** Run a little setup code on a qInstance; then validate it, and assert that it
** failed validation with reasons that match the supplied vararg-reasons (and
** require that exact # of reasons).
*******************************************************************************/
private void assertValidationFailureReasons(Consumer<QInstance> setup, String... reasons)
{
assertValidationFailureReasons(setup, false, reasons);
}
/*******************************************************************************
** Implementation for the overloads of this name.
*******************************************************************************/
private void assertValidationFailureReasons(Consumer<QInstance> setup, boolean allowExtraReasons, String... reasons)
{
try
{
QInstance qInstance = TestUtils.defineInstance();
qInstance.getTable("person").getField("homeState").setPossibleValueSourceName("not a real possible value source");
setup.accept(qInstance);
new QInstanceValidator().validate(qInstance);
fail("Should have thrown validationException");
}
catch(QInstanceValidationException e)
{
assertReason("Unrecognized possibleValueSourceName", e);
if(!allowExtraReasons)
{
assertEquals(reasons.length, e.getReasons().size(), "Expected number of validation failure reasons\nExpected: " + String.join(",", reasons) + "\nActual: " + e.getReasons());
}
for(String reason : reasons)
{
assertReason(reason, e);
}
}
}
@ -271,7 +342,9 @@ class QInstanceValidatorTest
*******************************************************************************/
private void assertReason(String reason, QInstanceValidationException e)
{
assertNotNull(e.getReasons());
assertTrue(e.getReasons().stream().anyMatch(s -> s.contains(reason)));
assertNotNull(e.getReasons(), "Expected there to be a reason for the failure (but there was not)");
assertThat(e.getReasons())
.withFailMessage("Expected any of:\n%s\nTo match: [%s]", e.getReasons(), reason)
.anyMatch(s -> s.contains(reason));
}
}

View File

@ -39,6 +39,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QBackendStepMetaData;
@ -53,8 +54,8 @@ import com.kingsrook.qqq.backend.core.modules.authentication.MockAuthenticationM
import com.kingsrook.qqq.backend.core.modules.authentication.metadata.QAuthenticationMetaData;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.mock.MockBackendModule;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.basic.BasicETLProcess;
import com.kingsrook.qqq.backend.core.processes.implementations.mock.MockBackendStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamed.StreamedETLProcess;
import com.kingsrook.qqq.backend.core.processes.implementations.mock.MockBackendStep;
/*******************************************************************************
@ -65,6 +66,10 @@ public class TestUtils
{
public static final String DEFAULT_BACKEND_NAME = "default";
public static final String APP_NAME_GREETINGS = "greetingsApp";
public static final String APP_NAME_PEOPLE = "peopleApp";
public static final String APP_NAME_MISCELLANEOUS = "miscellaneous";
public static final String TABLE_NAME_PERSON = "person";
public static final String PROCESS_NAME_GREET_PEOPLE = "greet";
@ -84,16 +89,21 @@ public class TestUtils
QInstance qInstance = new QInstance();
qInstance.setAuthentication(defineAuthentication());
qInstance.addBackend(defineBackend());
qInstance.addTable(defineTablePerson());
qInstance.addTable(definePersonFileTable());
qInstance.addTable(defineTableIdAndNameOnly());
qInstance.addPossibleValueSource(defineStatesPossibleValueSource());
qInstance.addProcess(defineProcessGreetPeople());
qInstance.addProcess(defineProcessGreetPeopleInteractive());
qInstance.addProcess(defineProcessAddToPeoplesAge());
qInstance.addProcess(new BasicETLProcess().defineProcessMetaData());
qInstance.addProcess(new StreamedETLProcess().defineProcessMetaData());
defineApps(qInstance);
System.out.println(new QInstanceAdapter().qInstanceToJson(qInstance));
return (qInstance);
@ -101,6 +111,30 @@ public class TestUtils
/*******************************************************************************
**
*******************************************************************************/
private static void defineApps(QInstance qInstance)
{
qInstance.addApp(new QAppMetaData()
.withName(APP_NAME_GREETINGS)
.withChild(qInstance.getProcess(PROCESS_NAME_GREET_PEOPLE))
.withChild(qInstance.getProcess(PROCESS_NAME_GREET_PEOPLE_INTERACTIVE)));
qInstance.addApp(new QAppMetaData()
.withName(APP_NAME_PEOPLE)
.withChild(qInstance.getTable(TABLE_NAME_PERSON))
.withChild(qInstance.getTable(TABLE_NAME_PERSON_FILE))
.withChild(qInstance.getApp(APP_NAME_GREETINGS)));
qInstance.addApp(new QAppMetaData()
.withName(APP_NAME_MISCELLANEOUS)
.withChild(qInstance.getTable(TABLE_NAME_ID_AND_NAME_ONLY))
.withChild(qInstance.getProcess(BasicETLProcess.PROCESS_NAME)));
}
/*******************************************************************************
** Define the "states" possible value source used in standard tests
**