QQQ-42 checkpoint of qqq reports

This commit is contained in:
2022-09-20 12:19:19 -05:00
parent 197dec3105
commit 1f546d8c7d
14 changed files with 375 additions and 55 deletions

View File

@ -32,7 +32,9 @@ import static com.kingsrook.qqq.backend.core.actions.reporting.FormulaInterprete
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
@ -140,4 +142,55 @@ class FormulaInterpreterTest
assertEquals(new BigDecimal("27.78"), interpretFormula(vi, "SCALE(MULTIPLY(100,DIVIDE_SCALE(${pivot.sum.noOfShoes},${total.sum.noOfShoes},6)),2)"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testComparisons() throws QFormulaException
{
QMetaDataVariableInterpreter vi = new QMetaDataVariableInterpreter();
vi.addValueMap("input", Map.of("one", 1, "two", 2, "foo", "bar"));
assertTrue((Boolean) interpretFormula(vi, "LT(${input.one},${input.two})"));
assertFalse((Boolean) interpretFormula(vi, "LT(${input.two},${input.one})"));
assertFalse((Boolean) interpretFormula(vi, "GT(${input.one},${input.two})"));
assertTrue((Boolean) interpretFormula(vi, "GT(${input.two},${input.one})"));
assertTrue((Boolean) interpretFormula(vi, "LTE(${input.one},${input.two})"));
assertTrue((Boolean) interpretFormula(vi, "LTE(${input.one},${input.one})"));
assertFalse((Boolean) interpretFormula(vi, "LTE(${input.two},${input.one})"));
assertFalse((Boolean) interpretFormula(vi, "GTE(${input.one},${input.two})"));
assertTrue((Boolean) interpretFormula(vi, "GTE(${input.one},${input.one})"));
assertTrue((Boolean) interpretFormula(vi, "GTE(${input.two},${input.one})"));
// todo - google sheets compares strings differently...
assertThatThrownBy(() -> interpretFormula(vi, "LT(${input.foo},${input.one})")).hasMessageContaining("[bar] as a number");
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testConditionals() throws QFormulaException
{
QMetaDataVariableInterpreter vi = new QMetaDataVariableInterpreter();
vi.addValueMap("input", Map.of("one", 1, "two", 2, "three", 3, "foo", "bar"));
assertEquals("A", interpretFormula(vi, "IF(LT(${input.one},${input.two}),A,B)"));
assertEquals("B", interpretFormula(vi, "IF(GT(${input.one},${input.two}),A,B)"));
assertEquals("C", interpretFormula(vi, "IF(GT(${input.one},${input.two}),A,IF(GT(${input.two},${input.three}),B,C))"));
assertEquals("B", interpretFormula(vi, "IF(GT(${input.one},${input.two}),A,IF(LT(${input.two},${input.three}),B,C))"));
assertEquals("A", interpretFormula(vi, "IF(GT(${input.two},${input.one}),A,IF(LT(${input.two},${input.three}),B,C))"));
assertEquals("Yes", interpretFormula(vi, "IF(GT(${input.one},0),Yes,No)"));
assertEquals("No", interpretFormula(vi, "IF(LT(${input.one},0),Yes,No)"));
}
}

View File

@ -59,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for GenerateReportAction
*******************************************************************************/
class GenerateReportActionTest
public class GenerateReportActionTest
{
private static final String REPORT_NAME = "personReport1";
@ -243,32 +243,32 @@ class GenerateReportActionTest
Map<String, String> row = iterator.next();
assertEquals(6, list.size());
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isEqualTo("Jonson");
assertThat(row.get("Quantity")).isNull();
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isEqualTo("Jones");
assertThat(row.get("Quantity")).isEqualTo("3");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isEqualTo("Kelly");
assertThat(row.get("Quantity")).isEqualTo("4");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isEqualTo("Keller");
assertThat(row.get("Quantity")).isEqualTo("5");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isEqualTo("Kelkhoff");
assertThat(row.get("Quantity")).isEqualTo("6");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("2");
assertThat(row.get("Home State Id")).isEqualTo("MO");
assertThat(row.get("Last Name")).isEqualTo("Kelkhoff");
assertThat(row.get("Quantity")).isEqualTo("7");
}
@ -297,15 +297,14 @@ class GenerateReportActionTest
Iterator<Map<String, String>> iterator = list.iterator();
Map<String, String> row = iterator.next();
assertEquals(2, list.size());
assertThat(row.get("Home State Id")).isEqualTo("2");
assertThat(row.get("Home State Id")).isEqualTo("MO");
assertThat(row.get("Last Name")).isNull();
assertThat(row.get("Quantity")).isEqualTo("7");
row = iterator.next();
assertThat(row.get("Home State Id")).isEqualTo("1");
assertThat(row.get("Home State Id")).isEqualTo("IL");
assertThat(row.get("Last Name")).isNull();
assertThat(row.get("Quantity")).isEqualTo("18");
}
@ -398,7 +397,7 @@ class GenerateReportActionTest
/*******************************************************************************
**
*******************************************************************************/
private QReportMetaData defineReport(boolean includeTotalRow)
public static QReportMetaData defineReport(boolean includeTotalRow)
{
return new QReportMetaData()
.withName(REPORT_NAME)

View File

@ -584,7 +584,7 @@ class QInstanceValidatorTest
{
QAppMetaData app = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection(null, "Section 1", new QIcon("person"), List.of("test"), null));
.withSection(new QAppSection(null, "Section 1", new QIcon("person"), List.of("test"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app), "Missing a name");
}
@ -598,7 +598,7 @@ class QInstanceValidatorTest
{
QAppMetaData app = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("Section 1", null, new QIcon("person"), List.of("test"), null));
.withSection(new QAppSection("Section 1", null, new QIcon("person"), List.of("test"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app), "Missing a label");
}
@ -612,12 +612,12 @@ class QInstanceValidatorTest
{
QAppMetaData app1 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of(), List.of()));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of(), List.of(), null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app1), "section1 does not have any children", "child test is not listed in any app sections");
QAppMetaData app2 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), null, null));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), null, null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app2), "section1 does not have any children", "child test is not listed in any app sections");
}
@ -631,11 +631,11 @@ class QInstanceValidatorTest
{
QAppMetaData app1 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test", "tset"), null));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test", "tset"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app1), "not a child of this app");
QAppMetaData app2 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), List.of("tset")));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), List.of("tset"), null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app2), "not a child of this app");
}
@ -649,23 +649,23 @@ class QInstanceValidatorTest
{
QAppMetaData app1 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test", "test"), null));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test", "test"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app1), "more than once");
QAppMetaData app2 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), null))
.withSection(new QAppSection("section2", "Section 2", new QIcon("person"), List.of("test"), null));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), null, null))
.withSection(new QAppSection("section2", "Section 2", new QIcon("person"), List.of("test"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app2), "more than once");
QAppMetaData app3 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), List.of("test")));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), List.of("test"), null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app3), "more than once");
QAppMetaData app4 = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), null, List.of("test", "test")));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), null, List.of("test", "test"), null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app4), "more than once");
}
@ -687,7 +687,7 @@ class QInstanceValidatorTest
QAppMetaData app = new QAppMetaData().withName("test")
.withChild(new QTableMetaData().withName("tset"))
.withChild(new QTableMetaData().withName("test"))
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), null));
.withSection(new QAppSection("section1", "Section 1", new QIcon("person"), List.of("test"), null, null));
assertValidationFailureReasons((qInstance) -> qInstance.addApp(app), "not listed in any app sections");
}

