DataSetLookupEditor implements IsWidget { public void init(DataSetLookupConstraints lookupConstraints, final DataSetLookup dataSetLookup) { this.dataSetLookup = dataSetLookup; this.lookupConstraints = lookupConstraints; this.view.clearAll(); this.clientServices.getPublicDataSetDefs(new RemoteCallback<List<DataSetDef>>() { public void callback(List<DataSetDef> dataSetDefs) { showDataSetDefs(dataSetDefs); if (dataSetLookup != null && dataSetLookup.getDataSetUUID() != null) { fetchMetadata(dataSetLookup.getDataSetUUID(), new RemoteCallback<DataSetMetadata>() { public void callback(DataSetMetadata metadata) { updateDataSetLookup(); } }); } } }); } @Inject  DataSetLookupEditor(final View view,
                               SyncBeanManager beanManager,
                               DataSetFilterEditor filterEditor,
                               DataSetGroupDateEditor groupDateEditor,
                               DataSetClientServices clientServices,
                               Event<DataSetLookupChangedEvent> event); void init(DataSetLookupConstraints lookupConstraints,
                     final DataSetLookup dataSetLookup); @Override Widget asWidget(); View getView(); DataSetFilterEditor getFilterEditor(); DataSetGroupDateEditor getGroupDateEditor(); DataSetLookup getDataSetLookup(); DataSetLookupConstraints getLookupConstraints(); void setDataSetDefFilter(DataSetDefFilter dataSetDefFilter); String getDataSetUUID(); String getColumnId(int index); ColumnType getColumnType(int index); ColumnType getColumnType(String columnId); DataSetGroup getFirstGroupOp(); boolean isFirstGroupOpDateBased(); List<GroupFunction> getFirstGroupFunctions(); int getFirstGroupFunctionIdx(GroupFunction gf); String getFirstGroupColumnId(); List<Integer> getAvailableGroupColumnIdxs(); void showDataSetDefs(List<DataSetDef> ds); void addDataSetDef(DataSetDef def); void removeDataSetDef(DataSetDef def);  }
@Test public void testNonExistingLookup() { presenter.init(DATA_2D_FIXED, null); verify(view).clearDataSetSelector(); verify(view).enableDataSetSelectorHint(); verify(view).addDataSetItem("Population", POPULATION_UUID); verify(view).addDataSetItem("Revenue", REVENUE_UUID); verify(view, never()).setSelectedDataSetIndex(anyInt()); verify(view, never()).setFilterEnabled(true); verify(view, never()).setGroupEnabled(true); verify(view, never()).setColumnsSectionEnabled(true); verify(view, never()).setAddColumnOptionEnabled(true); }
@Test public void testFromNonExistingLookup() { presenter.init(DATA_2D_FIXED, DataSetLookupFactory.newDataSetLookupBuilder() .dataset(POPULATION_UUID) .filter(greaterThan(100)) .group("country") .column("country", "Country") .column("population", AggregateFunctionType.SUM, "Total") .buildLookup()); verify(view, never()).enableDataSetSelectorHint(); reset(view); presenter.init(DATA_2D_FIXED, null); verify(view).enableDataSetSelectorHint(); }
@Test public void testDateGroup() { presenter.init(DATA_2D_FIXED, DataSetLookupFactory.newDataSetLookupBuilder() .dataset(POPULATION_UUID) .filter(greaterThan(100)) .group("year") .column("year", "Year") .column("population", AggregateFunctionType.SUM, "Total") .buildLookup()); verify(view).setGroupEnabled(true); verify(view).setGroupByDateEnabled(true); verify(view, never()).enableGroupColumnSelectorHint(); verify(groupDateEditor).init(any(ColumnGroup.class)); }
@Test public void testGroupAllowed() { presenter.init(DATA_MULTIPLE, DataSetLookupFactory.newDataSetLookupBuilder() .dataset(POPULATION_UUID) .column("year") .column("population") .buildLookup()); verify(view).setGroupEnabled(true); verify(view).enableGroupColumnSelectorHint(); verify(view).setAddColumnOptionEnabled(true); verify(event, never()).fire(any(DataSetLookupChangedEvent.class)); }
@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)); }