Search in sources :

Example 1 with ShowDataAccessPluginTask

use of au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testRun3.

/**
 * Test of run method, of class PluginDisplayer. Testing when daPane is null
 */
@Test
public void testRun3() {
    System.out.println("testRun3 null data access pane");
    // Setting up mocks
    notifDisplayer = mock(NotificationDisplayer.class);
    final Notification notif = new Notification() {

        @Override
        public void clear() {
        // do nothing, used for testing.
        }
    };
    // Setting up a mock for DataAccessUtilities to return null when fetching the pane.
    try (MockedStatic<DataAccessUtilities> mockedStatic1 = Mockito.mockStatic(DataAccessUtilities.class)) {
        mockedStatic1.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(null);
        // Mock the static method getDefault() to return the mock of NotificationDisplayer
        try (MockedStatic<NotificationDisplayer> mockedStatic3 = Mockito.mockStatic(NotificationDisplayer.class)) {
            when(notifDisplayer.notify("Data Access view", WARNING_ICON, "Please open the Data Access view and create a step.", null)).thenReturn(notif);
            mockedStatic3.when(() -> NotificationDisplayer.getDefault()).thenReturn(notifDisplayer);
            ShowDataAccessPluginTask pd = new ShowDataAccessPluginTask("SelectTopN");
            pd.run();
            // verify notificationdisplayer was called with correct string
            verify(notifDisplayer, times(1)).notify(Mockito.anyString(), Mockito.eq(WARNING_ICON), Mockito.eq("Please open the Data Access view and create a step."), Mockito.eq(null));
        }
    }
}
Also used : ShowDataAccessPluginTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) NotificationDisplayer(org.openide.awt.NotificationDisplayer) Notification(org.openide.awt.Notification) Test(org.testng.annotations.Test)

Example 2 with ShowDataAccessPluginTask

use of au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testRun2.

/**
 * Test of run method, of class PluginDisplayer. Testing when tab is null
 */
@Test
public void testRun2() {
    System.out.println("testRun2 testing null tab returned");
    // Setting up mocks
    daPane = mock(DataAccessPane.class);
    datPane = mock(DataAccessTabPane.class);
    notifDisplayer = mock(NotificationDisplayer.class);
    final Notification notif = new Notification() {

        @Override
        public void clear() {
        // do nothing, used for testing.
        }
    };
    // Setting up a mock for DataAccessUtilities to return null when fetching the pane.
    try (MockedStatic<DataAccessUtilities> mockedStatic1 = Mockito.mockStatic(DataAccessUtilities.class)) {
        when(daPane.getDataAccessTabPane()).thenReturn(datPane);
        when(datPane.getCurrentTab()).thenReturn(null);
        mockedStatic1.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(daPane);
        // Mock the static method getDefault() to return the mock of NotificationDisplayer
        try (MockedStatic<NotificationDisplayer> mockedStatic3 = Mockito.mockStatic(NotificationDisplayer.class)) {
            when(notifDisplayer.notify("Data Access view", WARNING_ICON, "Please create a step in the Data Access view.", null)).thenReturn(notif);
            mockedStatic3.when(() -> NotificationDisplayer.getDefault()).thenReturn(notifDisplayer);
            ShowDataAccessPluginTask pd = new ShowDataAccessPluginTask("SelectTopN");
            pd.run();
            // Verify that the current tab was attempted to be retrieved
            verify(datPane, times(1)).getCurrentTab();
            // verify notificationdisplayer was called with correct string
            verify(notifDisplayer, times(1)).notify(Mockito.anyString(), Mockito.eq(WARNING_ICON), Mockito.eq("Please create a step in the Data Access view."), Mockito.eq(null));
        }
    }
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) ShowDataAccessPluginTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) NotificationDisplayer(org.openide.awt.NotificationDisplayer) Notification(org.openide.awt.Notification) Test(org.testng.annotations.Test)

Example 3 with ShowDataAccessPluginTask

use of au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testRun1.

// //////////////////////////////////////////////////////////////////////////
// /////////////////  Start of PluginDisplayer Tests  ///////////////////////
// //////////////////////////////////////////////////////////////////////////
/**
 * Test of run method, of class PluginDisplayer.
 */
@Test
public void testRun1() {
    System.out.println("testRun1 testing query phase pane was successfully returned");
    // Setting up mocks
    daPane = mock(DataAccessPane.class);
    datPane = mock(DataAccessTabPane.class);
    qpPane = mock(QueryPhasePane.class);
    // Do nothing when the plugin is called to expand
    // May never get here with the code existing in the Platform thread.
    doNothing().when(qpPane).expandPlugin(Mockito.eq("SelectTopN"));
    // Mock the static method getQueryPhasePane to return the mocked QueryPhasePane
    try (MockedStatic<DataAccessTabPane> mockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        mockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(Mockito.any(Tab.class))).thenReturn(qpPane);
        // Return a new tab when the DataAccessPane mock is prompted for getCurrentTab
        when(daPane.getDataAccessTabPane()).thenReturn(datPane);
        when(datPane.getCurrentTab()).thenReturn(new Tab());
        // Mock the static method getDataAccessPane and return the mocked DataAccessPane
        try (MockedStatic<DataAccessUtilities> mockedStatic2 = Mockito.mockStatic(DataAccessUtilities.class)) {
            mockedStatic2.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(daPane);
            try {
                ShowDataAccessPluginTask pd = new ShowDataAccessPluginTask("SelectTopN");
                pd.run();
            } catch (final IllegalStateException ex) {
            // Catch the exception which happens when executing Platform thread in standalone tests
            // Fail for any other exception
            }
            // Verify that getCurrentTab was succcessfully called.
            verify(datPane, times(1)).getCurrentTab();
            // Verify that getQueryPhasePane was succcessfully called.
            mockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(Mockito.any()));
        }
    }
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Tab(javafx.scene.control.Tab) ShowDataAccessPluginTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) Test(org.testng.annotations.Test)

Aggregations

ShowDataAccessPluginTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask)3 DataAccessUtilities (au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities)3 Test (org.testng.annotations.Test)3 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)2 Notification (org.openide.awt.Notification)2 NotificationDisplayer (org.openide.awt.NotificationDisplayer)2 Tab (javafx.scene.control.Tab)1