View File

@ -200,6 +200,29 @@ class QMetaDataVariableInterpreterTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testLooksLikeVariableButNotFound()
{
QMetaDataVariableInterpreter variableInterpreter = new QMetaDataVariableInterpreter();
variableInterpreter.addValueMap("input", Map.of("x", 1, "y", 2));
variableInterpreter.addValueMap("others", Map.of("foo", "bar"));
assertNull(variableInterpreter.interpretForObject("${input.notFound}", null));
assertEquals(0, variableInterpreter.interpretForObject("${input.notFound}", 0));
assertEquals("--", variableInterpreter.interpretForObject("${input.notFound}", "--"));
assertEquals("--", variableInterpreter.interpretForObject("${others.notFound}", "--"));
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// this one doesn't count as "looking like a variable" - because the "prefix" (notValid) isn't a value map... //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
assertEquals("${notValid.notFound}", variableInterpreter.interpretForObject("${notValid.notFound}", "--"));
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -0,0 +1,77 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2022. 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.reports;
import java.time.LocalDate;
import java.time.Month;
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
import com.kingsrook.qqq.backend.core.actions.reporting.GenerateReportActionTest;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.reporting.QReportMetaData;
import com.kingsrook.qqq.backend.core.utils.TestUtils;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/*******************************************************************************
** Unit test for BasicRunReportProcess
*******************************************************************************/
class BasicRunReportProcessTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void testRunReport() throws QException
{
QInstance instance = TestUtils.defineInstance();
QReportMetaData report = GenerateReportActionTest.defineReport(true);
QProcessMetaData runReportProcess = BasicRunReportProcess.defineProcessMetaData();
instance.addReport(report);
report.setProcessName(runReportProcess.getName());
instance.addProcess(runReportProcess);
RunProcessInput runProcessInput = new RunProcessInput(instance);
runProcessInput.setSession(TestUtils.getMockSession());
runProcessInput.setProcessName(report.getProcessName());
runProcessInput.addValue(BasicRunReportProcess.FIELD_REPORT_NAME, report.getName());
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
String processUUID = runProcessOutput.getProcessUUID();
assertThat(runProcessOutput.getProcessState().getNextStepName()).isPresent().get().isEqualTo(BasicRunReportProcess.STEP_NAME_INPUT);
runProcessInput.addValue("startDate", LocalDate.of(1980, Month.JANUARY, 1));
runProcessInput.addValue("endDate", LocalDate.of(2099, Month.DECEMBER, 31));
runProcessInput.setStartAfterStep(BasicRunReportProcess.STEP_NAME_INPUT);
runProcessInput.setProcessUUID(processUUID);
runProcessOutput = new RunProcessAction().execute(runProcessInput);
assertThat(runProcessOutput.getProcessState().getNextStepName()).isPresent().get().isEqualTo(BasicRunReportProcess.STEP_NAME_ACCESS);
assertThat(runProcessOutput.getValues()).containsKeys("downloadFileName", "serverFilePath");
}
}