Search in sources :

Example 1 with NotificationDisplayer

use of org.openide.awt.NotificationDisplayer 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 NotificationDisplayer

use of org.openide.awt.NotificationDisplayer in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testRun3.

/**
 * Test of run method, of class PluginDisplayer. Testing when daPane is null
 */
@Test
public void testRun3() {
    System.out.println("testRun3 null data access pane");
    // Setting up mocks
    notifDisplayer = mock(NotificationDisplayer.class);
    final Notification notif = new Notification() {

        @Override
        public void clear() {
        // do nothing, used for testing.
        }
    };
    // Setting up a mock for DataAccessUtilities to return null when fetching the pane.
    try (MockedStatic<DataAccessUtilities> mockedStatic1 = Mockito.mockStatic(DataAccessUtilities.class)) {
        mockedStatic1.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(null);
        // Mock the static method getDefault() to return the mock of NotificationDisplayer
        try (MockedStatic<NotificationDisplayer> mockedStatic3 = Mockito.mockStatic(NotificationDisplayer.class)) {
            when(notifDisplayer.notify("Data Access view", WARNING_ICON, "Please open the Data Access view and create a step.", null)).thenReturn(notif);
            mockedStatic3.when(() -> NotificationDisplayer.getDefault()).thenReturn(notifDisplayer);
            ShowDataAccessPluginTask pd = new ShowDataAccessPluginTask("SelectTopN");
            pd.run();
            // verify notificationdisplayer was called with correct string
            verify(notifDisplayer, times(1)).notify(Mockito.anyString(), Mockito.eq(WARNING_ICON), Mockito.eq("Please open the Data Access view and create a step."), Mockito.eq(null));
        }
    }
}
Also used : ShowDataAccessPluginTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) NotificationDisplayer(org.openide.awt.NotificationDisplayer) Notification(org.openide.awt.Notification) Test(org.testng.annotations.Test)

Example 3 with NotificationDisplayer

use of org.openide.awt.NotificationDisplayer in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testRun2.

/**
 * Test of run method, of class PluginDisplayer. Testing when tab is null
 */
@Test
public void testRun2() {
    System.out.println("testRun2 testing null tab returned");
    // Setting up mocks
    daPane = mock(DataAccessPane.class);
    datPane = mock(DataAccessTabPane.class);
    notifDisplayer = mock(NotificationDisplayer.class);
    final Notification notif = new Notification() {

        @Override
        public void clear() {
        // do nothing, used for testing.
        }
    };
    // Setting up a mock for DataAccessUtilities to return null when fetching the pane.
    try (MockedStatic<DataAccessUtilities> mockedStatic1 = Mockito.mockStatic(DataAccessUtilities.class)) {
        when(daPane.getDataAccessTabPane()).thenReturn(datPane);
        when(datPane.getCurrentTab()).thenReturn(null);
        mockedStatic1.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(daPane);
        // Mock the static method getDefault() to return the mock of NotificationDisplayer
        try (MockedStatic<NotificationDisplayer> mockedStatic3 = Mockito.mockStatic(NotificationDisplayer.class)) {
            when(notifDisplayer.notify("Data Access view", WARNING_ICON, "Please create a step in the Data Access view.", null)).thenReturn(notif);
            mockedStatic3.when(() -> NotificationDisplayer.getDefault()).thenReturn(notifDisplayer);
            ShowDataAccessPluginTask pd = new ShowDataAccessPluginTask("SelectTopN");
            pd.run();
            // Verify that the current tab was attempted to be retrieved
            verify(datPane, times(1)).getCurrentTab();
            // verify notificationdisplayer was called with correct string
            verify(notifDisplayer, times(1)).notify(Mockito.anyString(), Mockito.eq(WARNING_ICON), Mockito.eq("Please create a step in the Data Access view."), Mockito.eq(null));
        }
    }
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) ShowDataAccessPluginTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) NotificationDisplayer(org.openide.awt.NotificationDisplayer) Notification(org.openide.awt.Notification) Test(org.testng.annotations.Test)

Example 4 with NotificationDisplayer

use of org.openide.awt.NotificationDisplayer in project constellation by constellation-app.

the class NotifyDisplayerNGTest method displayWithIcon.

/**
 * Configurable test for the display notification with icon method.
 *
 * @param isEventDispatchThread true if the test is meant to be running in the event dispatch thread, false otherwise
 * @param isFxApplicationThread true if the test is meant to be running in the fx application thread, false otherwise
 * @param runThroughThread true if the call is meant to run through a separate thread first, false otherwise
 */
