@Test public void testLoadDataSet() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(50); assertThat(result.getColumns().size()).isEqualTo(6); }
@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); }
@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 testSortByNumber() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.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 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(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 testEmptyConstraints() throws Exception { DataSetLookupConstraints constraints = new DataSetLookupConstraints() .setColumnTypes(null) .setGroupRequired(false); DataSetLookup lookup = constraints.newDataSetLookup(dataSet.getMetadata()); assertThat(constraints.check(lookup)).isNull(); DataSet result = dataSetManager.lookupDataSet(lookup); assertThat(result.getColumns().size()).isEqualTo(6); assertThat(result.getRowCount()).isEqualTo(50); }
@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"); }
@Test public void testAggregationAndFilterByNonAnalyzedField() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .column(COUNT, "#items") .filter(ExpenseReportsData.COLUMN_DEPARTMENT, equalsTo(EL_EXAMPLE_DEPT_ENGINEERING)) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); assertThat(result.getRowCount()).isEqualTo(1); assertThat(result.getValueAt(0, 0)).isEqualTo(19d); }