use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProviderNGTest method getPreferencesMultiplePrefsPicksLast.
@Test
public void getPreferencesMultiplePrefsPicksLast() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
final List<UserTablePreferences> tablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/vertex-preferences.json").getPath()), new TypeReference<List<UserTablePreferences>>() {
});
jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("vertex-")), any(TypeReference.class))).thenReturn(tablePrefs);
final UserTablePreferences tablePreferences = TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX);
final UserTablePreferences expected = new UserTablePreferences();
expected.setColumnOrder(List.of("ABC", "DEF"));
expected.setSortByColumn(ImmutablePair.of("DEF", TableColumn.SortType.DESCENDING));
expected.setMaxRowsPerPage(500);
assertEquals(expected, tablePreferences);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableViewPreferencesIoProviderNGTest method getPreferencesSinglePreference.
@Test
public void getPreferencesSinglePreference() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
final List<UserTablePreferences> tablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/transaction-preferences.json").getPath()), new TypeReference<List<UserTablePreferences>>() {
});
jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("transaction-")), any(TypeReference.class))).thenReturn(tablePrefs);
final UserTablePreferences tablepreferences = TableViewPreferencesIoProvider.getPreferences(GraphElementType.TRANSACTION);
final UserTablePreferences expected = new UserTablePreferences();
expected.setColumnOrder(List.of("ABC", "DEF", "JKL"));
expected.setSortByColumn(ImmutablePair.of("DEF", TableColumn.SortType.ASCENDING));
expected.setMaxRowsPerPage(5);
assertEquals(expected, tablepreferences);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableComparatorListenerNGTest method changedListenerInActive.
@Test
public void changedListenerInActive() throws InterruptedException {
final int maxRowsPerPage = 5;
activeTableReference.setSortingListenerActive(false);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(maxRowsPerPage);
activeTableReference.setUserTablePreferences(userTablePreferences);
final Pagination pagination = mock(Pagination.class);
when(activeTableReference.getPagination()).thenReturn(pagination);
Mockito.doAnswer(mockInvocation -> {
// This verifies then when update pagination is called, the
// sortingListenerActive flag is true
assertTrue(activeTableReference.isSortingListenerActive());
return pagination;
}).when(activeTableReference).updatePagination(maxRowsPerPage, tablePane);
tableComparatorListener.changed(null, null, null);
// Once the listener is complete the flag should be returned to false.
assertFalse(activeTableReference.isSortingListenerActive());
verify(activeTableReference).updatePagination(maxRowsPerPage, tablePane);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class UpdateDataTaskNGTest method runTableUpdated.
@Test
public void runTableUpdated() throws InterruptedException {
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(42);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final TableFilter.Builder filterBuilder = mock(TableFilter.Builder.class);
final TableFilter<ObservableList<String>> filter = mock(TableFilter.class);
final FilteredList<ObservableList<String>> filteredList = mock(FilteredList.class);
final ObjectProperty<Predicate<? super ObservableList<String>>> filterPredicateProperty = mock(ObjectProperty.class);
when(filter.getFilteredList()).thenReturn(filteredList);
when(filteredList.predicateProperty()).thenReturn(filterPredicateProperty);
try (final MockedStatic<TableFilter> tableFilterMockedStatic = Mockito.mockStatic(TableFilter.class)) {
tableFilterMockedStatic.when(() -> TableFilter.forTableView(tableView)).thenReturn(filterBuilder);
when(filterBuilder.lazy(true)).thenReturn(filterBuilder);
when(filterBuilder.apply()).thenReturn(filter);
updateDataTask.run();
}
// Wait for any JavaFX work to complete
final CountDownLatch countDownLatch = new CountDownLatch(1);
Platform.runLater(() -> countDownLatch.countDown());
countDownLatch.await();
// Verify listeners removed and the new rows are added to the table
verify(selectedItemProperty).removeListener(tableSelectionListener);
verify(selectedItems).removeListener(selectedOnlySelectionListener);
final SortedList<ObservableList<String>> newRowList = new SortedList<>(FXCollections.observableList(rows));
assertEquals(newRowList, activeTableReference.getSortedRowList());
verify(tableView).setItems(newRowList);
// Verify a new filter is created for the table
final ArgumentCaptor<BiPredicate<String, String>> filterStrategyCaptor = ArgumentCaptor.forClass(BiPredicate.class);
verify(filter).setSearchStrategy(filterStrategyCaptor.capture());
assertTrue(filterStrategyCaptor.getValue().test("ABC", "abcdefg"));
assertFalse(filterStrategyCaptor.getValue().test("DEF", "abcdefg"));
// Verify the table is updated with changes and listeners re-applied
verify(activeTableReference).updatePagination(42, newRowList, tablePane);
verify(selectedItemProperty).addListener(tableSelectionListener);
verify(selectedItems).addListener(selectedOnlySelectionListener);
// Verify the count down latch passed into the constructor has counted down
assertEquals(0, updateDataTask.getUpdateDataLatch().getCount());
// Extract the filter listener and verify its behaviour
final ArgumentCaptor<ChangeListener<? super Predicate<? super ObservableList<String>>>> filterListenerCaptor = ArgumentCaptor.forClass(ChangeListener.class);
verify(filterPredicateProperty).addListener(filterListenerCaptor.capture());
// Clear the mock invocation counts for clarity and simplicity
clearInvocations(activeTableReference, tablePane);
final Predicate predicate = mock(Predicate.class);
when(filteredList.getPredicate()).thenReturn(predicate);
// Invoke the listener
filterListenerCaptor.getValue().changed(null, null, null);
// Wait for any JavaFX work to complete
final CountDownLatch listenerCountDownLatch = new CountDownLatch(1);
Platform.runLater(() -> listenerCountDownLatch.countDown());
listenerCountDownLatch.await();
verify(activeTableReference).setSortedRowList(new SortedList<>(FXCollections.observableArrayList(new FilteredList<>(FXCollections.observableArrayList(rows), predicate))));
verify(activeTableReference).updatePagination(42, new SortedList<>(FXCollections.observableArrayList(new FilteredList<>(FXCollections.observableArrayList(rows), predicate))), tablePane);
}
use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.
the class TableSortTypeListenerNGTest method changedListenerInActive.
@Test
public void changedListenerInActive() throws InterruptedException {
final int maxRowsPerPage = 5;
activeTableReference.setSortingListenerActive(false);
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(maxRowsPerPage);
activeTableReference.setUserTablePreferences(userTablePreferences);
final Pagination pagination = mock(Pagination.class);
when(activeTableReference.getPagination()).thenReturn(pagination);
Mockito.doAnswer(mockInvocation -> {
// This verifies then when update pagination is called, the
// sortingListenerActive flag is true
assertTrue(activeTableReference.isSortingListenerActive());
return pagination;
}).when(activeTableReference).updatePagination(maxRowsPerPage, tablePane);
tableSortTypeListener.changed(null, null, null);
// Once the listener is complete the flag should be returned to false.
assertFalse(activeTableReference.isSortingListenerActive());
verify(activeTableReference).updatePagination(maxRowsPerPage, tablePane);
}
Aggregations