Search in sources :

Example 21 with TableViewState

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

the class TableNGTest method updateSelectionThreadInterrupted.

@Test
public void updateSelectionThreadInterrupted() {
    try (MockedStatic<TableViewUtilities> tableUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class);
        final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        final TableViewState tableViewState = new TableViewState();
        tableViewState.setSelectedOnly(false);
        when(activeTableReference.getElementIdToRowIndex()).thenReturn(Map.of());
        tableUtilsMockedStatic.when(() -> TableViewUtilities.getSelectedIds(graph, tableViewState)).thenReturn(List.of());
        Thread.currentThread().interrupt();
        table.updateSelection(graph, tableViewState);
        assertTrue(Thread.currentThread().isInterrupted());
        // Clears the current threads interrupt status
        Thread.interrupted();
        platformMockedStatic.verify(() -> Platform.runLater(any(Runnable.class)), times(0));
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) Test(org.testng.annotations.Test)

Example 22 with TableViewState

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

the class TableNGTest method updateSelectionOnSwingThread.

@Test(expectedExceptions = IllegalStateException.class)
public void updateSelectionOnSwingThread() {
    try (final MockedStatic<SwingUtilities> swingUtilsMockedStatic = Mockito.mockStatic(SwingUtilities.class)) {
        swingUtilsMockedStatic.when(SwingUtilities::isEventDispatchThread).thenReturn(true);
        table.updateSelection(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 23 with TableViewState

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

the class TableNGTest method updateSelectionNotInSelectedOnlyMode.

@Test
public void updateSelectionNotInSelectedOnlyMode() throws InterruptedException {
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setSelectedOnly(false);
    tableViewState.setElementType(GraphElementType.VERTEX);
    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 ObservableList<String> vertex1 = FXCollections.observableList(List.of("Vertex1Attr1", "Vertex1Attr2"));
    final ObservableList<String> vertex2 = FXCollections.observableList(List.of("Vertex2Attr1", "Vertex2Attr2"));
    final ObservableList<String> vertex3 = FXCollections.observableList(List.of("Vertex3Attr1", "Vertex3Attr2"));
    when(activeTableReference.getElementIdToRowIndex()).thenReturn(Map.of(100, vertex1, 102, vertex2, 103, vertex3));
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    when(table.getTableView()).thenReturn(tableView);
    // Order is important here. Should match on vertex 1 and 2, so indicies 0 and 2.
    when(tableView.getItems()).thenReturn(FXCollections.observableList(List.of(vertex1, vertex3, vertex2)));
    final TableViewSelectionModel<ObservableList<String>> selectionModel = mock(TableViewSelectionModel.class);
    when(tableView.getSelectionModel()).thenReturn(selectionModel);
    final ObservableList<ObservableList<String>> selectedItems = mock(ObservableList.class);
    when(selectionModel.getSelectedItems()).thenReturn(selectedItems);
    final ReadOnlyObjectProperty<ObservableList<String>> selectedProperty = mock(ReadOnlyObjectProperty.class);
    when(table.getSelectedProperty()).thenReturn(selectedProperty);
    try (MockedStatic<TableViewUtilities> tableUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
        tableUtilsMockedStatic.when(() -> TableViewUtilities.getSelectedIds(graph, tableViewState)).thenReturn(List.of(100, 102));
        table.updateSelection(graph, tableViewState);
    }
    final CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> latch.countDown());
    latch.await();
    verify(selectedProperty).removeListener(tableSelectionListener);
    verify(selectedItems).removeListener(selectedOnlySelectionListener);
    verify(selectionModel).clearSelection();
    verify(selectionModel).selectIndices(0, 0, 2);
    verify(selectedProperty).addListener(tableSelectionListener);
    verify(selectedItems).addListener(selectedOnlySelectionListener);
}
Also used : TableViewUtilities(au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities) CountDownLatch(java.util.concurrent.CountDownLatch) ListChangeListener(javafx.collections.ListChangeListener) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Test(org.testng.annotations.Test)

Example 24 with TableViewState

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

the class TableNGTest method updateColumns.

@Test
public void updateColumns() {
    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. Column 4 will not be found in the graph and
    // dropped in the column index created by the update call
    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 String columnType2 = "destination.";
    final Attribute attribute2 = mock(Attribute.class);
    final TableColumn<ObservableList<String>, String> column2 = mock(TableColumn.class);
    when(column2.getText()).thenReturn("destination.COLUMN_A");
    final String columnType3 = "transaction.";
    final Attribute attribute3 = mock(Attribute.class);
    final TableColumn<ObservableList<String>, String> column3 = mock(TableColumn.class);
    when(column3.getText()).thenReturn("transaction.COLUMN_B");
    final String columnType4 = "source.";
    final Attribute attribute4 = mock(Attribute.class);
    final TableColumn<ObservableList<String>, String> column4 = mock(TableColumn.class);
    when(column4.getText()).thenReturn("source.COLUMN_C");
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(columnType1, attribute1, column1));
    columnIndex.add(new Column(columnType2, attribute2, column2));
    columnIndex.add(new Column(columnType3, attribute3, column3));
    columnIndex.add(new Column(columnType4, attribute4, column4));
    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, "destination.COLUMN_A", column2, "transaction.COLUMN_B", column3, "source.COLUMN_C", column4);
    // Mock out the re-population of the column index from the graph. This excludes column 4.
    final CopyOnWriteArrayList<Column> sourceColumnIndex = new CopyOnWriteArrayList<>();
    sourceColumnIndex.add(new Column(columnType1, attribute1, column1));
    final CopyOnWriteArrayList<Column> destinationColumnIndex = new CopyOnWriteArrayList<>();
    destinationColumnIndex.add(new Column(columnType2, attribute2, column2));
    final CopyOnWriteArrayList<Column> transactionColumnIndex = new CopyOnWriteArrayList<>();
    transactionColumnIndex.add(new Column(columnType3, attribute3, column3));
    doReturn(sourceColumnIndex).when(table).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "source.", columnReferenceMap);
    doReturn(destinationColumnIndex).when(table).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "destination.", columnReferenceMap);
    doReturn(transactionColumnIndex).when(table).createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, "transaction.", columnReferenceMap);
    // Set up the table state
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.TRANSACTION);
    // This is used by the sort comparator. This will order the columnIndex
    // in a certain way that we can then verify below
    tableViewState.setColumnAttributes(List.of(Tuple.create("source.", attribute1), Tuple.create("transaction.", attribute3), Tuple.create("destination.", attribute2)));
    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<Column> expectedColumnIndex = new CopyOnWriteArrayList<>();
    expectedColumnIndex.add(new Column(columnType1, attribute1, column1));
    expectedColumnIndex.add(new Column(columnType3, attribute3, column3));
    expectedColumnIndex.add(new Column(columnType2, attribute2, column2));
    assertEquals(expectedColumnIndex, columnIndex);
    verify(column1, times(1)).setCellValueFactory(any(Callback.class));
    verify(column2, times(1)).setCellValueFactory(any(Callback.class));
    verify(column3, times(1)).setCellValueFactory(any(Callback.class));
    verify(column1, times(1)).setCellFactory(any(Callback.class));
    verify(column2, times(1)).setCellFactory(any(Callback.class));
    verify(column3, times(1)).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) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 25 with TableViewState

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

the class TableNGTest method updateDataOnFxThread.

@Test(expectedExceptions = IllegalStateException.class)
public void updateDataOnFxThread() {
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(true);
        table.updateData(graph, new TableViewState(), null);
    }
}
Also used : Platform(javafx.application.Platform) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) 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