Search in sources :

Example 16 with UserTablePreferences

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);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) List(java.util.List) ObservableList(javafx.collections.ObservableList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 17 with UserTablePreferences

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);
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) List(java.util.List) ObservableList(javafx.collections.ObservableList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 18 with UserTablePreferences

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);
}
Also used : Pagination(javafx.scene.control.Pagination) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) Test(org.testng.annotations.Test)

Example 19 with UserTablePreferences

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);
}
Also used : SortedList(javafx.collections.transformation.SortedList) CountDownLatch(java.util.concurrent.CountDownLatch) BiPredicate(java.util.function.BiPredicate) Predicate(java.util.function.Predicate) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) TableFilter(org.controlsfx.control.table.TableFilter) ObservableList(javafx.collections.ObservableList) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) BiPredicate(java.util.function.BiPredicate) Test(org.testng.annotations.Test)

Example 20 with UserTablePreferences

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);
}
Also used : Pagination(javafx.scene.control.Pagination) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) Test(org.testng.annotations.Test)

Aggregations

UserTablePreferences (au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences)21 ObservableList (javafx.collections.ObservableList)15 Test (org.testng.annotations.Test)14 List (java.util.List)9 Pagination (javafx.scene.control.Pagination)6 Graph (au.gov.asd.tac.constellation.graph.Graph)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 ActionEvent (javafx.event.ActionEvent)5 TableViewPreferencesIoProvider (au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 FileInputStream (java.io.FileInputStream)4 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)3 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TableColumn (javafx.scene.control.TableColumn)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)2 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)2 UpdateMethod (au.gov.asd.tac.constellation.views.tableview.api.UpdateMethod)2 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)2