Search in sources :

Example 41 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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 42 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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 43 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableNGTest method updateDataThreadInterrupted.

@Test
public void updateDataThreadInterrupted() {
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.TRANSACTION);
    tableViewState.setSelectedOnly(false);
    final BorderPane progressPane = mock(BorderPane.class);
    final ProgressBar progressBar = mock(ProgressBar.class);
    when(progressBar.getProgressPane()).thenReturn(progressPane);
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    doReturn(new HashMap<>()).when(activeTableReference).getElementIdToRowIndex();
    doReturn(new HashMap<>()).when(activeTableReference).getRowToElementIdIndex();
    when(readableGraph.getTransactionCount()).thenReturn(0);
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        Thread.currentThread().interrupt();
        table.updateData(graph, tableViewState, progressBar);
        assertTrue(Thread.currentThread().isInterrupted());
        platformMockedStatic.verify(() -> Platform.runLater(any(UpdateDataTask.class)), times(0));
    }
    // Clears interrupt status
    Thread.interrupted();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) BorderPane(javafx.scene.layout.BorderPane) Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 44 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableNGTest method updateColumnsOnSwingThread.

@Test(expectedExceptions = IllegalStateException.class)
public void updateColumnsOnSwingThread() {
    try (final MockedStatic<SwingUtilities> swingUtilsMockedStatic = Mockito.mockStatic(SwingUtilities.class)) {
        swingUtilsMockedStatic.when(SwingUtilities::isEventDispatchThread).thenReturn(true);
        table.updateColumns(graph, new TableViewState());
    }
}
Also used : TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) SwingUtilities(javax.swing.SwingUtilities) Test(org.testng.annotations.Test)

Example 45 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableNGTest method updateColumnsStateColumnsNotSet.

@Test
public void updateColumnsStateColumnsNotSet() {
    final ChangeListener<ObservableList<String>> tableSelectionListener = mock(ChangeListener.class);
    final ListChangeListener selectedOnlySelectionListener = mock(ListChangeListener.class);
    doReturn(tableSelectionListener).when(table).getTableSelectionListener();
    doReturn(selectedOnlySelectionListener).when(table).getSelectedOnlySelectionListener();
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    // Set up the initial column index.
    final String columnType1 = "source.";
    final Attribute attribute1 = mock(Attribute.class);
    final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
    when(column1.getText()).thenReturn("source.COLUMN_A");
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(columnType1, attribute1, column1));
    when(activeTableReference.getColumnIndex()).thenReturn(columnIndex);
    // This is a reference of the old column index that will be used whilst the new
    // index is being created. Because that creation is mocked this is used only as a
    // vertification that the parameter is being correctly constructed.
    final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = Map.of("source.COLUMN_A", column1);
    // Mock out the re-population of the column index from the graph
    final CopyOnWriteArrayList<ThreeTuple<String, Attribute, TableColumn<ObservableList<String>, String>>> sourceColumnIndex = new CopyOnWriteArrayList<>();
    sourceColumnIndex.add(ThreeTuple.create(columnType1, attribute1, column1));
    doReturn(sourceColumnIndex).when(table).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "source.", columnReferenceMap);
    // Set up the table state
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.VERTEX);
    // When this is null, the update is interrupted and the user is asked to select
    // which columns they want visible
    tableViewState.setColumnAttributes(null);
    // Don't want it trying to open the menu to select which columns to show
    doNothing().when(table).openColumnVisibilityMenu();
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(false);
        platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).then(mockInvocation -> {
            assertTrue(mockInvocation.getArgument(0) instanceof UpdateColumnsTask);
            return null;
        });
        table.updateColumns(graph, tableViewState);
    }
    // Verify the new column index
    final CopyOnWriteArrayList<ThreeTuple<String, Attribute, TableColumn<ObservableList<String>, String>>> expectedColumnIndex = new CopyOnWriteArrayList<>();
    expectedColumnIndex.add(ThreeTuple.create(columnType1, attribute1, column1));
    assertEquals(expectedColumnIndex, columnIndex);
    // Because the state element type is set to vertex, only the source columns are populated
    verify(table, times(0)).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "destination.", columnReferenceMap);
    verify(table, times(0)).createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, "transaction.", columnReferenceMap);
    // Verify the menu open method was called
    verify(table).openColumnVisibilityMenu();
    // Verify that the new column index did not have its factories set
    verify(column1, times(0)).setCellValueFactory(any(Callback.class));
    verify(column1, times(0)).setCellFactory(any(Callback.class));
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Platform(javafx.application.Platform) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) UpdateColumnsTask(au.gov.asd.tac.constellation.views.tableview.tasks.UpdateColumnsTask) TableColumn(javafx.scene.control.TableColumn) ListChangeListener(javafx.collections.ListChangeListener) Callback(javafx.util.Callback) 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) ThreeTuple(au.gov.asd.tac.constellation.utilities.datastructure.ThreeTuple) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Aggregations

TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)65 Test (org.testng.annotations.Test)50 Graph (au.gov.asd.tac.constellation.graph.Graph)24 Platform (javafx.application.Platform)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)14 ObservableList (javafx.collections.ObservableList)14 Attribute (au.gov.asd.tac.constellation.graph.Attribute)13 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)12 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)10 TableColumn (javafx.scene.control.TableColumn)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)7 ListChangeListener (javafx.collections.ListChangeListener)7 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)6 TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)5 ArrayList (java.util.ArrayList)5