Search in sources :

Example 11 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableViewPreferencesIoProviderNGTest method getPreferencesOldVersionWithEmptyEmptySort.

@Test
public void getPreferencesOldVersionWithEmptyEmptySort() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    final List<UserTablePreferences> tablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/old-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("", TableColumn.SortType.ASCENDING));
    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 12 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class PreferenceMenuNGTest method verifySavePreferencesAction.

/**
 * Verifies that when the save userTablePreferences button is pressed then
 * it will call out to
 * {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}.
 * If certain values are not set, then it will not save the preferences and
 * just return.
 * <p/>
 * There is a lot of mock setup for this so the code tries to re-use as much
 * of that as possible which is why its a little weird.
 *
 * @param savePreferencesMenu the save userTablePreferences menu
 * @param isTableViewColumnsEmpty true if when
 * {@link TableView#getColumns()} is called it should return an empty list,
 * false otherwise
 * @param isActivGraphNull true if when
 * {@link GraphManager#getActiveGraph()} is called it should return null,
 * false otherwise
 * @param expectSavePrefsCalled true if it is expected that
 * {@link TableViewPreferencesIoProvider#savePreferences(GraphElementType, TableView, int)}
 * should have been called, false otherwise
 */
private void verifySavePreferencesAction(final MenuItem savePreferencesMenu, final boolean isTableViewColumnsEmpty, final boolean isActivGraphNull, final boolean expectSavePrefsCalled) {
    try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefsIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class);
        final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        final TableView<ObservableList<String>> tableView = mock(TableView.class);
        when(table.getTableView()).thenReturn(tableView);
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setElementType(GraphElementType.VERTEX);
        when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
        final UserTablePreferences userTablePreferences = new UserTablePreferences();
        userTablePreferences.setMaxRowsPerPage(42);
        when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
        final GraphManager graphManager = mock(GraphManager.class);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        final Graph graph = mock(Graph.class);
        final ActionEvent actionEvent = mock(ActionEvent.class);
        if (isTableViewColumnsEmpty) {
            when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList());
        } else {
            when(tableView.getColumns()).thenReturn(FXCollections.observableArrayList(mock(TableColumn.class)));
        }
        if (isActivGraphNull) {
            when(graphManager.getActiveGraph()).thenReturn(null);
        } else {
            when(graphManager.getActiveGraph()).thenReturn(graph);
        }
        savePreferencesMenu.getOnAction().handle(actionEvent);
        if (expectSavePrefsCalled) {
            tablePrefsIOUtilsMockedStatic.verify(() -> TableViewPreferencesIoProvider.savePreferences(GraphElementType.VERTEX, tableView, 42));
        } else {
            tablePrefsIOUtilsMockedStatic.verifyNoInteractions();
        }
        verify(actionEvent).consume();
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ActionEvent(javafx.event.ActionEvent) TableViewPreferencesIoProvider(au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider)

Example 13 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class PreferenceMenuNGTest method loadPreferences.

