Search in sources :

Example 1 with PluginExecution

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

the class ExecuteListenerNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    dataAccessViewTopComponent = mock(DataAccessViewTopComponent.class);
    dataAccessPane = mock(DataAccessPane.class);
    dataAccessTabPane = mock(DataAccessTabPane.class);
    tabPane = mock(TabPane.class);
    graphManager = mock(GraphManager.class);
    activeGraph = mock(Graph.class);
    when(dataAccessPane.getParentComponent()).thenReturn(dataAccessViewTopComponent);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
    when(dataAccessViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
    executeListener = new ExecuteListener(dataAccessPane);
    graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
    when(graphManager.getActiveGraph()).thenReturn(activeGraph);
    when(activeGraph.getId()).thenReturn(GRAPH_ID);
    // Intercept the plugin execution run calls and run the plugins manually
    // so that it executes within the same thread and sequentially for the test
    pluginExecution = mock(PluginExecution.class);
    pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(SimplePlugin.class))).thenAnswer(iom -> {
        final SimplePlugin plugin = iom.getArgument(0);
        final PluginGraphs graphs = mock(PluginGraphs.class);
        when(graphs.getGraph()).thenReturn(null);
        final PluginInteraction pluginInteraction = mock(PluginInteraction.class);
        final PluginParameters pluginParameters = mock(PluginParameters.class);
        // This will call the execute method of the simple plugin
        plugin.run(graphs, pluginInteraction, pluginParameters);
        return pluginExecution;
    });
    // Intercept calls to start the wait for tasks so that they don't run
    completableFutureMockedStatic.when(() -> CompletableFuture.runAsync(any(WaitForQueriesToCompleteTask.class), any(ExecutorService.class))).thenReturn(null);
    notificationDisplayer = mock(NotificationDisplayer.class);
    notificationDisplayerMockedStatic.when(NotificationDisplayer::getDefault).thenReturn(notificationDisplayer);
    when(notificationDisplayer.notify(anyString(), any(Icon.class), anyString(), isNull())).thenReturn(null);
    statusDisplayer = mock(StatusDisplayer.class);
    statusDisplayerMockedStatic.when(StatusDisplayer::getDefault).thenReturn(statusDisplayer);
    DataAccessPaneState.clearState();
}
Also used : TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) StatusDisplayer(org.openide.awt.StatusDisplayer) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ExecutorService(java.util.concurrent.ExecutorService) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) NotificationDisplayer(org.openide.awt.NotificationDisplayer) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Icon(javax.swing.Icon) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with PluginExecution

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

the class QueryPhasePaneNGTest method testRunPlugins.

@Test
public void testRunPlugins() {
    // Initialize the current graph in the state.
    DataAccessPaneState.setCurrentGraphId("GraphId");
    final QueryPhasePane instance = spy(new QueryPhasePane(new HashMap<>(), null, null));
    // Setup the graph manager
    final GraphManager graphManager = mock(GraphManager.class);
    final Graph graph = mock(Graph.class);
    when(graphManager.getActiveGraph()).thenReturn(graph);
    // Setup the global parameters
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters globalPluginParameters = mock(PluginParameters.class);
    final PluginParameter globalPluginParameter1 = mock(PluginParameter.class);
    final PluginParameter globalPluginParameter2 = mock(PluginParameter.class);
    doReturn(globalParametersPane).when(instance).getGlobalParametersPane();
    when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
    when(globalPluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", globalPluginParameter1, "global.parameter1", globalPluginParameter2));
    when(globalPluginParameter1.getObjectValue()).thenReturn("GLOBAL PARAMETER 1");
    // Setup data access panes
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    doReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2)).when(instance).getDataAccessPanes();
    // Pane 1 is disabled so will not be run
    when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
    when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
    // Setup the plugin for pane 2
    final Plugin plugin = mock(Plugin.class);
    when(plugin.getName()).thenReturn("Plugin Name");
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
    // Pane 2 has two parameters. One of them matches in name to one of
    // the global parameters which means its value will be overriden with
    // the global value.
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", pluginParameter1, "abc.parameter2", pluginParameter2));
    when(pluginParameters.copy()).thenReturn(pluginParameters);
    when(dataSourceTitledPane2.getParameters()).thenReturn(pluginParameters);
    try (final MockedStatic<PluginRegistry> pluginRegistry = Mockito.mockStatic(PluginRegistry.class);
        final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
        final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class);
        final MockedConstruction<PluginSynchronizer> pluginSynchMocks = Mockito.mockConstruction(PluginSynchronizer.class, (pluginSyncMock, cnxt) -> {
            assertEquals(cnxt.arguments(), List.of(1));
        })) {
        // Not sure why this is being done but just retuning the same plugin
        // to save creating another mock.
        pluginRegistry.when(() -> PluginRegistry.get(plugin.getClass().getName())).thenReturn(plugin);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        // This is the future that will be returned when the plugin begins execution
        final Future future = CompletableFuture.completedFuture("Plugin Complete!");
        // This is the future of a plugin that was run previously
        final Future existingFuture = CompletableFuture.completedFuture("Previous Plugin Complete!");
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(plugin)).thenReturn(pluginExecution);
        // We don't need to verify any of these again (with the exception of the plugin synchronizer)
        // because a null pointer will happen if any of the params don't match up.
        when(pluginExecution.withParameters(pluginParameters)).thenReturn(pluginExecution);
        when(pluginExecution.waitingFor(List.of(existingFuture))).thenReturn(pluginExecution);
        when(pluginExecution.synchronizingOn(any(PluginSynchronizer.class))).thenReturn(pluginExecution);
        when(pluginExecution.executeLater(graph)).thenReturn(future);
        // Verify that the return contains the plugin future as defined above
        assertEquals(instance.runPlugins(List.of(existingFuture)), List.of(future));
        // Verify the state's running plugin list has been updated
        assertEquals(DataAccessPaneState.getRunningPlugins(), Map.of(future, "Plugin Name"));
        // Verify the local plugin parameter was updated with the global parameter value
        verify(pluginParameter1).setObjectValue("GLOBAL PARAMETER 1");
        // Verify the created plugin synchronizer is passed to the plugin execution
        verify(pluginExecution).synchronizingOn(pluginSynchMocks.constructed().get(0));
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginSynchronizer(au.gov.asd.tac.constellation.plugins.PluginSynchronizer) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) HashMap(java.util.HashMap) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginRegistry(au.gov.asd.tac.constellation.plugins.PluginRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) Test(org.testng.annotations.Test)

