Search in sources :

Example 1 with DataAccessPreferenceUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities in project constellation by constellation-app.

the class DataAccessResultsDirChooserNGTest method init.

@Test
public void init() {
    final DataAccessResultsDirChooser chooser = spy(new DataAccessResultsDirChooser());
    assertNotNull(chooser.getFileChooser());
    final FileChooserBuilder fileChooser = mock(FileChooserBuilder.class);
    doReturn(fileChooser).when(chooser).getFileChooser();
    final File expectedSelectedDir = new File("/tmp");
    when(fileChooser.showSaveDialog()).thenReturn(expectedSelectedDir);
    try (final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
        final File selectedDir = chooser.openAndSaveToPreferences();
        assertEquals(selectedDir, expectedSelectedDir);
        prefUtilsMockedStatic.verify(() -> DataAccessPreferenceUtilities.setDataAccessResultsDir(expectedSelectedDir));
    }
}
Also used : DataAccessPreferenceUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities) FileChooserBuilder(org.openide.filesystems.FileChooserBuilder) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with DataAccessPreferenceUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities in project constellation by constellation-app.

the class OptionsMenuBarNGTest method init.

@Test
public void init() {
    try (final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
        prefUtilsMockedStatic.when(DataAccessPreferenceUtilities::getDataAccessResultsDir).thenReturn(new File("/"));
        prefUtilsMockedStatic.when(DataAccessPreferenceUtilities::isDeselectPluginsOnExecuteEnabled).thenReturn(true);
        optionsMenuBar.init();
    }
    // Load Templates Menu Item
    verifyMenuItem(optionsMenuBar.getLoadMenuItem(), "Load Templates", new Image(OptionsMenuBar.class.getResourceAsStream("resources/DataAccessLoadTemplate.png")));
    try (final MockedStatic<DataAccessParametersIoProvider> prefProviderMockedStatic = Mockito.mockStatic(DataAccessParametersIoProvider.class)) {
        final ActionEvent actionEvent = mock(ActionEvent.class);
        optionsMenuBar.getLoadMenuItem().getOnAction().handle(actionEvent);
        prefProviderMockedStatic.verify(() -> DataAccessParametersIoProvider.loadParameters(dataAccessPane));
        verify(actionEvent).consume();
    }
    // Save Templates Menu Item
    verifyMenuItem(optionsMenuBar.getSaveMenuItem(), "Save Templates", new Image(OptionsMenuBar.class.getResourceAsStream("resources/DataAccessSaveTemplate.png")));
    try (final MockedStatic<DataAccessParametersIoProvider> prefProviderMockedStatic = Mockito.mockStatic(DataAccessParametersIoProvider.class)) {
        final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
        final TabPane tabPane = mock(TabPane.class);
        final ActionEvent actionEvent = mock(ActionEvent.class);
        when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
        when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
        optionsMenuBar.getSaveMenuItem().getOnAction().handle(actionEvent);
        prefProviderMockedStatic.verify(() -> DataAccessParametersIoProvider.saveParameters(tabPane));
        verify(actionEvent).consume();
    }
    // Save Results Menu Item
    verifyMenuItem(optionsMenuBar.getSaveResultsItem(), "Save Results", new Image(OptionsMenuBar.class.getResourceAsStream("resources/DataAccessSaveResults.png")));
    assertTrue(optionsMenuBar.getSaveResultsItem().isSelected());
    // Can't extract added listeners. Testing of the listener itself
    // happens separately.
    // De-Select Plugins On Execution Menu Item
    verifyMenuItem(optionsMenuBar.getDeselectPluginsOnExecutionMenuItem(), "Deselect On Go", new Image(OptionsMenuBar.class.getResourceAsStream("resources/DataAccessUnchecked.png")));
    assertTrue(optionsMenuBar.getDeselectPluginsOnExecutionMenuItem().isSelected());
    try (final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
        final ActionEvent actionEvent = mock(ActionEvent.class);
        optionsMenuBar.getDeselectPluginsOnExecutionMenuItem().getOnAction().handle(actionEvent);
        prefUtilsMockedStatic.verify(() -> DataAccessPreferenceUtilities.setDeselectPluginsOnExecute(true));
        verify(actionEvent).consume();
    }
    // Options Menu
    verifyMenuItem(optionsMenuBar.getOptionsMenu(), "Workflow Options", new Image(OptionsMenuBar.class.getResourceAsStream("resources/DataAccessSettings.png")));
    assertEquals(optionsMenuBar.getOptionsMenu().getItems(), FXCollections.observableArrayList(optionsMenuBar.getLoadMenuItem(), optionsMenuBar.getSaveMenuItem(), optionsMenuBar.getSaveResultsItem(), optionsMenuBar.getDeselectPluginsOnExecutionMenuItem()));
    // Menu Bar
    assertEquals(optionsMenuBar.getMenuBar().getMenus(), FXCollections.observableArrayList(optionsMenuBar.getOptionsMenu()));
    assertEquals(optionsMenuBar.getMenuBar().getMinHeight(), 36.0);
    assertEquals(optionsMenuBar.getMenuBar().getPadding(), new Insets(4));
}
Also used : DataAccessPreferenceUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities) TabPane(javafx.scene.control.TabPane) Insets(javafx.geometry.Insets) DataAccessParametersIoProvider(au.gov.asd.tac.constellation.views.dataaccess.io.DataAccessParametersIoProvider) ActionEvent(javafx.event.ActionEvent) Image(javafx.scene.image.Image) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with DataAccessPreferenceUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities in project constellation by constellation-app.

