Search in sources :

Example 1 with GlobalParametersPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane in project constellation by constellation-app.

the class ButtonToolbarNGTest method verifyAddTabAction.

/**
 * Verifies that the add button creates a new tab using the global plugin
 * configuration from the last tab if available.
 *
 * @param addButton the button to verify
 */
private void verifyAddTabAction(final Button addButton) {
    final ActionEvent actionEvent = mock(ActionEvent.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    // Set up the current tab pane. The code will take the last tab, i.e. tab2
    final Tab tab1 = mock(Tab.class);
    final Tab tab2 = mock(Tab.class);
    final ObservableList<Tab> tabs = FXCollections.observableArrayList(tab1, tab2);
    doReturn(tabs).when(buttonToolbar).getTabs();
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters pluginParameters = mock(PluginParameters.class);
    when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
    when(globalParametersPane.getParams()).thenReturn(pluginParameters);
    try (final MockedStatic<DataAccessTabPane> tabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        // There will be no interaction with tab1 so only mock out tab2
        tabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(tab2)).thenReturn(queryPhasePane);
        // Run the action
        addButton.getOnAction().handle(actionEvent);
        // Verify a new tab is created with the existing last tab's parameters
        verify(dataAccessTabPane).newTab(pluginParameters, "");
        verify(actionEvent).consume();
    }
}
Also used : Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ActionEvent(javafx.event.ActionEvent) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)

Example 2 with GlobalParametersPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane in project constellation by constellation-app.

the class DataAccessUtilitiesNGTest method loadDataAccessState.

@Test
public void loadDataAccessState() {
    // Create current data access view state and set some parameters
    // The code currenly only looks at the first tab so parameter2
    // value will be ignored
    final DataAccessState currentState = new DataAccessState();
    currentState.newTab();
    currentState.add("parameter1", "parameter1_new_value");
    currentState.newTab();
    currentState.add("parameter2", "parameter2_new_value");
    // mock graph
    final Graph graph = mock(Graph.class);
    final ReadableGraph rGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(rGraph);
    // mock data access state attribute in graph
    when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
    when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
    // mock tab pane
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final TabPane tabPane = mock(TabPane.class);
    final Tab currentTab = mock(Tab.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
    when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
    when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
    try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
        final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
        final PluginParameters globalPluginParameters = mock(PluginParameters.class);
        final PluginParameter pluginParameter1 = mock(PluginParameter.class);
        final PluginParameter pluginParameter2 = mock(PluginParameter.class);
        when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
        when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
        when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
        DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
        verify(pluginParameter1).setStringValue("parameter1_new_value");
        verify(pluginParameter2, never()).setStringValue(anyString());
        verify(rGraph).release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) 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 3 with GlobalParametersPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane in project constellation by constellation-app.

the class DataAccessParametersIoProviderNGTest method loadParameters.

@Test
public void loadParameters() throws IOException {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    final QueryPhasePane tab1 = mock(QueryPhasePane.class);
    final QueryPhasePane tab2 = mock(QueryPhasePane.class);
    when(dataAccessTabPane.newTab(anyString())).thenReturn(tab1).thenReturn(tab2);
    final GlobalParametersPane globalParametersPane1 = mock(GlobalParametersPane.class);
    final GlobalParametersPane globalParametersPane2 = mock(GlobalParametersPane.class);
    when(tab1.getGlobalParametersPane()).thenReturn(globalParametersPane1);
    when(tab2.getGlobalParametersPane()).thenReturn(globalParametersPane2);
    // By adding the settings bit here, it forces mockito to generate two different
    // classes. Otherwise they would be two different objects but have the same class name
    final Plugin plugin1 = mock(Plugin.class, withSettings().extraInterfaces(Comparable.class));
    final Plugin plugin2 = mock(Plugin.class, withSettings().extraInterfaces(Serializable.class));
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane1.getPlugin()).thenReturn(plugin1);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin2);
    when(tab1.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    when(tab2.getDataAccessPanes()).thenReturn(List.of());
    final PluginParameter pluginParameter1 = mock(PluginParameter.class);
    when(pluginParameter1.getId()).thenReturn("param1");
    final PluginParameter pluginParameter2 = mock(PluginParameter.class);
    when(pluginParameter2.getId()).thenReturn("param2");
    final PluginParameter pluginParameter3 = mock(PluginParameter.class);
    when(pluginParameter3.getId()).thenReturn("param3");
    final PluginParameter pluginParameter4 = mock(PluginParameter.class);
    when(pluginParameter4.getId()).thenReturn("param4");
    final PluginParameters globalPluginParameters1 = new PluginParameters();
    globalPluginParameters1.addParameter(pluginParameter1);
    globalPluginParameters1.addParameter(pluginParameter2);
    globalPluginParameters1.addParameter(pluginParameter3);
    final PluginParameters globalPluginParameters2 = new PluginParameters();
    globalPluginParameters2.addParameter(pluginParameter3);
    globalPluginParameters2.addParameter(pluginParameter4);
    when(globalParametersPane1.getParams()).thenReturn(globalPluginParameters1);
    when(globalParametersPane2.getParams()).thenReturn(globalPluginParameters2);
    try (final MockedStatic<JsonIO> jsonIOStaticMock = Mockito.mockStatic(JsonIO.class)) {
        final ObjectMapper objectMapper = new ObjectMapper();
        final String json = IOUtils.toString(new FileInputStream(getClass().getResource("resources/preferences.json").getPath()), StandardCharsets.UTF_8);
        // We do not know the mockito plugin names ahead of time so substitute them in now
        final StringSubstitutor substitutor = new StringSubstitutor(Map.of("INSERT_PLUGIN1_NAME", plugin1.getClass().getSimpleName(), "INSERT_PLUGIN2_NAME", plugin2.getClass().getSimpleName()));
        final List<DataAccessUserPreferences> preferences = objectMapper.readValue(substitutor.replace(json), new TypeReference<List<DataAccessUserPreferences>>() {
        });
        jsonIOStaticMock.when(() -> JsonIO.loadJsonPreferences(eq(Optional.of("DataAccessView")), any(TypeReference.class))).thenReturn(preferences);
        DataAccessParametersIoProvider.loadParameters(dataAccessPane);
    }
    verify(dataAccessTabPane, times(2)).newTab(anyString());
    // tab1 global parameters
    verify(pluginParameter1).setStringValue("tab1_param1_value");
    verify(pluginParameter3).setStringValue(null);
    // tab1 plugin parameters - only plugin1 because plugin2 is disabled
    verify(dataSourceTitledPane1).setParameterValues(Map.of(plugin1.getClass().getSimpleName() + "." + "__is_enabled__", "true", plugin1.getClass().getSimpleName() + "." + "param1", "plugin1_param1_value"));
    // tab2 global parameters
    verify(pluginParameter4).setStringValue("tab2_param4_value");
    // tab2 plugin parameters
    verify(dataSourceTitledPane2, times(0)).setParameterValues(anyMap());
}
Also used : JsonIO(au.gov.asd.tac.constellation.utilities.genericjsonio.JsonIO) Serializable(java.io.Serializable) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) DataAccessUserPreferences(au.gov.asd.tac.constellation.views.dataaccess.api.DataAccessUserPreferences) DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) StringSubstitutor(org.apache.commons.text.StringSubstitutor) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 4 with GlobalParametersPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane 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 5 with GlobalParametersPane