private void displayWithIcon(final boolean isEventDispatchThread, final boolean isFxApplicationThread, final boolean runThroughThread) {
    try (final MockedStatic<EventQueue> eventQueueMockedStatic = Mockito.mockStatic(EventQueue.class);
        final MockedStatic<CompletableFuture> completableFutureMockedStatic = Mockito.mockStatic(CompletableFuture.class);
        final MockedStatic<NotificationDisplayer> notificationDisplayerMockedStatic = Mockito.mockStatic(NotificationDisplayer.class);
        final MockedStatic<SwingUtilities> swingUtilitiesMockedStatic = Mockito.mockStatic(SwingUtilities.class);
        final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        setupThreadingMocks(eventQueueMockedStatic, completableFutureMockedStatic, swingUtilitiesMockedStatic, platformMockedStatic);
        final NotificationDisplayer notificationDisplayer = mock(NotificationDisplayer.class);
        notificationDisplayerMockedStatic.when(NotificationDisplayer::getDefault).thenReturn(notificationDisplayer);
        swingUtilitiesMockedStatic.when(SwingUtilities::isEventDispatchThread).thenReturn(isEventDispatchThread);
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(isFxApplicationThread);
        final String title = "TITLE";
        final Icon icon = mock(Icon.class);
        final String message = "MESSAGE";
        NotifyDisplayer.display(title, icon, message);
        verify(notificationDisplayer).notify(title, icon, message, null);
        if (runThroughThread) {
            completableFutureMockedStatic.verify(() -> CompletableFuture.runAsync(any(Runnable.class)));
        } else {
            completableFutureMockedStatic.verifyNoInteractions();
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Platform(javafx.application.Platform) NotificationDisplayer(org.openide.awt.NotificationDisplayer) SwingUtilities(javax.swing.SwingUtilities) Icon(javax.swing.Icon) EventQueue(java.awt.EventQueue)

Example 5 with NotificationDisplayer

use of org.openide.awt.NotificationDisplayer in project constellation by constellation-app.

the class WaitForQueriesToCompleteTaskNGTest method run_plugin_exception.

@Test
public void run_plugin_exception() {
    paneStateMockedStatic.when(() -> DataAccessPaneState.getRunningPlugins(GRAPH_ID)).thenReturn(Map.of(CompletableFuture.supplyAsync(() -> "I'm Complete"), "plugin1", CompletableFuture.supplyAsync(() -> {
        throw new RuntimeException("I am an error");
    }), "plugin2"));
    paneStateMockedStatic.when(DataAccessPaneState::getCurrentGraphId).thenReturn(GRAPH_ID);
    final NotificationDisplayer notificationDisplayer = mock(NotificationDisplayer.class);
    notificationDisplayerMockedStatic.when(NotificationDisplayer::getDefault).thenReturn(notificationDisplayer);
    doReturn(null).when(notificationDisplayer).notify(anyString(), any(Icon.class), anyString(), isNull(), eq(NotificationDisplayer.Priority.HIGH));
    waitForQueriesToCompleteTask.run();
    verify(notificationDisplayer).notify("Data Access Plug-In 'plugin2' Errored. Did NOT Finish.", UserInterfaceIconProvider.ERROR.buildIcon(16, ConstellationColor.CHERRY.getJavaColor()), "I am an error", null, NotificationDisplayer.Priority.HIGH);
    paneStateMockedStatic.verify(() -> DataAccessPaneState.setQueriesRunning(GRAPH_ID, false));
    paneStateMockedStatic.verify(() -> DataAccessPaneState.removeAllRunningPlugins(GRAPH_ID));
    verify(dataAccessPane).update();
}
Also used : NotificationDisplayer(org.openide.awt.NotificationDisplayer) Icon(javax.swing.Icon) Test(org.testng.annotations.Test)

Aggregations

NotificationDisplayer (org.openide.awt.NotificationDisplayer)5 Icon (javax.swing.Icon)3 Test (org.testng.annotations.Test)3 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)2 ShowDataAccessPluginTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask)2 DataAccessUtilities (au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities)2 Notification (org.openide.awt.Notification)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 DataAccessViewTopComponent (au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent)1 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)1 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)1 EventQueue (java.awt.EventQueue)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1