Search in sources :

Example 1 with DataAccessViewTopComponent

use of au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent 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 DataAccessViewTopComponent

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

the class DataAccessUtilitiesNGTest method testGetDataAccessPaneCalledByEventDispatchThread.

@Test
public void testGetDataAccessPaneCalledByEventDispatchThread() {
    final WindowManager windowManager = mock(WindowManager.class);
    final DataAccessViewTopComponent topComponent = mock(DataAccessViewTopComponent.class);
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    swingUtilitiesStaticMock.when(SwingUtilities::isEventDispatchThread).thenReturn(true);
    windowManagerStaticMock.when(WindowManager::getDefault).thenReturn(windowManager);
    when(windowManager.findTopComponent(DataAccessViewTopComponent.class.getSimpleName())).thenReturn(topComponent);
    when(topComponent.isOpened()).thenReturn(false);
    when(topComponent.getDataAccessPane()).thenReturn(dataAccessPane);
    DataAccessPane actual = DataAccessUtilities.getDataAccessPane();
    verify(topComponent, times(1)).open();
    verify(topComponent, times(1)).requestVisible();
    assertSame(actual, dataAccessPane);
}
Also used : DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) WindowManager(org.openide.windows.WindowManager) Test(org.testng.annotations.Test)

Example 3 with DataAccessViewTopComponent

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

the class DataAccessUtilitiesNGTest method testGetDataAccessPaneNotCalledByEventDispatchThread.

@Test
public void testGetDataAccessPaneNotCalledByEventDispatchThread() {
    final WindowManager windowManager = mock(WindowManager.class);
    final DataAccessViewTopComponent topComponent = mock(DataAccessViewTopComponent.class);
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    swingUtilitiesStaticMock.when(SwingUtilities::isEventDispatchThread).thenReturn(false);
    swingUtilitiesStaticMock.when(() -> SwingUtilities.invokeAndWait(any(Runnable.class))).thenAnswer(invocation -> {
        final Runnable r = invocation.getArgument(0);
        r.run();
        return null;
    });
    windowManagerStaticMock.when(WindowManager::getDefault).thenReturn(windowManager);
    when(windowManager.findTopComponent(DataAccessViewTopComponent.class.getSimpleName())).thenReturn(topComponent);
    when(topComponent.isOpened()).thenReturn(false);
    when(topComponent.getDataAccessPane()).thenReturn(dataAccessPane);
    DataAccessPane actual = DataAccessUtilities.getDataAccessPane();
    assertSame(actual, dataAccessPane);
}
Also used : DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) WindowManager(org.openide.windows.WindowManager) Test(org.testng.annotations.Test)

Aggregations

DataAccessViewTopComponent (au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent)3 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)3 WindowManager (org.openide.windows.WindowManager)2 Test (org.testng.annotations.Test)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)1 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)1 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)1 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)1 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)1 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)1 ExecutorService (java.util.concurrent.ExecutorService)1 TabPane (javafx.scene.control.TabPane)1 Icon (javax.swing.Icon)1 NotificationDisplayer (org.openide.awt.NotificationDisplayer)1 StatusDisplayer (org.openide.awt.StatusDisplayer)1 BeforeMethod (org.testng.annotations.BeforeMethod)1