@Test
public void loadPreferences() {
    try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class)) {
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setElementType(GraphElementType.VERTEX);
        final Graph graph = mock(Graph.class);
        when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
        when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
        // These are the existing table userTablePreferences
        final UserTablePreferences currentTablePreferences = new UserTablePreferences();
        currentTablePreferences.setMaxRowsPerPage(42);
        // There are 4 columns in the table. Set them up and all required variables
        // that describe them
        when(activeTableReference.getUserTablePreferences()).thenReturn(currentTablePreferences);
        final TableView<ObservableList<String>> tableView = mock(TableView.class);
        when(table.getTableView()).thenReturn(tableView);
        final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
        final TableColumn<ObservableList<String>, String> column2 = mock(TableColumn.class);
        final TableColumn<ObservableList<String>, String> column3 = mock(TableColumn.class);
        final TableColumn<ObservableList<String>, String> column4 = mock(TableColumn.class);
        when(column1.getText()).thenReturn("Column1");
        when(column2.getText()).thenReturn("Column2");
        when(column3.getText()).thenReturn("Column3");
        when(column4.getText()).thenReturn("Column4");
        when(tableView.getColumns()).thenReturn(FXCollections.observableList(List.of(column1, column2, column3, column4)));
        final Attribute attribute1 = mock(Attribute.class);
        final Attribute attribute2 = mock(Attribute.class);
        final Attribute attribute3 = mock(Attribute.class);
        final Attribute attribute4 = mock(Attribute.class);
        final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
        columnIndex.add(new Column("type1", attribute1, column1));
        columnIndex.add(new Column("type2", attribute2, column2));
        columnIndex.add(new Column("type3", attribute3, column3));
        columnIndex.add(new Column("type4", attribute4, column4));
        when(table.getColumnIndex()).thenReturn(columnIndex);
        // The loaded userTablePreferences specifies 3 of the 4 columns in the table
        final UserTablePreferences loadedTablePreferences = new UserTablePreferences();
        loadedTablePreferences.setColumnOrder(List.of("Column1", "Column2", "Column4"));
        loadedTablePreferences.setSortByColumn(ImmutablePair.of("Column2", TableColumn.SortType.DESCENDING));
        loadedTablePreferences.setMaxRowsPerPage(150);
        when(activeTableReference.updateVisibleColumns(any(Graph.class), any(TableViewState.class), any(List.class), eq(UpdateMethod.REPLACE))).thenReturn(CompletableFuture.completedFuture(null));
        // Create page size option menu items, with one matching the pages size
        // in the loaded prefs above
        final ToggleGroup toggleGroup = mock(ToggleGroup.class);
        final RadioMenuItem pageSizeOption1 = mock(RadioMenuItem.class);
        final RadioMenuItem pageSizeOption2 = mock(RadioMenuItem.class);
        when(pageSizeOption1.getText()).thenReturn("100");
        when(pageSizeOption2.getText()).thenReturn("150");
        when(preferencesMenu.getPageSizeToggle()).thenReturn(toggleGroup);
        when(toggleGroup.getToggles()).thenReturn(FXCollections.observableList(List.of(pageSizeOption1, pageSizeOption2)));
        // Return the loaded userTablePreferences when the load call is made
        tablePrefIOUtilsMockedStatic.when(() -> TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX)).thenReturn(loadedTablePreferences);
        // Start the test
        preferencesMenu.loadPreferences();
        verify(column1).setVisible(true);
        verify(column2).setVisible(true);
        verify(column3, times(0)).setVisible(anyBoolean());
        verify(column4).setVisible(true);
        verify(activeTableReference).saveSortDetails("Column2", TableColumn.SortType.DESCENDING);
        verify(activeTableReference).updateVisibleColumns(same(graph), same(tableViewState), eq(List.of(Tuple.create("type1", attribute1), Tuple.create("type2", attribute2), Tuple.create("type4", attribute4))), eq(UpdateMethod.REPLACE));
        verify(pageSizeOption1, times(0)).setSelected(true);
        verify(pageSizeOption2, times(1)).setSelected(true);
        assertEquals(150, currentTablePreferences.getMaxRowsPerPage());
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RadioMenuItem(javafx.scene.control.RadioMenuItem) Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ToggleGroup(javafx.scene.control.ToggleGroup) List(java.util.List) ObservableList(javafx.collections.ObservableList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TableViewPreferencesIoProvider(au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 14 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class PreferenceMenuNGTest method loadPreferencesColumnOrderIsEmpty.

@Test
public void loadPreferencesColumnOrderIsEmpty() {
    try (final MockedStatic<TableViewPreferencesIoProvider> tablePrefIOUtilsMockedStatic = Mockito.mockStatic(TableViewPreferencesIoProvider.class)) {
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setElementType(GraphElementType.VERTEX);
        when(tableViewTopComponent.getCurrentState()).thenReturn(tableViewState);
        final UserTablePreferences currentTablePreferences = new UserTablePreferences();
        currentTablePreferences.setMaxRowsPerPage(42);
        when(activeTableReference.getUserTablePreferences()).thenReturn(currentTablePreferences);
        final UserTablePreferences loadedTablePreferences = new UserTablePreferences();
        loadedTablePreferences.setColumnOrder(Collections.emptyList());
        tablePrefIOUtilsMockedStatic.when(() -> TableViewPreferencesIoProvider.getPreferences(GraphElementType.VERTEX)).thenReturn(loadedTablePreferences);
        preferencesMenu.loadPreferences();
        verify(activeTableReference, times(0)).saveSortDetails(anyString(), any(TableColumn.SortType.class));
        verify(activeTableReference, times(0)).updateVisibleColumns(any(Graph.class), any(TableViewState.class), any(List.class), any(UpdateMethod.class));
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) List(java.util.List) ObservableList(javafx.collections.ObservableList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) UpdateMethod(au.gov.asd.tac.constellation.views.tableview.api.UpdateMethod) TableViewPreferencesIoProvider(au.gov.asd.tac.constellation.views.tableview.io.TableViewPreferencesIoProvider) Test(org.testng.annotations.Test)

Example 15 with UserTablePreferences

use of au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences in project constellation by constellation-app.

the class TableViewPreferencesIoProviderNGTest method savePreferences.

@Test
public void savePreferences() throws IOException {
    final TableColumn<ObservableList<String>, ? extends Object> column1 = mock(TableColumn.class);
    final TableColumn<ObservableList<String>, ? extends Object> column2 = mock(TableColumn.class);
    final TableColumn<ObservableList<String>, ? extends Object> column3 = mock(TableColumn.class);
    final TableColumn<ObservableList<String>, ? extends Object> column4 = mock(TableColumn.class);
    when(column1.isVisible()).thenReturn(true);
    when(column1.getText()).thenReturn("ABC");
    when(column2.isVisible()).thenReturn(true);
    when(column2.getText()).thenReturn("DEF");
    when(column2.getSortType()).thenReturn(TableColumn.SortType.ASCENDING);
    when(column3.isVisible()).thenReturn(false);
    when(column3.getText()).thenReturn("GHI");
    when(column4.isVisible()).thenReturn(true);
    when(column4.getText()).thenReturn("JKL");
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(tableView.getColumns()).thenReturn(FXCollections.observableList(List.of(column1, column2, column3, column4)));
    when(tableView.getSortOrder()).thenReturn(FXCollections.observableList(List.of(column2)));
    TableViewPreferencesIoProvider.savePreferences(GraphElementType.TRANSACTION, tableView, 5);
    final ObjectMapper objectMapper = new ObjectMapper();
    final List<UserTablePreferences> expectedTablePrefs = objectMapper.readValue(new FileInputStream(getClass().getResource("resources/transaction-preferences.json").getPath()), new TypeReference<List<UserTablePreferences>>() {
    });
    jsonIOStaticMock.verify(() -> JsonIO.saveJsonPreferences(eq(Optional.of("TableViewPreferences")), eq(Optional.of("transaction-")), eq(expectedTablePrefs)));
}
Also used : UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) List(java.util.List) ObservableList(javafx.collections.ObservableList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) 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