use of au.gov.asd.tac.constellation.plugins.PluginExecution 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.plugins.PluginExecution in project constellation by constellation-app.
the class ActiveTableReferenceNGTest method updateVisibleColumnsRemove.
@Test
public void updateVisibleColumnsRemove() {
try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final Graph graph = mock(Graph.class);
final Attribute attribute = mock(Attribute.class);
final PluginExecution pluginExecution = mock(PluginExecution.class);
final List<Tuple<String, Attribute>> paramColumnAttributes = List.of(Tuple.create("paramAttr", attribute));
final List<Tuple<String, Attribute>> stateColumnAttributes = List.of(Tuple.create("stateAttr", attribute), Tuple.create("paramAttr", attribute));
final TableViewState tableViewState = new TableViewState();
tableViewState.setColumnAttributes(stateColumnAttributes);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(executeUpdateStatePlugin(pluginExecution, tableViewState, List.of(Tuple.create("stateAttr", attribute))));
activeTableReference.updateVisibleColumns(graph, tableViewState, paramColumnAttributes, UpdateMethod.REMOVE);
verify(pluginExecution).executeLater(graph);
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class ExportMenuNGTest method verifyExportExcelAction.
/**
* Verify that the passed event handler exports to Excel either the whole
* table or just the selected rows.
*
* @param eventHandler the handler to test
* @param expectedCopyOnlySelectedRows true if only the selected rows are
* expected to be exported, false otherwise
* @param userCancelsRequest true if the user is meant to cancel the export when
* picking a file in the file chooser
*/
private void verifyExportExcelAction(final EventHandler<ActionEvent> eventHandler, final boolean userCancelsRequest, final boolean expectedExportOnlySelectedRows) throws InterruptedException, PluginException, ExecutionException {
final ExportMenuItemActionHandler exportActionHandler = (ExportMenuItemActionHandler) eventHandler;
final ExportMenuItemActionHandler spiedExportActionHandler = spy(exportActionHandler);
final FileChooserBuilder exportFileChooser = mock(FileChooserBuilder.class);
final File exportFile = userCancelsRequest ? null : new File("test.xlsx");
final Optional<File> optionalExportFile = Optional.ofNullable(exportFile);
doReturn(exportFileChooser).when(spiedExportActionHandler).getExportFileChooser();
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
final MockedStatic<FileChooser> fileChooserMockedStatic = Mockito.mockStatic(FileChooser.class);
final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
// This is added so that the mocked static that we would otherwise be
// trying to run in the fx thread is actually invoked properly
platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer(iom -> {
((Runnable) iom.getArgument(0)).run();
return null;
});
fileChooserMockedStatic.when(() -> FileChooser.openSaveDialog(exportFileChooser)).thenReturn(CompletableFuture.completedFuture(optionalExportFile));
final ActionEvent actionEvent = mock(ActionEvent.class);
final Pagination pagination = mock(Pagination.class);
final TableView<ObservableList<String>> tableView = mock(TableView.class);
final int maxRowsPerPage = 42;
final UserTablePreferences userTablePreferences = new UserTablePreferences();
userTablePreferences.setMaxRowsPerPage(maxRowsPerPage);
when(activeTableReference.getPagination()).thenReturn(pagination);
when(table.getTableView()).thenReturn(tableView);
when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(mockitoInvocation -> {
final ExportToExcelFilePlugin plugin = (ExportToExcelFilePlugin) mockitoInvocation.getArgument(0);
if (exportFile != null) {
assertEquals(exportFile.getAbsolutePath(), plugin.getFile().getAbsolutePath());
} else {
assertEquals(exportFile, plugin.getFile());
}
assertEquals(pagination, plugin.getPagination());
assertEquals(tableView, plugin.getTable());
assertEquals(42, plugin.getRowsPerPage());
assertEquals(GRAPH_ID, plugin.getSheetName());
assertEquals(expectedExportOnlySelectedRows, plugin.isSelectedOnly());
return pluginExecution;
});
spiedExportActionHandler.handle(actionEvent);
// Wait for the export job to complete
spiedExportActionHandler.getLastExport().get();
fileChooserMockedStatic.verify(() -> FileChooser.openSaveDialog(exportFileChooser));
if (userCancelsRequest) {
verifyNoInteractions(pluginExecution);
} else {
verify(pluginExecution).executeNow((Graph) null);
}
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class TableToolbarNGTest method elementTypeChangeActionChecks.
/**
* When the element type button is pressed the tables state is switched
* between VERTEX and TRANSACTION. This verifies that as the button is
* pressed that transition happens and the update state plugin is executed
* triggering the required changes. The buttons icon should also change to
* the element type now set in the state.
*
* @param elementTypeInitialState the initial element type in the state
* before the button is pressed
* @param elementTypeEndState the expected element type in the state after
* the button is pressed
* @param expectedNewIcon the expected image to be now on the element type
* change button
*/
private void elementTypeChangeActionChecks(final GraphElementType elementTypeInitialState, final GraphElementType elementTypeEndState, final Image expectedNewIcon) {
try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
final ActionEvent actionEvent = mock(ActionEvent.class);
final TableViewState tableViewState = new TableViewState();
tableViewState.setElementType(elementTypeInitialState);
when(tableTopComponent.getCurrentState()).thenReturn(tableViewState);
final ArgumentCaptor<UpdateStatePlugin> captor = ArgumentCaptor.forClass(UpdateStatePlugin.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(captor.capture())).thenReturn(pluginExecution);
tableToolbar.getElementTypeButton().getOnAction().handle(actionEvent);
final UpdateStatePlugin updatePlugin = captor.getValue();
final ImageView buttonIcon = (ImageView) tableToolbar.getElementTypeButton().getGraphic();
assertTrue(isImageEqual(expectedNewIcon, buttonIcon.getImage()));
assertEquals(elementTypeEndState, updatePlugin.getTableViewState().getElementType());
verify(pluginExecution).executeLater(graph);
verify(actionEvent).consume();
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class TableViewUtilitiesNGTest method copySelectionToGraph.
@Test
public void copySelectionToGraph() {
try (MockedStatic<PluginExecution> pluginExecutionStaticMock = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionStaticMock.when(() -> PluginExecution.withPlugin(any(SelectionToGraphPlugin.class))).thenReturn(pluginExecution);
final TableView<ObservableList<String>> table = mock(TableView.class);
final Map<ObservableList<String>, Integer> index = mock(Map.class);
final Graph graph = mock(Graph.class);
TableViewUtilities.copySelectionToGraph(table, index, GraphElementType.META, graph);
verify(pluginExecution).executeLater(graph);
}
}
Aggregations