use of au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method validateTabTimeRange.

@Test
public void validateTabTimeRange() {
    final Tab tab = mock(Tab.class);
    final ScrollPane scrollPane = mock(ScrollPane.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
    final PluginParameters globalPluginParameters = mock(PluginParameters.class);
    when(tab.getContent()).thenReturn(scrollPane);
    when(scrollPane.getContent()).thenReturn(queryPhasePane);
    when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
    when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
    final ZonedDateTime before = ZonedDateTime.of(2020, 1, 1, 1, 0, 0, 0, ZoneOffset.UTC);
    final ZonedDateTime after = ZonedDateTime.of(2021, 1, 1, 1, 0, 0, 0, ZoneOffset.UTC);
    // A tab's date range is valid if the to part of the range is after the from part.
    when(globalPluginParameters.getDateTimeRangeValue("CoreGlobalParameters.datetime_range")).thenReturn(new DateTimeRange(before, after));
    assertTrue(DataAccessTabPane.validateTabTimeRange(tab));
    when(globalPluginParameters.getDateTimeRangeValue("CoreGlobalParameters.datetime_range")).thenReturn(new DateTimeRange(after, before));
    assertFalse(DataAccessTabPane.validateTabTimeRange(tab));
}
Also used : Tab(javafx.scene.control.Tab) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) ZonedDateTime(java.time.ZonedDateTime) ScrollPane(javafx.scene.control.ScrollPane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DateTimeRange(au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange) Test(org.testng.annotations.Test)

Aggregations

PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)8 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)8 Test (org.testng.annotations.Test)7 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Tab (javafx.scene.control.Tab)6 ScrollPane (javafx.scene.control.ScrollPane)4 TabPane (javafx.scene.control.TabPane)4 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)3 DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)2 RecentParameterValues (au.gov.asd.tac.constellation.plugins.parameters.RecentParameterValues)2 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)2 DataAccessState (au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 PluginParameterType (au.gov.asd.tac.constellation.plugins.parameters.PluginParameterType)1 DateTimeRange (au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange)1