/** * Check if some data set rows match a given result. * @param dataSet The data set to validate. * @param x The x position of the cell to check (starting at 0). * @param y The y position of the cell to check (starting at 0). * @param expected The expected value in the given cell. */ public static void assertDataSetValue(DataSet dataSet, int x, int y, String expected) { assertDataSetValue(dataSet, new DataSetFormatter(), x, y, expected); }
/** * Check if some data set rows match a given result. * @param dataSet The data set to validate. * @param x The x position of the cell to check (starting at 0). * @param y The y position of the cell to check (starting at 0). * @param expected The expected value in the given cell. */ public static void assertDataSetValue(DataSet dataSet, int x, int y, String expected) { assertDataSetValue(dataSet, new DataSetFormatter(), x, y, expected); }
@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 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 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 testSortByDate() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.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 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 testORExpression() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(COLUMN_AMOUNT, OR(NOT(greaterThan(100)), greaterThan(1000), equalsTo(COLUMN_ID, 1))) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(8); assertDataSetValue(result, 0, 0, "1.00"); assertDataSetValue(result, 1, 0, "2.00"); assertDataSetValue(result, 7, 0, "30.00"); }
@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 testInOperator() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(in(COLUMN_CITY, Arrays.asList("Barcelona", "Madrid"))) .column(COLUMN_ID) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(12); assertDataSetValue(result, 0, 0, "1.00"); assertDataSetValue(result, 5, 0, "6.00"); }
@Test public void testNotInOperator() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .filter(notIn(COLUMN_CITY, Arrays.asList("Barcelona", "Madrid"))) .column(COLUMN_ID) .sort(COLUMN_ID, SortOrder.ASCENDING) .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(38); assertDataSetValue(result, 0, 0, "13.00"); assertDataSetValue(result, 5, 0, "18.00"); }
@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( 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 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( 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 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 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 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 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"); }