Search in sources :

Example 61 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method validateTabEnabledPlugins.

/**
 * Validates that if one enabled plugin on a tab has an error in one of its
 * parameters then the whole tab is deemed invalid. The method takes two
 * errors that are added to plugin parameters. The errors can be null,
 * indicating that there is no error present.
 *
 * @param error1 the error for plugin parameter 1, or null if no error
 * @param error2 the error for plugin parameter 2, or null if no error
 * @param expected true if the tab was determined to be valid, false otherwise
 */
private void validateTabEnabledPlugins(final String error1, final String error2, final boolean expected) {
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane3 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane4 = mock(DataSourceTitledPane.class);
    final PluginParameters pane3PluginParameters = mock(PluginParameters.class);
    final PluginParameters pane4PluginParameters = mock(PluginParameters.class);
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    final Tab tab = mock(Tab.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    try (final MockedStatic<DataAccessTabPane> datPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class, Mockito.CALLS_REAL_METHODS)) {
        datPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(same(tab))).thenReturn(queryPhasePane);
        // Set up out fake query pane that exists within a tab
        when(queryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2, dataSourceTitledPane3, dataSourceTitledPane4));
        // Pane 1 is disabled so it will be ignored during the check
        when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
        when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
        when(dataSourceTitledPane3.isQueryEnabled()).thenReturn(true);
        when(dataSourceTitledPane4.isQueryEnabled()).thenReturn(true);
        // Pane 2 has no parameters so it will be ignored during the check
        when(dataSourceTitledPane2.getParameters()).thenReturn(null);
        when(dataSourceTitledPane3.getParameters()).thenReturn(pane3PluginParameters);
        when(dataSourceTitledPane4.getParameters()).thenReturn(pane4PluginParameters);
        when(pane3PluginParameters.getParameters()).thenReturn(Map.of("plugin1", pluginParameter1));
        when(pane4PluginParameters.getParameters()).thenReturn(Map.of("plugin2", pluginParameter2));
        // Set the passed error values to the plugin parameters
        when(pluginParameter1.getError()).thenReturn(error1);
        when(pluginParameter2.getError()).thenReturn(error2);
        assertEquals(DataAccessTabPane.validateTabEnabledPlugins(tab), expected);
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Example 62 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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"));
    }
}
Also used : TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ScrollPane(javafx.scene.control.ScrollPane) RecentParameterValues(au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 63 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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"));
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ScrollPane(javafx.scene.control.ScrollPane) RecentParameterValues(au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues) ArrayList(java.util.ArrayList) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 64 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class GlobalParametersNGTest method getParameters.

@Test
public void getParameters() {
    final PluginParameters previous = mock(PluginParameters.class);
    final Lookup lookup = mock(Lookup.class);
    final PluginParameter param1 = mock(PluginParameter.class);
    final PluginParameter param2 = mock(PluginParameter.class);
    when(param1.getId()).thenReturn("param1");
    when(param2.getId()).thenReturn("param2");
    when(param1.getType()).thenReturn(ActionParameterType.INSTANCE);
    when(param2.getType()).thenReturn(ActionParameterType.INSTANCE);
    final GlobalParameters.PositionalPluginParameter positionalParam1 = new GlobalParameters.PositionalPluginParameter(param1, 10);
    final GlobalParameters.PositionalPluginParameter positionalParam2 = new GlobalParameters.PositionalPluginParameter(param2, 5);
    final GlobalParameters globalParameters1 = mock(GlobalParameters.class);
    final GlobalParameters globalParameters2 = mock(GlobalParameters.class);
    when(globalParameters1.getParameterList(previous)).thenReturn(List.of(positionalParam1));
    when(globalParameters2.getParameterList(previous)).thenReturn(List.of(positionalParam2));
    lookupStaticMock.when(Lookup::getDefault).thenReturn(lookup);
    doReturn(List.of(globalParameters1, globalParameters2)).when(lookup).lookupAll(GlobalParameters.class);
    final PluginParameters actual = GlobalParameters.getParameters(previous);
    assertEquals(actual.getParameters().size(), 2);
    assertSame(actual.getParameters().get("param1"), param1);
    assertSame(actual.getParameters().get("param2"), param2);
    // Calling it a second time to ensure that the post process is not called more than once.
    final PluginParameters actualSecondCall = GlobalParameters.getParameters(previous);
    assertEquals(actualSecondCall.getParameters().size(), 2);
    assertSame(actualSecondCall.getParameters().get("param1"), param1);
    assertSame(actualSecondCall.getParameters().get("param2"), param2);
    final ArgumentCaptor<PluginParameters> captor1 = ArgumentCaptor.forClass(PluginParameters.class);
    verify(globalParameters1, times(1)).postProcess(captor1.capture());
    final ArgumentCaptor<PluginParameters> captor2 = ArgumentCaptor.forClass(PluginParameters.class);
    verify(globalParameters2, times(1)).postProcess(captor2.capture());
    // It iterates over GlobalParameters list and calls post process on each passing the newly
    // generated global parameters list. i.e. the returned value from the method. This verifies
    // that it passes the same object in each call and a cursory check thats its the same plugin
    // parameters object that was returned.
    assertSame(captor1.getValue(), captor2.getValue());
    assertEquals(captor1.getValue().getParameters().keySet(), Set.of("param1", "param2"));
}
Also used : GlobalParameters(au.gov.asd.tac.constellation.views.dataaccess.GlobalParameters) Lookup(org.openide.util.Lookup) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 65 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter 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);
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) HashMap(java.util.HashMap) PluginParameterType(au.gov.asd.tac.constellation.plugins.parameters.PluginParameterType) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) Map(java.util.Map) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Aggregations

PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)93 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)53 Test (org.testng.annotations.Test)52 ArrayList (java.util.ArrayList)36 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)25 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)21 Map (java.util.Map)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)11 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)11 Graph (au.gov.asd.tac.constellation.graph.Graph)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)10 HashMap (java.util.HashMap)10 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)9 List (java.util.List)9 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)8 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)8