the class OptionsMenuBarNGTest method saveResultsListener.

@Test
public void saveResultsListener() throws InterruptedException, ExecutionException {
    final CheckMenuItem menuItem = mock(CheckMenuItem.class);
    when(optionsMenuBar.getSaveResultsItem()).thenReturn(menuItem);
    OptionsMenuBar.SaveResultsListener listener = optionsMenuBar.new SaveResultsListener();
    try (final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
        listener.changed(null, null, false);
        // Wait for any work to complete
        listener.getLastChange().get();
        prefUtilsMockedStatic.verify(() -> DataAccessPreferenceUtilities.setDataAccessResultsDir(null));
    }
    // Value Changed is TRUE
    verifySaveResultsListenerValueChangedTrue(listener, menuItem, new File("/savedir/"), false);
    verifySaveResultsListenerValueChangedTrue(listener, menuItem, null, true);
}
Also used : CheckMenuItem(javafx.scene.control.CheckMenuItem) DataAccessPreferenceUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with DataAccessPreferenceUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities in project constellation by constellation-app.

the class ButtonToolbarNGTest method verifyManageFavouritesWithUserInput.

/**
 * Verifies that when manage favourites is called, depending on the user
 * action against the dialog, different outcomes will occur.
 *
 * @param pluginTitle the plugin title of the only selected pane that is
 * enabled
 * @param selectedOption the option that the user selection in the dialog
 * @param preferenceUtilsVerification the verification against
 * {@link DataAccessPreferenceUtilities}
 */
private void verifyManageFavouritesWithUserInput(final String pluginTitle, final Object selectedOption, final Verification preferenceUtilsVerification) {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
    final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
    final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
    final Plugin plugin = mock(Plugin.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
    when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
    when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
    when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
    when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
    when(plugin.getName()).thenReturn(pluginTitle);
    try (final MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class);
        final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
        notifyDisplayerMockedStatic.when(() -> NotifyDisplayer.displayAndWait(any(NotifyDescriptor.class))).thenAnswer(iom -> {
            final NotifyDescriptor descriptor = iom.getArgument(0);
            final String expectedMessage = "Add or remove plugins from your favourites category.\n\n" + "The following plugins were selected:\n" + pluginTitle + "\n" + "\nNote that you need to restart before changes take effect.";
            assertEquals(descriptor.getMessage(), expectedMessage);
            assertEquals(descriptor.getTitle(), "Manage Favourites");
            assertEquals(descriptor.getOptionType(), NotifyDescriptor.DEFAULT_OPTION);
            assertEquals(descriptor.getMessageType(), NotifyDescriptor.QUESTION_MESSAGE);
            assertEquals(descriptor.getOptions(), new Object[] { "Add", "Remove", NotifyDescriptor.CANCEL_OPTION });
            assertEquals(descriptor.getValue(), NotifyDescriptor.OK_OPTION);
            // Simulating the value returned when the function is called on the FX thread
            return CompletableFuture.completedFuture(CompletableFuture.completedFuture(selectedOption));
        });
        buttonToolbar.manageFavourites();
        if (preferenceUtilsVerification != null) {
            prefUtilsMockedStatic.verify(preferenceUtilsVerification);
        } else {
            prefUtilsMockedStatic.verifyNoInteractions();
        }
    }
}
Also used : DataSourceTitledPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane) NotifyDescriptor(org.openide.NotifyDescriptor) DataAccessPreferenceUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) NotifyDisplayer(au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Aggregations

DataAccessPreferenceUtilities (au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessPreferenceUtilities)4 File (java.io.File)3 Test (org.testng.annotations.Test)3 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)1 NotifyDisplayer (au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer)1 DataAccessParametersIoProvider (au.gov.asd.tac.constellation.views.dataaccess.io.DataAccessParametersIoProvider)1 DataSourceTitledPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataSourceTitledPane)1 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)1 ActionEvent (javafx.event.ActionEvent)1 Insets (javafx.geometry.Insets)1 CheckMenuItem (javafx.scene.control.CheckMenuItem)1 TabPane (javafx.scene.control.TabPane)1 Image (javafx.scene.image.Image)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 FileChooserBuilder (org.openide.filesystems.FileChooserBuilder)1