use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities 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.utilities.TableViewUtilities 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.utilities.TableViewUtilities in project constellation by constellation-app.
the class TableNGTest method updateSelectionNotInSelectedOnlyModeAndNothingSelected.
@Test
public void updateSelectionNotInSelectedOnlyModeAndNothingSelected() 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 TableView<ObservableList<String>> tableView = mock(TableView.class);
when(table.getTableView()).thenReturn(tableView);
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());
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, times(0)).selectIndices(anyInt(), any(int[].class));
verify(selectedProperty).addListener(tableSelectionListener);
verify(selectedItems).addListener(selectedOnlySelectionListener);
}
use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.
the class ExportToCsvFilePluginNGTest method exportCSV.
@Test
public void exportCSV() throws IOException, InterruptedException, PluginException {
final TableView<ObservableList<String>> table = mock(TableView.class);
final Pagination pagination = mock(Pagination.class);
final PluginInteraction pluginInteraction = mock(PluginInteraction.class);
File tmpFile = null;
try (MockedStatic<TableViewUtilities> tableViewUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
tmpFile = File.createTempFile("constellationTest", ".csv");
final String csv = "COLUMN_1,COLUMN_2\nrow1Column1,row1Column2\nrow2Column1,row2Column2\n";
tableViewUtilsMockedStatic.when(() -> TableViewUtilities.getTableData(table, pagination, true, true)).thenReturn(csv);
final ExportToCsvFilePlugin plugin = new ExportToCsvFilePlugin(tmpFile, table, pagination, true);
plugin.execute(null, pluginInteraction, null);
final String outputtedFile = new String(IOUtils.toByteArray(new FileInputStream(tmpFile)), StandardCharsets.UTF_8);
assertEquals(csv, outputtedFile);
assertEquals(plugin.getName(), "Table View: Export to Delimited File");
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}
use of au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities in project constellation by constellation-app.
the class ExportMenuNGTest method createExportButtons.
@Test
public void createExportButtons() throws InterruptedException, PluginException, ExecutionException {
exportMenu.init();
assertNotNull(exportMenu.getExportButton());
assertNotNull(exportMenu.getExportCsvMenu());
assertNotNull(exportMenu.getExportCsvSelectionMenu());
assertNotNull(exportMenu.getExportExcelMenu());
assertNotNull(exportMenu.getExportExcelSelectionMenu());
assertEquals(FXCollections.observableList(List.of(exportMenu.getExportCsvMenu(), exportMenu.getExportCsvSelectionMenu(), exportMenu.getExportExcelMenu(), exportMenu.getExportExcelSelectionMenu())), exportMenu.getExportButton().getItems());
final Graph graph = mock(Graph.class);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(graph);
when(graph.getId()).thenReturn(GRAPH_ID);
// Export Button
final ImageView icon = (ImageView) exportMenu.getExportButton().getGraphic();
assertTrue(isImageEqual(UserInterfaceIconProvider.UPLOAD.buildImage(16), icon.getImage()));
assertEquals(120.0d, exportMenu.getExportButton().getMaxWidth());
assertEquals(Side.RIGHT, exportMenu.getExportButton().getPopupSide());
// Export Whole Table as CSV Menu Item
assertEquals("Export to CSV", exportMenu.getExportCsvMenu().getText());
verifyExportCSVAction(exportMenu.getExportCsvMenu().getOnAction(), false, false);
verifyExportCSVAction(exportMenu.getExportCsvMenu().getOnAction(), true, false);
reset(activeTableReference, table);
// Export Selected Rows as CSV Menu Item
assertEquals("Export to CSV (Selection)", exportMenu.getExportCsvSelectionMenu().getText());
verifyExportCSVAction(exportMenu.getExportCsvSelectionMenu().getOnAction(), false, true);
verifyExportCSVAction(exportMenu.getExportCsvSelectionMenu().getOnAction(), true, true);
reset(activeTableReference, table);
// Export Whole Table as Excel Menu Item
assertEquals("Export to Excel", exportMenu.getExportExcelMenu().getText());
verifyExportExcelAction(exportMenu.getExportExcelMenu().getOnAction(), false, false);
verifyExportExcelAction(exportMenu.getExportExcelMenu().getOnAction(), true, false);
reset(activeTableReference, table);
// Export Selected Rows as Excel Menu Item
assertEquals("Export to Excel (Selection)", exportMenu.getExportExcelSelectionMenu().getText());
verifyExportExcelAction(exportMenu.getExportExcelSelectionMenu().getOnAction(), false, true);
verifyExportExcelAction(exportMenu.getExportExcelSelectionMenu().getOnAction(), true, true);
reset(activeTableReference, table);
// The following verifies that the ExportMenuItemActionHandler wont run if
// the current graph is null
when(tableViewTopComponent.getCurrentGraph()).thenReturn(null);
try (MockedStatic<TableViewUtilities> tableViewUtilsMockedStatic = Mockito.mockStatic(TableViewUtilities.class)) {
final ActionEvent actionEvent = mock(ActionEvent.class);
exportMenu.getExportCsvMenu().getOnAction().handle(actionEvent);
tableViewUtilsMockedStatic.verifyNoInteractions();
verify(actionEvent).consume();
}
}
Aggregations