Search in sources :

Example 11 with PluginExecution

use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.

the class SetGraphValues method setGraphAttributes.

private static void setGraphAttributes(final Graph graph, final ArrayNode columns, final ArrayNode row) {
    final Plugin p = new SetGraphAttributesFromRestApiPlugin(columns, row);
    final PluginExecution pe = PluginExecution.withPlugin(p);
    try {
        pe.executeNow(graph);
    } catch (final InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new RestServiceException(ex);
    } catch (final PluginException ex) {
        throw new RestServiceException(ex);
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 12 with PluginExecution

use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.

the class MergeNodesPluginNGTest method edit.

@Test
public void edit() throws InterruptedException, PluginException, MergeNodeType.MergeException {
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    final PluginInteraction interaction = mock(PluginInteraction.class);
    final PluginParameters parameters = mock(PluginParameters.class);
    final PluginExecution pluginExecution = mock(PluginExecution.class);
    final PluginParameter mergeTypeParameter = mock(PluginParameter.class);
    final PluginParameter thresholdParameter = mock(PluginParameter.class);
    final PluginParameter mergerParameter = mock(PluginParameter.class);
    final PluginParameter leadParameter = mock(PluginParameter.class);
    final PluginParameter selectedParameter = mock(PluginParameter.class);
    final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", mergeTypeParameter, "MergeNodesPlugin.threshold", thresholdParameter, "MergeNodesPlugin.merger", mergerParameter, "MergeNodesPlugin.lead", leadParameter, "MergeNodesPlugin.selected", selectedParameter);
    when(parameters.getParameters()).thenReturn(pluginParameters);
    when(mergeTypeParameter.getStringValue()).thenReturn(TestMergeType.NAME);
    when(thresholdParameter.getIntegerValue()).thenReturn(TestMergeType.MERGE_SUCCESS_THRESHOLD);
    when(mergerParameter.getStringValue()).thenReturn("Retain lead vertex attributes if present");
    when(leadParameter.getStringValue()).thenReturn("Longest Value");
    when(selectedParameter.getBooleanValue()).thenReturn(true);
    doReturn(null).when(pluginExecution).executeNow(graph);
    try (MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA)).thenReturn(pluginExecution);
        mergeNodesPlugin.edit(graph, interaction, parameters);
        verify(pluginExecution).executeNow(graph);
        verify(interaction).setProgress(1, 0, "Merged 2 nodes.", true);
    // Due to accessibility issues the call to mergeVerticies and its follow
    // on logic cannot be verified without tying this test to the logic of
    // one of the concrete implementations of GraphElementMerger.
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 13 with PluginExecution

use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.

the class FindViewControllerNGTest method testRetriveMatchingElements.

/**
 * Test of retriveMatchingElements method, of class FindViewController.
 */
@Test
public void testRetriveMatchingElements() {
    System.out.println("retriveMatchingElements");
    /**
     * Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
     * (2 of type string), 3 transaction attributes (2 of type string)
     */
    setupGraph();
    /**
     * Create a mock of the top component, get an instance of the
     * controller, create a mock of the graph manager, when getAllGraphs is
     * called return the graphMap created in this class
     */
    final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
    FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    when(gm.getActiveGraph()).thenReturn(graph);
    System.out.println("before try");
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        System.out.println("in try");
        try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
            PluginExecution pluginExecution = mock(PluginExecution.class);
            /**
             * The first test should execute the plugin once on graph as the
             * parameters are not set to look at all graphs
             */
            when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.retriveMatchingElements(true, false);
            verify(pluginExecution).executeLater(Mockito.eq(graph));
            /**
             * Set the parameters to find in all graphs and repeat the same
             * process. The plugin should be executed on graph a second
             * time, and should be executed on graph2 for the first time.
             */
            instance.updateBasicFindParameters(parametersAllGraphs);
            when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.retriveMatchingElements(true, false);
            verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
            verify(pluginExecution).executeLater(Mockito.eq(graph2));
        }
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 14 with PluginExecution

use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.

the class ExportMenuNGTest method verifyExportCSVAction.

/**
 * Verify that the passed event handler exports to CSV 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 verifyExportCSVAction(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.csv");
    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);
        when(activeTableReference.getPagination()).thenReturn(pagination);
        when(table.getTableView()).thenReturn(tableView);
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(Plugin.class))).thenAnswer(mockitoInvocation -> {
            final ExportToCsvFilePlugin plugin = (ExportToCsvFilePlugin) 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(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) Pagination(javafx.scene.control.Pagination) ExportToCsvFilePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.ExportToCsvFilePlugin) 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 15 with PluginExecution

use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.

the class TableToolbarNGTest method selectedOnlyModeActionChecks.

/**
 * When the selected only mode button is pressed, the table switches between
 * "Selected Only Mode" ON and OFF. This verifies that as the button is
 * pressed that transition between ON and OFF happens and the update state
 * plugin is executed triggering the required changes.
 *
 * @param selectedOnlyModeInitialState the initial status of the "Selected
 * Only Mode", the expected status after the button is pressed will be the
 * inverse
 * @param expectedNewIcon the new image that is expected to be on the button
 * after it was clicked
 */
private void selectedOnlyModeActionChecks(final boolean selectedOnlyModeInitialState, 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.setSelectedOnly(selectedOnlyModeInitialState);
        when(tableTopComponent.getCurrentState()).thenReturn(tableViewState);
        final ArgumentCaptor<UpdateStatePlugin> captor = ArgumentCaptor.forClass(UpdateStatePlugin.class);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(captor.capture())).thenReturn(pluginExecution);
        tableToolbar.getSelectedOnlyButton().getOnAction().handle(actionEvent);
        final UpdateStatePlugin updatePlugin = captor.getValue();
        final ImageView buttonIcon = (ImageView) tableToolbar.getSelectedOnlyButton().getGraphic();
        assertTrue(isImageEqual(expectedNewIcon, buttonIcon.getImage()));
        assertEquals(!selectedOnlyModeInitialState, updatePlugin.getTableViewState().isSelectedOnly());
        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)

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