use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.
the class TableViewTopComponentNGTest method showSelected.
@Test
public void showSelected() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
final TableViewState currentState = new TableViewState();
final Graph currentGraph = mock(Graph.class);
final TableViewState expectedNewState = new TableViewState();
expectedNewState.setElementType(GraphElementType.META);
expectedNewState.setSelectedOnly(true);
final TablePane tablePane = mock(TablePane.class);
final Table table = mock(Table.class);
doCallRealMethod().when(tableViewTopComponent).showSelected(any(GraphElementType.class), anyInt());
when(tableViewTopComponent.getCurrentState()).thenReturn(currentState);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
when(tableViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
when(tablePane.getTable()).thenReturn(table);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
when(pluginExecution.executeLater(any(Graph.class))).thenReturn(CompletableFuture.completedFuture(null));
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
assertEquals(expectedNewState, plugin.getTableViewState());
// Change the mock now that the "Update Plugin" has run
when(tableViewTopComponent.getCurrentState()).thenReturn(expectedNewState);
return pluginExecution;
});
final Future<?> updateTask = tableViewTopComponent.showSelected(GraphElementType.META, 42);
// Ensure that the update selection task is completed
try {
updateTask.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
fail("The submitted task in show selected did not complete in the " + "allowed time. Something is probably wrong.");
}
verify(pluginExecution).executeLater(currentGraph);
verify(table).updateSelection(currentGraph, expectedNewState);
}
}
use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.
the class UpdateColumnsTaskNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
tableViewTopComponent = mock(TableViewTopComponent.class);
tableView = mock(TableView.class);
tablePane = mock(TablePane.class);
table = mock(Table.class);
activeTableReference = mock(ActiveTableReference.class);
selectionModel = mock(TableViewSelectionModel.class);
selectedItemProperty = mock(ReadOnlyObjectProperty.class);
selectedItems = mock(ObservableList.class);
tableSelectionListener = mock(ChangeListener.class);
selectedOnlySelectionListener = mock(ListChangeListener.class);
columnType1 = "source.";
attribute1 = mock(Attribute.class);
column1 = mock(TableColumn.class);
columnType2 = "destination.";
attribute2 = mock(Attribute.class);
column2 = mock(TableColumn.class);
columnType3 = "source.";
attribute3 = mock(Attribute.class);
column3 = mock(TableColumn.class);
columnType4 = "transaction.";
attribute4 = mock(Attribute.class);
column4 = mock(TableColumn.class);
columnType5 = "transaction.";
attribute5 = mock(Attribute.class);
column5 = mock(TableColumn.class);
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));
columnIndex.add(new Column(columnType5, attribute5, column5));
when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
when(tablePane.getTable()).thenReturn(table);
when(tablePane.getActiveTableReference()).thenReturn(activeTableReference);
when(tablePane.getParentComponent()).thenReturn(tableViewTopComponent);
when(activeTableReference.getColumnIndex()).thenReturn(columnIndex);
when(table.getTableView()).thenReturn(tableView);
when(table.getSelectedOnlySelectionListener()).thenReturn(selectedOnlySelectionListener);
when(table.getTableSelectionListener()).thenReturn(tableSelectionListener);
when(table.getParentComponent()).thenReturn(tablePane);
when(tableView.getSelectionModel()).thenReturn(selectionModel);
when(selectionModel.selectedItemProperty()).thenReturn(selectedItemProperty);
when(selectionModel.getSelectedItems()).thenReturn(selectedItems);
updateColumnsTask = spy(new UpdateColumnsTask(table));
}
use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.
the class UpdateTableDataTaskNGTest method updateDataTask.
@Test
public void updateDataTask() {
final TablePane tablePane = mock(TablePane.class);
final Graph graph = mock(Graph.class);
final TableViewState tableViewState = new TableViewState();
final Table table = mock(Table.class);
final ProgressBar progressBar = mock(ProgressBar.class);
when(tablePane.getTable()).thenReturn(table);
when(tablePane.getProgressBar()).thenReturn(progressBar);
final TriggerDataUpdateTask updateTableDataTask = new TriggerDataUpdateTask(tablePane, graph, tableViewState);
updateTableDataTask.run();
verify(table).updateData(graph, tableViewState, progressBar);
}
use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.
the class TablePaneNGTest method updateTableGraphIsNull.
@Test
public void updateTableGraphIsNull() throws InterruptedException, ExecutionException, TimeoutException {
final Table table = mock(Table.class);
final TableView<ObservableList<String>> tableView = mock(TableView.class);
final TableViewState tableViewState = new TableViewState();
final TableToolbar tableToolbar = mock(TableToolbar.class);
final List<TableColumn<ObservableList<String>, String>> tableColumns = new ArrayList<>();
tableColumns.add(mock(TableColumn.class));
tableColumns.add(mock(TableColumn.class));
final ObservableList<TableColumn<ObservableList<String>, String>> columns = FXCollections.observableList(tableColumns);
when(tablePane.getTable()).thenReturn(table);
when(table.getTableView()).thenReturn(tableView);
doReturn(columns).when(tableView).getColumns();
when(tablePane.getTableToolbar()).thenReturn(tableToolbar);
tablePane.updateTable(null, tableViewState);
try {
tablePane.getFuture().get(30, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
fail("The update thread did not finish as expected within the allowed time. " + "Something went wrong");
}
verify(tableToolbar).updateToolbar(tableViewState);
verify(table, times(0)).updateColumns(any(Graph.class), any(TableViewState.class));
verify(table, times(0)).updateData(any(Graph.class), any(TableViewState.class), any(ProgressBar.class));
verify(table, times(0)).updateSelection(any(Graph.class), any(TableViewState.class));
// The future finished but maybe not the JavaFX thread
WaitForAsyncUtils.waitForFxEvents();
verify(table, times(0)).updateSortOrder();
assertTrue(columns.isEmpty());
}
use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.
the class TablePaneNGTest method updateTable_interrupt.
@Test
public void updateTable_interrupt() {
final Graph graph = mock(Graph.class);
final TableViewState tableViewState = new TableViewState();
final Table table = mock(Table.class);
final ProgressBar progressBar = mock(ProgressBar.class);
final TableToolbar tableToolbar = mock(TableToolbar.class);
when(tablePane.getTable()).thenReturn(table);
when(tablePane.getProgressBar()).thenReturn(progressBar);
when(tablePane.getTableToolbar()).thenReturn(tableToolbar);
doAnswer(mockitoInvocation -> {
System.out.println("Interrupt: " + Thread.currentThread().getName());
Thread.currentThread().interrupt();
return null;
}).when(table).updateColumns(graph, tableViewState);
tablePane.updateTable(graph, tableViewState);
try {
tablePane.getFuture().get(30, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
fail("The update thread did not finish as expected within the allowed time. " + "Something went wrong");
}
verify(tableToolbar).updateToolbar(tableViewState);
// Update columns is called
verify(table).updateColumns(graph, tableViewState);
// Verify everything after that is not called
verify(table, times(0)).updateData(graph, tableViewState, progressBar);
verify(table, times(0)).updateSelection(graph, tableViewState);
// The future finished but maybe not the JavaFX thread
WaitForAsyncUtils.waitForFxEvents();
verify(table, times(0)).updateSortOrder();
}
Aggregations