use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class DataAccessUserPreferencesNGTest method initWithPane.
@Test
public void initWithPane() {
final QueryPhasePane tab = mock(QueryPhasePane.class);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
when(tab.getGlobalParametersPane()).thenReturn(globalParametersPane);
final Plugin plugin1 = mock(Plugin.class);
final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(true);
final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(false);
when(tab.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
final PluginParameterType passwordType = mock(PluginParameterType.class);
when(passwordType.getId()).thenReturn("password");
final PluginParameterType stringType = mock(PluginParameterType.class);
when(stringType.getId()).thenReturn("string");
// Plugin params will be in global and plugin but because it is in global
// it should not be included in the plugin section
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
when(pluginParameter1.getId()).thenReturn("param1");
when(pluginParameter1.getStringValue()).thenReturn("value1");
when(pluginParameter1.getType()).thenReturn(stringType);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(pluginParameter2.getId()).thenReturn("param2");
when(pluginParameter2.getStringValue()).thenReturn("value2");
when(pluginParameter2.getType()).thenReturn(stringType);
final PluginParameter pluginParameter3 = mock(PluginParameter.class);
when(pluginParameter3.getId()).thenReturn("param3");
when(pluginParameter3.getStringValue()).thenReturn("value3");
when(pluginParameter3.getType()).thenReturn(stringType);
// Param 4 is of password type and should not be added
final PluginParameter pluginParameter4 = mock(PluginParameter.class);
when(pluginParameter4.getId()).thenReturn("param4");
when(pluginParameter4.getStringValue()).thenReturn("value4");
when(pluginParameter4.getType()).thenReturn(passwordType);
// Set the global parameters
final PluginParameters globalPluginParameters1 = new PluginParameters();
globalPluginParameters1.addParameter(pluginParameter1);
globalPluginParameters1.addParameter(pluginParameter2);
// Set the parameters for plugin1
final PluginParameters plugin1Parameters = new PluginParameters();
plugin1Parameters.addParameter(pluginParameter1);
plugin1Parameters.addParameter(pluginParameter3);
plugin1Parameters.addParameter(pluginParameter4);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters1);
when(dataSourceTitledPane1.getParameters()).thenReturn(plugin1Parameters);
final DataAccessUserPreferences preferences = new DataAccessUserPreferences(tab);
final DataAccessUserPreferences expectedPreferences = new DataAccessUserPreferences();
expectedPreferences.setGlobalParameters(Map.of("param1", "value1", "param2", "value2"));
final Map<String, Map<String, String>> examplePluginParameters = new HashMap<>();
examplePluginParameters.put(plugin1.getClass().getSimpleName(), Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", "param3", "value3"));
expectedPreferences.setPluginParameters(examplePluginParameters);
assertEquals(preferences, expectedPreferences);
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class QueryPhasePane method runPlugins.
/**
* Run the plugin for each data access pane in this query pane, optionally
* waiting first on a list of passed futures. This method will start the
* plugin execution and return a list of futures representing each plugins
* execution.
*
* @param async if not null, the plugins to be executed will wait till all the
* futures in the list have been completed before running
* @return a list of futures representing the plugins that were executed
*/
public List<Future<?>> runPlugins(final List<Future<?>> async) {
// Get the global plugin parameters for this query pane
final Map<String, PluginParameter<?>> globalParams = getGlobalParametersPane().getParams().getParameters();
// Pre-query validation checking
for (final DataAccessPreQueryValidation check : PRE_QUERY_VALIDATION) {
if (!check.execute(this)) {
return Collections.emptyList();
}
}
// Determine the number of plugins that will be executed
final int pluginsToRun = Long.valueOf(getDataAccessPanes().stream().filter(DataSourceTitledPane::isQueryEnabled).count()).intValue();
LOGGER.log(Level.INFO, "\tRunning {0} plugins", pluginsToRun);
final PluginSynchronizer synchroniser = new PluginSynchronizer(pluginsToRun);
final List<Future<?>> newAsync = new ArrayList<>(pluginsToRun);
getDataAccessPanes().stream().filter(DataSourceTitledPane::isQueryEnabled).forEach(pane -> {
// Copy global parameters into plugin parameters where there
// is overlap
PluginParameters parameters = pane.getParameters();
if (parameters != null) {
parameters = parameters.copy();
parameters.getParameters().entrySet().stream().filter(entry -> globalParams.containsKey(entry.getKey())).forEach(entry -> entry.getValue().setObjectValue(globalParams.get(entry.getKey()).getObjectValue()));
}
// Get the plugin for this pane and run it
final Plugin plugin = PluginRegistry.get(pane.getPlugin().getClass().getName());
LOGGER.log(Level.INFO, "\t\tRunning {0}", plugin.getName());
final Future<?> pluginResult = PluginExecution.withPlugin(plugin).withParameters(parameters).waitingFor(async).synchronizingOn(synchroniser).executeLater(GraphManager.getDefault().getActiveGraph());
newAsync.add(pluginResult);
DataAccessPaneState.addRunningPlugin(pluginResult, plugin.getName());
});
return newAsync;
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class SaveResultsFileWriterNGTest method testGenerateFilename.
/**
* Test of generateFilename method. Ensure that generated filename is of the
* correct format yyyyMMddTHHmmssSSS.
*/
@Test
public void testGenerateFilename() {
Plugin plugin = new ExampleClass();
String filename = SaveResultsFileWriter.generateFilename(plugin, "xml");
Pattern pattern = Pattern.compile("[0-9]{8}T[0-9]{9}-ExampleClass.xml");
Matcher matcher = pattern.matcher(filename);
Assert.assertTrue(matcher.matches(), "Testing generated filename matches pattern - yyyyMMddTHHmmssSSS.");
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class SaveResultsFileWriterNGTest method testWriteRecordStoreNoDataAccessResultsDir.
/**
* Test of writeRecordStore method for case when
* DataAccessPreferenceKeys.getDataAccessResultsDir() returns null. The
* expectation is that no attempted writes are made. This test executes a
* code path through SaveResultsFileWriter.writeRecordStore that does not
* throw an exception.
*
* @throws java.lang.Exception
*/
@Test
public void testWriteRecordStoreNoDataAccessResultsDir() throws Exception {
Plugin plugin = new ExampleClass();
TabularRecordStore tabularRecordStore = new TabularRecordStore();
mockedDataAccessPreferenceKeys.when(() -> DataAccessPreferenceUtilities.getDataAccessResultsDir()).thenReturn(null);
SaveResultsFileWriter.writeRecordStore(plugin, tabularRecordStore);
Assert.assertTrue(true, "Testing writing record to non existant directory - code will do nothing.");
}
use of au.gov.asd.tac.constellation.plugins.Plugin in project constellation by constellation-app.
the class DataAccessPaneNGTest method update_pass_null_graph.
@Test
public void update_pass_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);
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);
dataAccessPane.update((Graph) null);
verify(plugin).updateParameters(null, pluginParameters);
verify(dataAccessPane).update((String) null);
}
Aggregations