use of au.gov.asd.tac.constellation.plugins.PluginExecution 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.plugins.PluginExecution in project constellation by constellation-app.
the class QueryPhasePaneNGTest method testRunPlugins.
@Test
public void testRunPlugins() {
// Initialize the current graph in the state.
DataAccessPaneState.setCurrentGraphId("GraphId");
final QueryPhasePane instance = spy(new QueryPhasePane(new HashMap<>(), null, null));
// Setup the graph manager
final GraphManager graphManager = mock(GraphManager.class);
final Graph graph = mock(Graph.class);
when(graphManager.getActiveGraph()).thenReturn(graph);
// Setup the global parameters
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
final PluginParameter globalPluginParameter1 = mock(PluginParameter.class);
final PluginParameter globalPluginParameter2 = mock(PluginParameter.class);
doReturn(globalParametersPane).when(instance).getGlobalParametersPane();
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", globalPluginParameter1, "global.parameter1", globalPluginParameter2));
when(globalPluginParameter1.getObjectValue()).thenReturn("GLOBAL PARAMETER 1");
// Setup data access panes
final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
doReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2)).when(instance).getDataAccessPanes();
// Pane 1 is disabled so will not be run
when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
// Setup the plugin for pane 2
final Plugin plugin = mock(Plugin.class);
when(plugin.getName()).thenReturn("Plugin Name");
when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
// Pane 2 has two parameters. One of them matches in name to one of
// the global parameters which means its value will be overriden with
// the global value.
final PluginParameters pluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(pluginParameters.getParameters()).thenReturn(Map.of("abc.parameter1", pluginParameter1, "abc.parameter2", pluginParameter2));
when(pluginParameters.copy()).thenReturn(pluginParameters);
when(dataSourceTitledPane2.getParameters()).thenReturn(pluginParameters);
try (final MockedStatic<PluginRegistry> pluginRegistry = Mockito.mockStatic(PluginRegistry.class);
final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class);
final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class);
final MockedConstruction<PluginSynchronizer> pluginSynchMocks = Mockito.mockConstruction(PluginSynchronizer.class, (pluginSyncMock, cnxt) -> {
assertEquals(cnxt.arguments(), List.of(1));
})) {
// Not sure why this is being done but just retuning the same plugin
// to save creating another mock.
pluginRegistry.when(() -> PluginRegistry.get(plugin.getClass().getName())).thenReturn(plugin);
graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
// This is the future that will be returned when the plugin begins execution
final Future future = CompletableFuture.completedFuture("Plugin Complete!");
// This is the future of a plugin that was run previously
final Future existingFuture = CompletableFuture.completedFuture("Previous Plugin Complete!");
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(plugin)).thenReturn(pluginExecution);
// We don't need to verify any of these again (with the exception of the plugin synchronizer)
// because a null pointer will happen if any of the params don't match up.
when(pluginExecution.withParameters(pluginParameters)).thenReturn(pluginExecution);
when(pluginExecution.waitingFor(List.of(existingFuture))).thenReturn(pluginExecution);
when(pluginExecution.synchronizingOn(any(PluginSynchronizer.class))).thenReturn(pluginExecution);
when(pluginExecution.executeLater(graph)).thenReturn(future);
// Verify that the return contains the plugin future as defined above
assertEquals(instance.runPlugins(List.of(existingFuture)), List.of(future));
// Verify the state's running plugin list has been updated
assertEquals(DataAccessPaneState.getRunningPlugins(), Map.of(future, "Plugin Name"));
// Verify the local plugin parameter was updated with the global parameter value
verify(pluginParameter1).setObjectValue("GLOBAL PARAMETER 1");
// Verify the created plugin synchronizer is passed to the plugin execution
verify(pluginExecution).synchronizingOn(pluginSynchMocks.constructed().get(0));
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class FindViewControllerNGTest method testReplaceMatchingElements.
// // Populate the attribute list with the attributes of the given type
// for (Graph graph : gm.getAllGraphs().values()) {
// try {
// System.out.println("in for graph try");
//
// WritableGraph wg = graph.getWritableGraph("", true);
// for (int i = 0; i < stringAttributeList.size(); i++) {
// int attributeInt = wg.getAttribute(type, stringAttributeList.get(i));
// attributes.add(new GraphAttribute(wg, attributeInt));
// System.out.println(attributes.get(i).getName() + " = attribute name");
//
// }
//
// instance.updateBasicFindParameters(parameters);
//
// System.out.println("before method call");
//
// instance.retriveMatchingElements(true, false);
//
// System.out.println("before assert");
// System.out.println(wg.getStringValue(labelV, vxId1));
//
// System.out.println(wg.getBooleanValue(selectedV, vxId1));
// assertEquals(wg.getBooleanValue(selectedV, vxId1), true);
// System.out.println("after equals");
//
// wg.commit();
//
// } catch (final InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// Thread.currentThread().interrupt();
// }
//
// }
//
// }
/**
* Test of replaceMatchingElements method, of class FindViewController.
*/
@Test
public void testReplaceMatchingElements() {
System.out.println("replaceMatchingElements");
/**
* Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
* (2 of type string), 3 transaction attributes (2 of type string)
*/
setupGraph();
/**
* Create a mock of the top component, get an instance of the
* controller, create a mock of the graph manager, when getAllGraphs is
* called return the graphMap created in this class
*/
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
when(gm.getActiveGraph()).thenReturn(graph);
System.out.println("before try");
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
System.out.println("in try");
try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
PluginExecution pluginExecution = mock(PluginExecution.class);
/**
* The first test should execute the plugin once on graph as the
* parameters are not set to look at all graphs
*/
when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution).executeLater(Mockito.eq(graph));
/**
* Set the parameters to find in all graphs and repeat the same
* process. The plugin should be executed on graph a second
* time, and should be executed on graph2 for the first time.
*/
instance.updateBasicReplaceParameters(parametersAllGraphs);
when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
verify(pluginExecution).executeLater(Mockito.eq(graph2));
}
}
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class TableViewTopComponentNGTest method updateStateNotPresentInGraphAttributes.
@Test
public void updateStateNotPresentInGraphAttributes() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
doCallRealMethod().when(tableViewTopComponent).getCurrentState();
final Graph graph = mock(Graph.class);
final Graph currentGraph = mock(Graph.class);
final ReadableGraph readableGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(readableGraph);
when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
when(readableGraph.getObjectValue(42, 0)).thenReturn(null);
when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
final PluginExecution pluginExecution = mock(PluginExecution.class);
pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
assertEquals(new TableViewState(), plugin.getTableViewState());
return pluginExecution;
});
tableViewTopComponent.updateState(graph);
verify(pluginExecution).executeLater(currentGraph);
}
assertEquals(new TableViewState(), tableViewTopComponent.getCurrentState());
verify(graph).getReadableGraph();
verify(readableGraph).release();
}
use of au.gov.asd.tac.constellation.plugins.PluginExecution in project constellation by constellation-app.
the class TableViewTopComponentNGTest method updateStatePresentInGraphAttributes.
@Test
public void updateStatePresentInGraphAttributes() {
final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
doCallRealMethod().when(tableViewTopComponent).updateState(any(Graph.class));
doCallRealMethod().when(tableViewTopComponent).updateState(isNull());
doCallRealMethod().when(tableViewTopComponent).getCurrentState();
final Graph graph = mock(Graph.class);
final ReadableGraph readableGraph = mock(ReadableGraph.class);
final TableViewState state = new TableViewState();
// <-- Non Default Value
state.setElementType(GraphElementType.META);
when(graph.getReadableGraph()).thenReturn(readableGraph);
when(readableGraph.getAttribute(GraphElementType.META, "table_view_state")).thenReturn(42);
when(readableGraph.getObjectValue(42, 0)).thenReturn(state);
try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
tableViewTopComponent.updateState(graph);
pluginExecutionMockedStatic.verifyNoInteractions();
}
assertEquals(state, tableViewTopComponent.getCurrentState());
tableViewTopComponent.updateState(null);
assertEquals(null, tableViewTopComponent.getCurrentState());
// Should only be called once. Second call has null graph
verify(graph).getReadableGraph();
verify(readableGraph).release();
}
Aggregations