mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 05:30:43 +00:00
SPRINT-12: updated to define widgets at table level, refactoring of some of the widget stuff to match other "Action"s
This commit is contained in:
@ -25,10 +25,9 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -40,7 +39,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
|
||||
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -62,7 +61,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
|
||||
labels.add("May 2022");
|
||||
data.add(64);
|
||||
|
||||
return (new ChartData("Persons created per Month", null, "Person records", labels, data));
|
||||
return (new RenderWidgetOutput(new ChartData("Persons created per Month", null, "Person records", labels, data)));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -24,8 +24,7 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QuickSightChartMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@ -43,7 +42,7 @@ class QuickSightChartRendererTest
|
||||
@Test
|
||||
void testWrongMetaDataClass() throws QException
|
||||
{
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(), new QWidgetMetaData()))
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())))
|
||||
.hasRootCauseInstanceOf(ClassCastException.class);
|
||||
}
|
||||
|
||||
@ -55,7 +54,7 @@ class QuickSightChartRendererTest
|
||||
@Test
|
||||
void testNoCredentials() throws QException
|
||||
{
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(), new QuickSightChartMetaData()))
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())))
|
||||
.hasRootCauseInstanceOf(NullPointerException.class);
|
||||
}
|
||||
|
||||
@ -67,14 +66,8 @@ class QuickSightChartRendererTest
|
||||
@Test
|
||||
void testBadCredentials() throws QException
|
||||
{
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(TestUtils.defineInstance(), TestUtils.getMockSession(),
|
||||
new QuickSightChartMetaData()
|
||||
.withName("test")
|
||||
.withAccessKey("FAIL")
|
||||
.withSecretKey("FAIL")
|
||||
.withRegion("FAIL")
|
||||
.withAccountId("FAIL")
|
||||
assertThatThrownBy(() -> new QuickSightChartRenderer().render(new RenderWidgetInput(TestUtils.defineInstance())
|
||||
)).hasRootCauseInstanceOf(UnknownHostException.class);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,10 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.widgets.RenderWidgetOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.ChartData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -32,9 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for WidgetDataLoader
|
||||
** Unit test for RenderWidgetAction
|
||||
*******************************************************************************/
|
||||
class WidgetDataLoaderTest
|
||||
class RenderWidgetActionTest
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
@ -42,9 +45,14 @@ class WidgetDataLoaderTest
|
||||
@Test
|
||||
void test() throws QException
|
||||
{
|
||||
Object widgetData = new WidgetDataLoader().execute(TestUtils.defineInstance(), TestUtils.getMockSession(), PersonsByCreateDateBarChart.class.getSimpleName());
|
||||
assertThat(widgetData).isInstanceOf(ChartData.class);
|
||||
ChartData chartData = (ChartData) widgetData;
|
||||
QInstance testQInstance = TestUtils.defineInstance();
|
||||
RenderWidgetInput input = new RenderWidgetInput(testQInstance)
|
||||
.withSession(TestUtils.getMockSession())
|
||||
.withWidgetMetaData(testQInstance.getWidget(PersonsByCreateDateBarChart.class.getSimpleName()));
|
||||
|
||||
RenderWidgetOutput output = new RenderWidgetAction().execute(input);
|
||||
assertThat(output.getWidgetData()).isInstanceOf(ChartData.class);
|
||||
ChartData chartData = (ChartData) output.getWidgetData();
|
||||
assertEquals("barChart", chartData.getType());
|
||||
assertThat(chartData.getTitle()).isNotBlank();
|
||||
assertNotNull(chartData.getChartData());
|
Reference in New Issue
Block a user