use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane 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"));
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane 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.views.dataaccess.panes.GlobalParametersPane in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method testsaveDataAccessState.
@Test
public void testsaveDataAccessState() throws Exception {
System.out.println("testsaveDataAccessState");
// mock Tab
final Tab tab = mock(Tab.class);
ObservableList<Tab> observableArrayList = FXCollections.observableArrayList(tab);
// mock TabPane
final TabPane tabPane = mock(TabPane.class);
when(tabPane.getTabs()).thenReturn(observableArrayList);
final ScrollPane scrollPane = mock(ScrollPane.class);
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters pluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter = mock(PluginParameter.class);
when(tab.getContent()).thenReturn(scrollPane);
when(scrollPane.getContent()).thenReturn(queryPhasePane);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(pluginParameters);
when(pluginParameter.getStringValue()).thenReturn("something");
final String someKey = "someKey";
final Map<String, PluginParameter<?>> map = Map.of(someKey, pluginParameter);
when(pluginParameters.getParameters()).thenReturn(map);
// mock graph
final Graph graph = mock(Graph.class);
final WritableGraph wGraph = mock(WritableGraph.class);
when(graph.getWritableGraph("Update Data Access State", true)).thenReturn(wGraph);
DataAccessUtilities.saveDataAccessState(tabPane, graph);
final DataAccessState expectedTab = new DataAccessState();
expectedTab.newTab();
expectedTab.add("someKey", "something");
assertEquals(expectedTab.getState().size(), 1);
verify(wGraph).setObjectValue(0, 0, expectedTab);
}
Aggregations