Search in sources :

Example 1 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class TabContextMenuNGTest method verifyFindPluginMenuItemAction.

/**
 * Verify the find plugin is run when the menu item is clicked.
 *
 * @param findPluginMenuItem the find plugin menu item
 */
private void verifyFindPluginMenuItemAction(final MenuItem findPluginMenuItem) {
    try (final MockedStatic<DataAccessTabPane> tabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class);
        final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
        when(dataAccessTabPane.getDataAccessPane()).thenReturn(dataAccessPane);
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        tabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab)).thenReturn(queryPhasePane);
        platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer(iom -> {
            // The code is run in the JavaFX thread, so intercept it and run locally
            final Runnable action = iom.getArgument(0);
            // The code constructs a plugin finder and then calls find. Need to inject
            // a mock into that construction
            final MockedConstruction<PluginFinder> mockedPluginFinders = Mockito.mockConstruction(PluginFinder.class);
            action.run();
            // Verify the plugin finder was created and used as expected
            assertEquals(mockedPluginFinders.constructed().size(), 1);
            verify(mockedPluginFinders.constructed().get(0)).find(queryPhasePane);
            return null;
        });
        final ActionEvent actionEvent = mock(ActionEvent.class);
        findPluginMenuItem.getOnAction().handle(actionEvent);
        verify(actionEvent).consume();
    }
}
Also used : Platform(javafx.application.Platform) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) PluginFinder(au.gov.asd.tac.constellation.views.dataaccess.panes.PluginFinder) ActionEvent(javafx.event.ActionEvent)

Example 2 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessViewTopComponentNGTest method handleComponentOpened.

@Test(enabled = false)
public void handleComponentOpened() {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doReturn(dataAccessPane).when(spiedTopComponent).getDataAccessPane();
    try (final MockedStatic<QualityControlAutoVetter> qualityControlAutoVetterMockedStatic = Mockito.mockStatic(QualityControlAutoVetter.class)) {
        final QualityControlAutoVetter instance = mock(QualityControlAutoVetter.class);
        qualityControlAutoVetterMockedStatic.when(QualityControlAutoVetter::getInstance).thenReturn(instance);
        spiedTopComponent.handleComponentOpened();
        verify(instance).addObserver(dataAccessPane);
    }
}
Also used : QualityControlAutoVetter(au.gov.asd.tac.constellation.views.qualitycontrol.daemon.QualityControlAutoVetter) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Example 3 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class ShowDataAccessPluginTask method run.

/**
 * Gets the data access pane view and gets the pane of the current tab. Searches
 * the pane for the provided plugin name and if found, it will expand that plugin.
 * <p/>
 * If the data access view is closed or there is not current tab then a error
 * notification is displayed.
 */
@Override
public void run() {
    final String message;
    final DataAccessPane dataAccessPane = DataAccessUtilities.getDataAccessPane();
    if (dataAccessPane != null) {
        final Tab tab = dataAccessPane.getDataAccessTabPane().getCurrentTab();
        if (tab != null) {
            final QueryPhasePane queryPhasePane = DataAccessTabPane.getQueryPhasePane(tab);
            Platform.runLater(() -> queryPhasePane.expandPlugin(pluginName));
            return;
        } else {
            message = STEP_STRING;
        }
    } else {
        message = DAV_STEP_STRING;
    }
    NotificationDisplayer.getDefault().notify(NOTIFICATION_TITLE, WARNING_ICON, message, null);
}
Also used : Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)

Example 4 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane 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 5 with DataAccessPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane in project constellation by constellation-app.

the class DataAccessUtilitiesNGTest method loadDataAccessState.

@Test
public void loadDataAccessState() {
    // Create current data access view state and set some parameters
    // The code currenly only looks at the first tab so parameter2
    // value will be ignored
    final DataAccessState currentState = new DataAccessState();
    currentState.newTab();
    currentState.add("parameter1", "parameter1_new_value");
    currentState.newTab();
    currentState.add("parameter2", "parameter2_new_value");
    // mock graph
    final Graph graph = mock(Graph.class);
    final ReadableGraph rGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(rGraph);
    // mock data access state attribute in graph
    when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
    when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
    // mock tab pane
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final TabPane tabPane = mock(TabPane.class);
    final Tab currentTab = mock(Tab.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
    try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
        final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
        final PluginParameters globalPluginParameters = mock(PluginParameters.class);
        final PluginParameter pluginParameter1 = mock(PluginParameter.class);
        final PluginParameter pluginParameter2 = mock(PluginParameter.class);
        when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
        when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
        when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
        DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
        verify(pluginParameter1).setStringValue("parameter1_new_value");
        verify(pluginParameter2, never()).setStringValue(anyString());
        verify(rGraph).release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Aggregations

DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)19 Test (org.testng.annotations.Test)15 Graph (au.gov.asd.tac.constellation.graph.Graph)8 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)8 Tab (javafx.scene.control.Tab)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)5 DataAccessViewTopComponent (au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent)4 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3 TabPane (javafx.scene.control.TabPane)3 WindowManager (org.openide.windows.WindowManager)3 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 JsonIO (au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO)2 DataAccessUserPreferences (au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences)2 DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)2 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)2 DataAccessState (au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)2 QualityControlAutoVetter (au.gov.asd.tac.constellation.views.qualitycontrol.daemon.QualityControlAutoVetter)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2