Search in sources :

Example 61 with PluginParameters

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameters 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 62 with PluginParameters

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

the class DataAccessPaneNGTest method update_pass_non_null_graph.

@Test
public void update_pass_non_null_graph() {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final Tab currentTab = mock(Tab.class);
    final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
    final DataSourceTitledPane dataSourceTitledPane = mock(DataSourceTitledPane.class);
    final Plugin plugin = mock(Plugin.class);
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    final Graph graph = mock(Graph.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
    when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane));
    when(dataSourceTitledPane.getPlugin()).thenReturn(plugin);
    when(dataSourceTitledPane.getParameters()).thenReturn(pluginParameters);
    when(graph.getId()).thenReturn("graphId");
    dataAccessPane.update(graph);
    verify(plugin).updateParameters(graph, pluginParameters);
    verify(dataAccessPane).update("graphId");
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Graph(au.gov.asd.tac.constellation.graph.Graph) Tab(javafx.scene.control.Tab) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 63 with PluginParameters

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

the class DataSourceTitledPaneNGTest method setParametersNonNullPerPluginParamMap.

@Test
public void setParametersNonNullPerPluginParamMap() {
    final String actionKey = "actionKey";
    final String nonActionKey = "nonActionKey";
    final String value = "value";
    final PluginParameter<?> nonActionPluginParameter = mock(PluginParameter.class);
    final PluginParameter<?> actionPluginParameter = mock(PluginParameter.class);
    when(nonActionPluginParameter.getId()).thenReturn("Not ActionParameterType.ID");
    when(actionPluginParameter.getId()).thenReturn(ActionParameterType.ID);
    final Map<String, PluginParameter<?>> parameters = Map.of(actionKey, actionPluginParameter, nonActionKey, nonActionPluginParameter);
    when(dataSourceParameters.hasParameter(actionKey)).thenReturn(true);
    when(dataSourceParameters.hasParameter(nonActionKey)).thenReturn(true);
    when(dataSourceParameters.getParameters()).thenReturn(parameters);
    final Map<String, String> perPluginParamMap = Map.of(actionKey, value, nonActionKey, value, GLOBAL_PARAM_1, value, GLOBAL_PARAM_2, value);
    dataSourceTitledPane.setParameterValues(perPluginParamMap);
    // The set parameters happens in its own thread. We add the loop to ensure
    // there isn't a race condition happening.
    PluginParameters pluginParameters;
    // need a safety catch so it doesn't get stuck
    int counter = 0;
    while ((pluginParameters = dataSourceTitledPane.getParameters()) == null && counter < 3) {
        Thread.yield();
        counter++;
    }
    ;
    assertSame(pluginParameters, dataSourceParameters);
    verify(nonActionPluginParameter).setStringValue(value);
    verify(actionPluginParameter, times(0)).setStringValue(value);
}
Also used : DefaultPluginParameters(au.gov.asd.tac.constellation.plugins.parameters.DefaultPluginParameters) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 64 with PluginParameters

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

the class DataSourceTitledPaneNGTest method setParametersNullPerPluginParamMap.

@Test
public void setParametersNullPerPluginParamMap() {
    dataSourceTitledPane.setParameterValues(null);
    // The set parameters happens in its own thread. We add the loop to ensure
    // there isn't a race condition happening.
    PluginParameters pluginParameters;
    // need a safety catch so it doesn't get stuck
    int counter = 0;
    while ((pluginParameters = dataSourceTitledPane.getParameters()) == null && counter < 3) {
        Thread.yield();
        counter++;
    }
    ;
    assertSame(pluginParameters, dataSourceParameters);
    assertFalse(dataSourceTitledPane.isQueryEnabled());
}
Also used : DefaultPluginParameters(au.gov.asd.tac.constellation.plugins.parameters.DefaultPluginParameters) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Test(org.testng.annotations.Test)

Example 65 with PluginParameters

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameters 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)

Aggregations

PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)377 Test (org.testng.annotations.Test)185 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)60 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)60 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)58 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)58 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)52 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)48 ArrayList (java.util.ArrayList)47 Graph (au.gov.asd.tac.constellation.graph.Graph)37 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)34 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)32 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)24 List (java.util.List)20 Map (java.util.Map)20 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)19 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)19 ObjectParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.ObjectParameterType.ObjectParameterValue)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)17 IOException (java.io.IOException)17