Example 3 with PluginExecution

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

the class FindViewControllerNGTest method testReplaceMatchingElements.

// // Populate the attribute list with the attributes of the given type
// for (Graph graph : gm.getAllGraphs().values()) {
// try {
// System.out.println("in for graph try");
// 
// WritableGraph wg = graph.getWritableGraph("", true);
// for (int i = 0; i < stringAttributeList.size(); i++) {
// int attributeInt = wg.getAttribute(type, stringAttributeList.get(i));
// attributes.add(new GraphAttribute(wg, attributeInt));
// System.out.println(attributes.get(i).getName() + " = attribute name");
// 
// }
// 
// instance.updateBasicFindParameters(parameters);
// 
// System.out.println("before method call");
// 
// instance.retriveMatchingElements(true, false);
// 
// System.out.println("before assert");
// System.out.println(wg.getStringValue(labelV, vxId1));
// 
// System.out.println(wg.getBooleanValue(selectedV, vxId1));
// assertEquals(wg.getBooleanValue(selectedV, vxId1), true);
// System.out.println("after equals");
// 
// wg.commit();
// 
// } catch (final InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// Thread.currentThread().interrupt();
// }
// 
// }
// 
// }
/**
 * Test of replaceMatchingElements method, of class FindViewController.
 */
@Test
public void testReplaceMatchingElements() {
    System.out.println("replaceMatchingElements");
    /**
     * 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.replaceMatchingElements(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.updateBasicReplaceParameters(parametersAllGraphs);
            when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
            mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
            instance.replaceMatchingElements(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 4 with PluginExecution

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

the class TableViewTopComponentNGTest method updateStateNotPresentInGraphAttributes.

@Test
public void updateStateNotPresentInGraphAttributes() {
    final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
    doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
    doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
    doCallRealMethod().when(tableViewTopComponent).getCurrentState();
    final Graph graph = mock(Graph.class);
    final Graph currentGraph = mock(Graph.class);
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
    when(readableGraph.getObjectValue(42, 0)).thenReturn(null);
    when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
    try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
            final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
            assertEquals(new TableViewState(), plugin.getTableViewState());
            return pluginExecution;
        });
        tableViewTopComponent.updateState(graph);
        verify(pluginExecution).executeLater(currentGraph);
    }
    assertEquals(new TableViewState(), tableViewTopComponent.getCurrentState());
    verify(graph).getReadableGraph();
    verify(readableGraph).release();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) 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) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) Test(org.testng.annotations.Test)

Example 5 with PluginExecution

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

the class TableViewTopComponentNGTest method updateStatePresentInGraphAttributes.

@Test
public void updateStatePresentInGraphAttributes() {
    final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
    doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
    doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
    doCallRealMethod().when(tableViewTopComponent).getCurrentState();
    final Graph graph = mock(Graph.class);
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    final TableViewState state = new TableViewState();
    // <-- Non Default Value
    state.setElementType(GraphElementType.META);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
    when(readableGraph.getObjectValue(42, 0)).thenReturn(state);
    try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        tableViewTopComponent.updateState(graph);
        pluginExecutionMockedStatic.verifyNoInteractions();
    }
    assertEquals(state, tableViewTopComponent.getCurrentState());
    tableViewTopComponent.updateState(null);
    assertEquals(null, tableViewTopComponent.getCurrentState());
    // Should only be called once. Second call has null graph
    verify(graph).getReadableGraph();
    verify(readableGraph).release();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) 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) 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