Search in sources :

Example 6 with PluginExecution

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);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ExecutionException(java.util.concurrent.ExecutionException) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 7 with PluginExecution

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);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 8 with PluginExecution

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();
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Platform(javafx.application.Platform) ActionEvent(javafx.event.ActionEvent) ExportMenuItemActionHandler(au.gov.asd.tac.constellation.views.tableview.components.ExportMenu.ExportMenuItemActionHandler) ExportToExcelFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToExcelFilePlugin) Pagination(javafx.scene.control.Pagination) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ObservableList(javafx.collections.ObservableList) JFileChooser(javax.swing.JFileChooser) FileChooser(au.gov.asd.tac.constellation.utilities.gui.filechooser.FileChooser) FileChooserBuilder(org.openide.filesystems.FileChooserBuilder) File(java.io.File) ExportToExcelFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToExcelFilePlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) ExportToCsvFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToCsvFilePlugin)

Example 9 with PluginExecution

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();
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ActionEvent(javafx.event.ActionEvent) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) ImageView(javafx.scene.image.ImageView)

Example 10 with PluginExecution

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);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) ObservableList(javafx.collections.ObservableList) SelectionToGraphPlugin(au.gov.asd.tac.constellation.views.tableview.plugins.SelectionToGraphPlugin) Test(org.testng.annotations.Test)

Aggregations

PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)17 Graph (au.gov.asd.tac.constellation.graph.Graph)11 Test (org.testng.annotations.Test)11 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)9 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)8 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)7 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)4 ActionEvent (javafx.event.ActionEvent)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)3 ObservableList (javafx.collections.ObservableList)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)2 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)2 FileChooser (au.gov.asd.tac.constellation.utilities.gui.filechooser.FileChooser)2 ExportMenuItemActionHandler (au.gov.asd.tac.constellation.views.tableview.components.ExportMenu.ExportMenuItemActionHandler)2