use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues in project constellation by constellation-app.
the class DataAccessTabPane method storeParameterValues.
/**
* Store current parameter values for all tabs and plug-ins in the
* {@link RecentParameterValues} repository. It will store both global and
* plugin parameters.
*/
protected void storeParameterValues() {
getTabPane().getTabs().parallelStream().forEach(tab -> {
final QueryPhasePane pluginPane = getQueryPhasePane(tab);
// Store global parameters
pluginPane.getGlobalParametersPane().getParams().getParameters().entrySet().stream().filter(param -> param.getValue().getStringValue() != null && !param.getValue().getStringValue().isEmpty()).forEach(param -> RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getStringValue()));
// Store data access plugin parameters
pluginPane.getDataAccessPanes().stream().map(DataSourceTitledPane::getParameters).filter(Objects::nonNull).map(PluginParameters::getParameters).map(Map::entrySet).flatMap(Collection::stream).filter(param -> param.getValue().getObjectValue() != null).forEach(param -> {
if (!param.getValue().getType().toString().contains(LOCAL_DATE_PARAMETER_TYPE)) {
RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getStringValue());
} else {
RecentParameterValues.storeRecentValue(param.getKey(), param.getValue().getObjectValue().toString());
}
});
});
}
use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues in project constellation by constellation-app.
the class DataAccessTabPaneNGTest method storeParameterValues_verify_global_params_stored.
@Test
public void storeParameterValues_verify_global_params_stored() {
final TabPane tabPane = mock(TabPane.class);
final Tab tab1 = mock(Tab.class);
final ScrollPane scrollPane = mock(ScrollPane.class);
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
final PluginParameter pluginParameter3 = mock(PluginParameter.class);
// Set up our fake tab pane
doReturn(tabPane).when(dataAccessTabPane).getTabPane();
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1));
when(tab1.getContent()).thenReturn(scrollPane);
when(scrollPane.getContent()).thenReturn(queryPhasePane);
// Set up the global parameters
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters pluginParameters = mock(PluginParameters.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(pluginParameters);
when(pluginParameters.getParameters()).thenReturn(Map.of("plugin1", pluginParameter1, "plugin2", pluginParameter2, "plugin3", pluginParameter3));
// Parameters for plugins 1 and 2 will be dropped because they have no value.
when(pluginParameter1.getStringValue()).thenReturn(null);
when(pluginParameter2.getStringValue()).thenReturn(" ");
when(pluginParameter3.getStringValue()).thenReturn("PluginParam3 String Value");
try (final MockedStatic<RecentParameterValues> recentParamValsMockedStatic = Mockito.mockStatic(RecentParameterValues.class)) {
dataAccessTabPane.storeParameterValues();
// Verify that only plugin 3 parameter was set in the store
recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin3", "PluginParam3 String Value"));
}
}
use of au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues in project constellation by constellation-app.
the class DataAccessTabPaneNGTest method storeParameterValues_verify_plugin_params_stored.
@Test
public void storeParameterValues_verify_plugin_params_stored() {
final TabPane tabPane = mock(TabPane.class);
final Tab tab1 = mock(Tab.class);
final ScrollPane scrollPane = mock(ScrollPane.class);
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
// Set up our fake tab pane
doReturn(tabPane).when(dataAccessTabPane).getTabPane();
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1));
when(tab1.getContent()).thenReturn(scrollPane);
when(scrollPane.getContent()).thenReturn(queryPhasePane);
// This just needs to be set up to prevent null pointers
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of());
// Add three data source title panes to the query source pane
final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane dataSourceTitledPane3 = mock(DataSourceTitledPane.class);
final List<DataSourceTitledPane> dataSourceTitledPanes = new ArrayList<>();
dataSourceTitledPanes.add(dataSourceTitledPane1);
dataSourceTitledPanes.add(dataSourceTitledPane2);
dataSourceTitledPanes.add(dataSourceTitledPane3);
when(queryPhasePane.getDataAccessPanes()).thenReturn(dataSourceTitledPanes);
// Stub out the data source title pane's plugin parameters
// Pane 1 has no parameters so it will be dropped
when(dataSourceTitledPane1.getParameters()).thenReturn(null);
final PluginParameters pane2PluginParameters = mock(PluginParameters.class);
final PluginParameters pane3PluginParameters = mock(PluginParameters.class);
when(dataSourceTitledPane2.getParameters()).thenReturn(pane2PluginParameters);
when(dataSourceTitledPane3.getParameters()).thenReturn(pane3PluginParameters);
// Stub out the individual parameters
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
final PluginParameter pluginParameter3 = mock(PluginParameter.class);
when(pane2PluginParameters.getParameters()).thenReturn(Map.of("plugin1", pluginParameter1, "plugin2", pluginParameter2));
when(pane3PluginParameters.getParameters()).thenReturn(Map.of("plugin3", pluginParameter3));
// Plugin 1 parameter will have no value and so will be ignored
when(pluginParameter1.getObjectValue()).thenReturn(null);
// Plugin 2 parameter will be a local date param type and handled differently
when(pluginParameter2.getType()).thenReturn(LocalDateParameterType.INSTANCE);
when(pluginParameter2.getObjectValue()).thenReturn("PluginParam2 Object Value");
when(pluginParameter2.getStringValue()).thenReturn("PluginParam2 String Value");
when(pluginParameter3.getType()).thenReturn(BooleanParameterType.INSTANCE);
when(pluginParameter3.getObjectValue()).thenReturn("PluginParam3 Object Value");
when(pluginParameter3.getStringValue()).thenReturn("PluginParam3 String Value");
try (final MockedStatic<RecentParameterValues> recentParamValsMockedStatic = Mockito.mockStatic(RecentParameterValues.class)) {
dataAccessTabPane.storeParameterValues();
// Verify that parameters for plugins 2 and 3 were set to the store correctly
recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin2", "PluginParam2 Object Value"));
recentParamValsMockedStatic.verify(() -> RecentParameterValues.storeRecentValue("plugin3", "PluginParam3 String Value"));
}
}
Aggregations