protected List<CoreFunctionType> getAvailableFunctions(CoreFunctionFilter coreFilter) { ColumnType columnType = metadata.getColumnType(coreFilter.getColumnId()); List<CoreFunctionType> functionTypes = CoreFunctionType.getSupportedTypes(columnType); Iterator<CoreFunctionType> it = functionTypes.iterator(); while (it.hasNext()) { CoreFunctionType next = it.next(); if (next.equals(coreFilter.getType())) { it.remove(); } } return functionTypes; }
protected List<CoreFunctionType> getAvailableFunctions(CoreFunctionFilter coreFilter) { ColumnType columnType = metadata.getColumnType(coreFilter.getColumnId()); List<CoreFunctionType> functionTypes = CoreFunctionType.getSupportedTypes(columnType); Iterator<CoreFunctionType> it = functionTypes.iterator(); while (it.hasNext()) { CoreFunctionType next = it.next(); if (next.equals(coreFilter.getType())) { it.remove(); } } return functionTypes; }
@Test public void getSupportedTypeTest() { CoreFunctionType[] dateFunctionTypesUnsupported = {LIKE_TO, IN, NOT_IN}; CoreFunctionType[] textLabelFunctionTypesUnsupported = {TIME_FRAME}; CoreFunctionType[] numericFunctionTypesUnsupported = {LIKE_TO, TIME_FRAME}; assertThat(CoreFunctionType.getSupportedTypes(ColumnType.DATE)) .doesNotContain(dateFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.LABEL)) .doesNotContain(textLabelFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.NUMBER)) .doesNotContain(numericFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.TEXT)) .doesNotContain(textLabelFunctionTypesUnsupported); } }
@Test public void getSupportedTypeTest() { CoreFunctionType[] dateFunctionTypesUnsupported = {LIKE_TO, IN, NOT_IN}; CoreFunctionType[] textLabelFunctionTypesUnsupported = {TIME_FRAME}; CoreFunctionType[] numericFunctionTypesUnsupported = {LIKE_TO, TIME_FRAME}; assertThat(CoreFunctionType.getSupportedTypes(ColumnType.DATE)) .doesNotContain(dateFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.LABEL)) .doesNotContain(textLabelFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.NUMBER)) .doesNotContain(numericFunctionTypesUnsupported); assertThat(CoreFunctionType.getSupportedTypes(ColumnType.TEXT)) .doesNotContain(textLabelFunctionTypesUnsupported); } }
@Test public void testTextParam() { setupEditor(ColumnType.LABEL, CoreFunctionType.EQUALS_TO, "Test"); int n = CoreFunctionType.getSupportedTypes(ColumnType.LABEL).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view, never()).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(textParameterEditor); verify(view).setFunctionSelected("col = Test"); }
@Test public void testNumberParam() throws Exception { double number = 1000.23; NumberFormat numberFormat = NumberFormat.getNumberInstance(); when(view.formatNumber(number)).thenReturn(numberFormat.format(number)); setupEditor(ColumnType.NUMBER, CoreFunctionType.EQUALS_TO, number); int n = CoreFunctionType.getSupportedTypes(ColumnType.NUMBER).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view, never()).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view, never()).addFunctionItem(CoreFunctionType.LIKE_TO); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(numberParameterEditor); verify(view).setFunctionSelected("col = " + numberFormat.format(number)); }
@Test public void testNumberParam() throws Exception { double number = 1000.23; NumberFormat numberFormat = NumberFormat.getNumberInstance(); when(view.formatNumber(number)).thenReturn(numberFormat.format(number)); setupEditor(ColumnType.NUMBER, CoreFunctionType.EQUALS_TO, number); int n = CoreFunctionType.getSupportedTypes(ColumnType.NUMBER).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view, never()).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view, never()).addFunctionItem(CoreFunctionType.LIKE_TO); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(numberParameterEditor); verify(view).setFunctionSelected("col = " + numberFormat.format(number)); }
@Test public void testTextParam() { setupEditor(ColumnType.LABEL, CoreFunctionType.EQUALS_TO, "Test"); int n = CoreFunctionType.getSupportedTypes(ColumnType.LABEL).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view, never()).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(textParameterEditor); verify(view).setFunctionSelected("col = Test"); }
@Test public void testDateParam() throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String dateStr = "23-11-2020 23:59:59"; Date d = dateFormat.parse(dateStr); when(view.formatDate(d)).thenReturn(dateStr); setupEditor(ColumnType.DATE, CoreFunctionType.EQUALS_TO, d); int n = CoreFunctionType.getSupportedTypes(ColumnType.DATE).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view, never()).addFunctionItem(CoreFunctionType.LIKE_TO); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(dateParameterEditor); verify(view).setFunctionSelected("col = " + dateStr); }
@Test public void testDateParam() throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String dateStr = "23-11-2020 23:59:59"; Date d = dateFormat.parse(dateStr); when(view.formatDate(d)).thenReturn(dateStr); setupEditor(ColumnType.DATE, CoreFunctionType.EQUALS_TO, d); int n = CoreFunctionType.getSupportedTypes(ColumnType.DATE).size()-1; verify(view).clearFunctionSelector(); verify(view, times(n)).addFunctionItem(any(CoreFunctionType.class)); verify(view).addFunctionItem(CoreFunctionType.TIME_FRAME); verify(view, never()).addFunctionItem(CoreFunctionType.LIKE_TO); verify(view).clearFilterConfig(); verify(view).addFilterConfigWidget(dateParameterEditor); verify(view).setFunctionSelected("col = " + dateStr); }