@Test public void testGroupNotAllowed() { presenter.init(DATA_MULTIPLE_NO_GROUP, DataSetLookupFactory.newDataSetLookupBuilder() .dataset(POPULATION_UUID) .column("year") .column("population") .buildLookup()); verify(view, never()).setGroupEnabled(true); verify(view, never()).enableGroupColumnSelectorHint(); verify(event, never()).fire(any(DataSetLookupChangedEvent.class)); }
@Test public void testAutoCreateRequiredGroup() { presenter.init(DATA_2D_FIXED, DataSetLookupFactory.newDataSetLookupBuilder() .dataset(POPULATION_UUID) .filter(greaterThan(100)) .column("country") .column("population", AggregateFunctionType.SUM) .buildLookup()); assertEquals(presenter.getFirstGroupColumnId(), "continent"); verify(event).fire(any(DataSetLookupChangedEvent.class)); }
@Test(expected = RuntimeException.class) public void testSortingWithNonDefinedColumn() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_CUSTOM_COLUMNS2_UUID) .sort(ExpenseReportsData.COLUMN_DEPARTMENT, SortOrder.DESCENDING) .buildLookup()); }
@Test(expected = RuntimeException.class) public void testSortingWithNonExistingColumn() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .sort("mycolumn", SortOrder.DESCENDING) .buildLookup()); }
@Test public void testFilterUntilToday() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_DATE, timeFrame("10second")) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //assertThat(result.getRowCount()).isEqualTo(0); }
@Test(expected = RuntimeException.class) public void testFilterLikeToByStringNotAnalyzedAndCaseUnSensitive() throws Exception { // Case un-sensitive DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter(ExpenseReportsData.COLUMN_DEPARTMENT, likeTo(ExpenseReportsData.COLUMN_DEPARTMENT, "Sal%", false)) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); }
@Test public void testSortByNumber() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .sort(COLUMN_AMOUNT, ASCENDING) .buildLookup()); //printDataSet(result); assertDataSetValue(result, 0, 0, "23.00"); assertDataSetValue(result, 49, 0, "2.00"); }
@Test public void testFilterUntilToday() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_DATE, timeFrame("10second")) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //assertThat(result.getRowCount()).isEqualTo(0); }
@Test public void testSortByDate() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .sort(COLUMN_DATE, ASCENDING) .buildLookup()); //printDataSet(result); assertDataSetValue(result, 0, 0, "50.00"); assertDataSetValue(result, 49, 0, "1.00"); }
@Test public void testDateMinMaxFunctions() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .column(COLUMN_DATE, AggregateFunctionType.MIN) .column(COLUMN_DATE, AggregateFunctionType.MAX) .buildLookup()); assertDataSetValues(result, dataSetFormatter, new String[][]{ {"01/04/12 12:00", "12/11/15 12:00"} }, 0); }
@Test public void testTrim() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .rowNumber(10) .buildLookup()); assertThat(result.getColumns().size()).isEqualTo(6); assertThat(result.getRowCount()).isEqualTo(10); }
@Test public void testColumnMissing() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DEPARTMENT) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test public void testValidationOk() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE).fixed(DateIntervalType.MONTH, true) .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNull(error); }
@Test public void testColumnMissing() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DEPARTMENT) .column(AMOUNT, AggregateFunctionType.SUM) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test(expected = RuntimeException.class) public void testAggregationFunctionByNonExistingColumn() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .group(ExpenseReportsData.COLUMN_DEPARTMENT) .column(ExpenseReportsData.COLUMN_DEPARTMENT, "Department") .column(COUNT, "Occurrences") .column("mycolumn", MIN, "min") .buildLookup()); }
@Test public void testFilterByStringWithPreProcessor() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS + "2") .filter(COLUMN_CITY, equalsTo("Barcelona")) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(0); }
public DataSet lookupGroupByMonthDynamic(boolean emptyIntervals) throws Exception { return dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).dynamic(99, MONTH, emptyIntervals) .column(COLUMN_DATE, "Period") .column(COLUMN_EMPLOYEE, "Employee") .column(COUNT, "Occurrences") .column(COLUMN_AMOUNT, SUM, "totalAmount") .buildLookup()); }
@Test public void testGroupByQuarter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(QUARTER, true).select("1") .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(14); }
@Test public void testFilterLikeToByStringNotAnalyzedAndCaseSensitive() throws Exception { // Case sensitive DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter(ExpenseReportsData.COLUMN_DEPARTMENT, likeTo(ExpenseReportsData.COLUMN_DEPARTMENT, "Sal%", true)) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); assertThat(result.getRowCount()).isEqualTo(8); }
@Test public void testFilterEqualsByStringAnalyzed() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter(ExpenseReportsData.COLUMN_EMPLOYEE, equalsTo(EL_EXAMPLE_EMP_NITA)) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); assertThat(result.getRowCount()).isEqualTo(4); assertDataSetValue(result, 0, 0, "9.00"); assertDataSetValue(result, 3, 0, "12.00"); }