@Test public void testFirstDayOfMonthOk() throws Exception { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(MONTH, true) .firstMonth(Month.APRIL); }
@Test public void testFixedIntervalsSupported() throws Exception { for (DateIntervalType type : DateIntervalType.values()) { try { DataSetLookupFactory.newDataSetLookupBuilder().group(COLUMN_DATE).fixed(type, true); if (!DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Missing exception on a not supported fixed interval: " + type); } } catch (Exception e) { if (DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Exception on a supported fixed interval: " + type); } } } }
@Test public void testFixedIntervalsSupported() throws Exception { for (DateIntervalType type : DateIntervalType.values()) { try { DataSetLookupFactory.newDataSetLookupBuilder().group(COLUMN_DATE).fixed(type, true); if (!DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Missing exception on a not supported fixed interval: " + type); } } catch (Exception e) { if (DateIntervalType.FIXED_INTERVALS_SUPPORTED.contains(type)) { fail("Exception on a supported fixed interval: " + type); } } } }
@Test public void testFirstDayOfWeekOk() throws Exception { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(DAY_OF_WEEK, true) .firstDay(DayOfWeek.MONDAY); }
@Test public void testFirstDayOfMonthOk() throws Exception { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(MONTH, true) .firstMonth(Month.APRIL); }
@Test public void testFirstDayOfWeekOk() throws Exception { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(DAY_OF_WEEK, true) .firstDay(DayOfWeek.MONDAY); }
@Test public void testGroupByQuarter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(QUARTER, true).select("1") .buildLookup()); //printDataSet(result); assertThat(result.getRowCount()).isEqualTo(14); }
@Test public void testFirstDayOfWeekNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstDay(DayOfWeek.MONDAY); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
@Test public void testFirstDayOfMonthNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstMonth(Month.APRIL); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
@Test public void testFirstDayOfWeekNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstDay(DayOfWeek.MONDAY); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
@Test public void testFirstDayOfMonthNok() throws Exception { try { DataSetLookupFactory.newDataSetLookupBuilder() .group(COLUMN_DATE) .fixed(QUARTER, true) .firstMonth(Month.APRIL); fail("firstDayOfWeek required a DAY_OF_WEEK fixed domain."); } catch (Exception e) { // Expected. } }
@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 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 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 testColumnExcess() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE).fixed(DateIntervalType.MONTH, true) .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .column(AMOUNT, AggregateFunctionType.AVERAGE) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test public void testColumnExcess() { DataSetLookup lookup = DataSetLookupFactory.newDataSetLookupBuilder() .group(DATE).fixed(DateIntervalType.MONTH, true) .column(DATE) .column(AMOUNT, AggregateFunctionType.SUM) .column(AMOUNT, AggregateFunctionType.AVERAGE) .buildLookup(); ValidationError error = TWO_COLUMNS_GROUPED.check(lookup, METADATA); assertNotNull(error); assertEquals(error.getCode(), DataSetLookupConstraints.ERROR_COLUMN_NUMBER); }
@Test public void testGroupByQuarter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(QUARTER, true) .column(COLUMN_DATE, "Period") .column(COUNT, "Occurrences") .column(COLUMN_AMOUNT, SUM, "totalAmount") .buildLookup()); //printDataSet(result); assertDataSetValues(result, dataSetFormatter, new String[][]{ {"1", "14.00", "6,222.32"}, {"2", "17.00", "7,678.27"}, {"3", "9.00", "3,499.64"}, {"4", "10.00", "5,331.03"} }, 0); }
@Test public void testGroupByQuarter() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(QUARTER, true) .column(COLUMN_DATE, "Period") .column(COUNT, "Occurrences") .column(COLUMN_AMOUNT, SUM, "totalAmount") .buildLookup()); //printDataSet(result); assertDataSetValues(result, dataSetFormatter, new String[][]{ {"1", "14.00", "6,222.32"}, {"2", "17.00", "7,678.27"}, {"3", "9.00", "3,499.64"}, {"4", "10.00", "5,331.03"} }, 0); }
@Test public void testGroupByDayOfWeekFixed() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(DAY_OF_WEEK, true).firstDay(DayOfWeek.MONDAY) .column(COLUMN_DATE, "Period") .column(COUNT, "Occurrences") .column(COLUMN_AMOUNT, SUM, "totalAmount") .buildLookup()); // printDataSet(result); assertDataSetValues(result, dataSetFormatter, new String[][]{ {"2", "10.00", "3,904.17"}, {"3", "8.00", "4,525.69"}, {"4", "7.00", "4,303.14"}, {"5", "4.00", "1,021.95"}, {"6", "8.00", "3,099.08"}, {"7", "5.00", "2,012.05"}, {"1", "8.00", "3,865.18"} }, 0); }
@Test public void testGroupByDayOfWeekFixed() throws Exception { DataSet result = dataSetManager.lookupDataSet( DataSetLookupFactory.newDataSetLookupBuilder() .dataset(EXPENSE_REPORTS) .group(COLUMN_DATE).fixed(DAY_OF_WEEK, true).firstDay(DayOfWeek.MONDAY) .column(COLUMN_DATE, "Period") .column(COUNT, "Occurrences") .column(COLUMN_AMOUNT, SUM, "totalAmount") .buildLookup()); // printDataSet(result); assertDataSetValues(result, dataSetFormatter, new String[][]{ {"2", "10.00", "3,904.17"}, {"3", "8.00", "4,525.69"}, {"4", "7.00", "4,303.14"}, {"5", "4.00", "1,021.95"}, {"6", "8.00", "3,099.08"}, {"7", "5.00", "2,012.05"}, {"1", "8.00", "3,865.18"} }, 0); }