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));
}
}
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());
}
}
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);
}
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));
}
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);
}
}
Aggregations