use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class DataAccessUtilities method saveDataAccessState.
/**
* Build a data access state from the passed tab pane and save it to the graph.
* <p/>
* Currently only global parameters are saved.
*
* @param tabs the tab pane to build the new data access state from
* @param graph the active graph to save the state to
*/
public static void saveDataAccessState(final TabPane tabs, final Graph graph) {
if (graph != null) {
// Build a new data access state from the passed tabs
final DataAccessState dataAccessState = new DataAccessState();
tabs.getTabs().forEach(step -> {
dataAccessState.newTab();
DataAccessTabPane.getQueryPhasePane(step).getGlobalParametersPane().getParams().getParameters().entrySet().stream().filter(entry -> entry.getValue().getStringValue() != null).forEach(entry -> dataAccessState.add(entry.getKey(), entry.getValue().getStringValue()));
});
// Save the state onto the graph
WritableGraph wg = null;
try {
wg = graph.getWritableGraph("Update Data Access State", true);
final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.ensure(wg);
wg.setObjectValue(dataAccessStateAttribute, 0, dataAccessState);
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
} finally {
if (wg != null) {
wg.commit();
}
}
}
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class DataAccessPaneNGTest method update_pass_non_null_graph.
@Test
public void update_pass_non_null_graph() {
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final Tab currentTab = mock(Tab.class);
final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
final DataSourceTitledPane dataSourceTitledPane = mock(DataSourceTitledPane.class);
final Plugin plugin = mock(Plugin.class);
final PluginParameters pluginParameters = mock(PluginParameters.class);
final Graph graph = mock(Graph.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane));
when(dataSourceTitledPane.getPlugin()).thenReturn(plugin);
when(dataSourceTitledPane.getParameters()).thenReturn(pluginParameters);
when(graph.getId()).thenReturn("graphId");
dataAccessPane.update(graph);
verify(plugin).updateParameters(graph, pluginParameters);
verify(dataAccessPane).update("graphId");
}
use of au.gov.asd.tac.constellation.graph.Graph 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.graph.Graph in project constellation by constellation-app.
the class ExtractWordsFromTextPluginNGTest method testUpdateParameters.
/**
* Test updateParameters
*/
@Test
public void testUpdateParameters() {
ExtractWordsFromTextPlugin instance = new ExtractWordsFromTextPlugin();
PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> attributeType = SingleChoiceParameterType.build(ATTRIBUTE_PARAMETER_ID);
parameters.addParameter(attributeType);
final PluginParameter<StringParameterValue> textParameter = StringParameterType.build(WORDS_PARAMETER_ID);
textParameter.setStringValue("text");
parameters.addParameter(textParameter);
final PluginParameter<BooleanParameterValue> useRegexParameter = BooleanParameterType.build(USE_REGEX_PARAMETER_ID);
useRegexParameter.setBooleanValue(true);
parameters.addParameter(useRegexParameter);
Graph graph1 = new DualGraph(graph.getSchema(), graph);
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 3);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.ATTRIBUTE_PARAMETER_ID));
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.WORDS_PARAMETER_ID).getStringValue(), "text");
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.USE_REGEX_PARAMETER_ID).getBooleanValue(), true);
assertFalse(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
parameters = instance.createParameters();
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 11);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
}
use of au.gov.asd.tac.constellation.graph.Graph in project constellation by constellation-app.
the class RecordStoreQueryPluginNGTest method testEdit.
/**
* Test of edit method, of class RecordStoreQueryPlugin.
*/
@Test
public void testEdit() throws InterruptedException, PluginException {
System.out.println("edit");
final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
// only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
final Graph graph = new DualGraph(schema);
final PluginInteraction interaction = null;
final PluginParameters parameters = null;
ReadableGraph rg = graph.getReadableGraph();
try {
instance.read(rg, interaction, parameters);
instance.query(interaction, parameters);
} finally {
rg.release();
}
GraphRecordStore query;
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getAll(rg, false, false);
} finally {
rg.release();
}
final WritableGraph wg = graph.getWritableGraph("", true);
try {
VisualConcept.VertexAttribute.X.ensure(wg);
VisualConcept.VertexAttribute.Y.ensure(wg);
VisualConcept.VertexAttribute.Z.ensure(wg);
VisualConcept.GraphAttribute.CAMERA.ensure(wg);
instance.edit(wg, interaction, parameters);
} finally {
wg.commit();
}
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
} finally {
rg.release();
}
// verify nothing has moved
query.reset();
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
Aggregations