@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 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 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 public void testFilterByString() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_CITY, equalsTo("Barcelona")) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(6); assertDataSetValue(result, 0, 0, "1.00"); assertDataSetValue(result, 5, 0, "6.00"); }
@Test public void testANDExpression() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, AND(greaterThan(100), lowerThan(150))) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "1.00"); }
@Test(expected = RuntimeException.class) public void testFilterByNonExistingColumn() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter("myfield", greaterOrEqualsTo(1000)) .buildLookup()); }
@Test public void testFilterMultiple2() throws Exception { // The order of the filter criteria does not alter the result. DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter(ExpenseReportsData.COLUMN_CITY, notEqualsTo(EL_EXAMPLE_CITY_BARCELONA)) .filter(ExpenseReportsData.COLUMN_AMOUNT, greaterOrEqualsTo(1000)) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "15.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 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 testGroupSelectionFilter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, FilterFactory.greaterThan(500)) .group(COLUMN_DEPARTMENT).select("Engineering") .group(COLUMN_CITY).select("Westford") .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "26.00"); }
@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 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"); }
@Test public void testFilterByString() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_CITY, equalsTo("Barcelona")) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(6); assertDataSetValue(result, 0, 0, "1.00"); assertDataSetValue(result, 5, 0, "6.00"); }
@Test public void testANDExpression() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EL_DATASET_UUID) .filter(ExpenseReportsData.COLUMN_AMOUNT, AND(greaterThan(100), lowerThan(150))) .sort(ExpenseReportsData.COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "1.00"); }
@Test public void testANDExpression() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, AND(greaterThan(100), lowerThan(150))) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "1.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); }
@Test public void testNOTExpression() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, NOT(greaterThan(100))) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(5); assertDataSetValue(result, 0, 0, "9.00"); assertDataSetValue(result, 4, 0, "30.00"); }
@Test public void testGroupSelectionFilter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, FilterFactory.greaterThan(500)) .group(COLUMN_DEPARTMENT).select("Engineering") .group(COLUMN_CITY).select("Westford") .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(1); assertDataSetValue(result, 0, 0, "26.00"); }