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();
}
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));
}
}
}
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));
}
}
}
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();
}
}
}
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();
}
Aggregations