use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class DataSourceTitledPaneNGTest method setParametersNonNullPerPluginParamMap.
@Test
public void setParametersNonNullPerPluginParamMap() {
final String actionKey = "actionKey";
final String nonActionKey = "nonActionKey";
final String value = "value";
final PluginParameter<?> nonActionPluginParameter = mock(PluginParameter.class);
final PluginParameter<?> actionPluginParameter = mock(PluginParameter.class);
when(nonActionPluginParameter.getId()).thenReturn("Not ActionParameterType.ID");
when(actionPluginParameter.getId()).thenReturn(ActionParameterType.ID);
final Map<String, PluginParameter<?>> parameters = Map.of(actionKey, actionPluginParameter, nonActionKey, nonActionPluginParameter);
when(dataSourceParameters.hasParameter(actionKey)).thenReturn(true);
when(dataSourceParameters.hasParameter(nonActionKey)).thenReturn(true);
when(dataSourceParameters.getParameters()).thenReturn(parameters);
final Map<String, String> perPluginParamMap = Map.of(actionKey, value, nonActionKey, value, GLOBAL_PARAM_1, value, GLOBAL_PARAM_2, value);
dataSourceTitledPane.setParameterValues(perPluginParamMap);
// The set parameters happens in its own thread. We add the loop to ensure
// there isn't a race condition happening.
PluginParameters pluginParameters;
// need a safety catch so it doesn't get stuck
int counter = 0;
while ((pluginParameters = dataSourceTitledPane.getParameters()) == null && counter < 3) {
Thread.yield();
counter++;
}
;
assertSame(pluginParameters, dataSourceParameters);
verify(nonActionPluginParameter).setStringValue(value);
verify(actionPluginParameter, times(0)).setStringValue(value);
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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.parameters.PluginParameter in project constellation by constellation-app.
the class MergeNodesByPrefixNGTest method testUpdateParameters.
/**
* Test of updateParameters method.
*/
@Test
public void testUpdateParameters() {
System.out.println("testUpdateParameters");
final PluginParameters pluginParameters = new PluginParameters();
pluginParameters.addParameter(BooleanParameterType.build(MERGE_TYPE_PARAMETER_ID));
pluginParameters.addParameter(IntegerParameterType.build(THRESHOLD_PARAMETER_ID));
pluginParameters.addParameter(BooleanParameterType.build(MERGER_PARAMETER_ID));
pluginParameters.addParameter(BooleanParameterType.build(LEAD_PARAMETER_ID));
pluginParameters.addParameter(BooleanParameterType.build(SELECTED_PARAMETER_ID));
final Map<String, PluginParameter<?>> parameters = pluginParameters.getParameters();
final MergeNodesByPrefix instance = new MergeNodesByPrefix();
instance.updateParameters(parameters);
assertTrue(parameters.get(MERGE_TYPE_PARAMETER_ID).isEnabled());
assertEquals(parameters.get(THRESHOLD_PARAMETER_ID).getDescription(), "The prefix length to consider");
assertEquals(parameters.get(THRESHOLD_PARAMETER_ID).getIntegerValue(), 9);
assertTrue(parameters.get(THRESHOLD_PARAMETER_ID).isEnabled());
assertTrue(parameters.get(MERGER_PARAMETER_ID).isEnabled());
assertTrue(parameters.get(LEAD_PARAMETER_ID).isEnabled());
assertTrue(parameters.get(SELECTED_PARAMETER_ID).isEnabled());
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class MergeNodesByTypeNGTest method testUpdateParameters.
/**
* Test of updateParameters method, of class MergeNodesByType.
*/
@Test
public void testUpdateParameters() {
System.out.println("testUpdateParameters");
final MergeNodesByType instance = new MergeNodesByType();
final PluginParameters parameters = new PluginParameters();
final PluginParameter<BooleanParameterType.BooleanParameterValue> mergeTypeParameter = BooleanParameterType.build(MERGE_TYPE_PARAMETER_ID);
mergeTypeParameter.setBooleanValue(false);
parameters.addParameter(mergeTypeParameter);
final PluginParameter<IntegerParameterType.IntegerParameterValue> thresholdParameter = IntegerParameterType.build(THRESHOLD_PARAMETER_ID);
thresholdParameter.setIntegerValue(0);
parameters.addParameter(thresholdParameter);
final PluginParameter<BooleanParameterType.BooleanParameterValue> mergeParameter = BooleanParameterType.build(MERGER_PARAMETER_ID);
mergeParameter.setBooleanValue(false);
parameters.addParameter(mergeParameter);
final PluginParameter<BooleanParameterType.BooleanParameterValue> leadParameter = BooleanParameterType.build(LEAD_PARAMETER_ID);
leadParameter.setBooleanValue(false);
parameters.addParameter(leadParameter);
final PluginParameter<BooleanParameterType.BooleanParameterValue> selectedParameter = BooleanParameterType.build(SELECTED_PARAMETER_ID);
selectedParameter.setBooleanValue(false);
parameters.addParameter(selectedParameter);
final Map<String, PluginParameter<?>> parametersMap = parameters.getParameters();
instance.updateParameters(parametersMap);
assertEquals(parametersMap.size(), 5);
assertTrue(parametersMap.get(MERGE_TYPE_PARAMETER_ID).isEnabled());
assertFalse(parametersMap.get(THRESHOLD_PARAMETER_ID).isEnabled());
assertTrue(parametersMap.get(MERGER_PARAMETER_ID).isEnabled());
assertFalse(parametersMap.get(LEAD_PARAMETER_ID).isEnabled());
assertTrue(parametersMap.get(SELECTED_PARAMETER_ID).isEnabled());
}
use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.
the class MergeNodesPluginNGTest method editMergeError.
@Test(expectedExceptions = PluginException.class)
public void editMergeError() throws InterruptedException, PluginException, MergeNodeType.MergeException {
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
final PluginInteraction interaction = mock(PluginInteraction.class);
final PluginParameters parameters = mock(PluginParameters.class);
final PluginParameter mergeTypeParameter = mock(PluginParameter.class);
final PluginParameter thresholdParameter = mock(PluginParameter.class);
final PluginParameter mergerParameter = mock(PluginParameter.class);
final PluginParameter leadParameter = mock(PluginParameter.class);
final PluginParameter selectedParameter = mock(PluginParameter.class);
final Map<String, PluginParameter<?>> pluginParameters = Map.of("MergeNodesPlugin.merge_type", mergeTypeParameter, "MergeNodesPlugin.threshold", thresholdParameter, "MergeNodesPlugin.merger", mergerParameter, "MergeNodesPlugin.lead", leadParameter, "MergeNodesPlugin.selected", selectedParameter);
when(parameters.getParameters()).thenReturn(pluginParameters);
when(mergeTypeParameter.getStringValue()).thenReturn(TestMergeType.NAME);
when(thresholdParameter.getIntegerValue()).thenReturn(TestMergeType.MERGE_EXCEPTION_THRESHOLD);
when(mergerParameter.getStringValue()).thenReturn("Retain lead vertex attributes if present");
when(leadParameter.getStringValue()).thenReturn("Longest Value");
when(selectedParameter.getBooleanValue()).thenReturn(true);
mergeNodesPlugin.edit(graph, interaction, parameters);
}
Aggregations