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