Search in sources :

Example 1 with DataAccessUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities 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 DataAccessUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities 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 DataAccessUtilities

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

the class DataAccessViewTopComponentNGTest method handleNewGraph.

@Test(enabled = false)
public void handleNewGraph() {
    final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
    final DataAccessViewTopComponent spiedTopComponent = spy(dataAccessViewTopComponent);
    doReturn(dataAccessPane).when(spiedTopComponent).getDataAccessPane();
    final Graph graph = mock(Graph.class);
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class);
        final MockedStatic<DataAccessUtilities> utilitiesMockedStatic = Mockito.mockStatic(DataAccessUtilities.class)) {
        platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).thenAnswer((iom) -> {
            final Runnable runnable = iom.getArgument(0);
            runnable.run();
            return null;
        });
        spiedTopComponent.componentOpened();
        spiedTopComponent.handleNewGraph(graph);
        verify(dataAccessPane).update(graph);
        utilitiesMockedStatic.verify(() -> DataAccessUtilities.loadDataAccessState(dataAccessPane, graph));
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Platform(javafx.application.Platform) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) Test(org.testng.annotations.Test)

Example 4 with DataAccessUtilities

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

the class DataAccessSearchProviderNGTest method testEvaluateSuccess.

/**
 * Test of evaluate method, of class DataAccessSearchProvider.
 */
@Test
public void testEvaluateSuccess() {
    System.out.println("evaluate success");
    // Creating mocks
    daPane = mock(DataAccessPane.class);
    datPane = mock(DataAccessTabPane.class);
    qpPane = mock(QueryPhasePane.class);
    request = mock(SearchRequest.class);
    response = mock(SearchResponse.class);
    // Create mock of DataAccessPane to return the query phase pane mock
    try (MockedStatic<DataAccessTabPane> mockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
        mockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(Mockito.any(Tab.class))).thenReturn(qpPane);
    }
    // Mock of DataAccessPane will return a blank new tab when called
    try (MockedStatic<DataAccessUtilities> mockedStatic2 = Mockito.mockStatic(DataAccessUtilities.class)) {
        when(daPane.getDataAccessTabPane()).thenReturn(datPane);
        when(datPane.getCurrentTab()).thenReturn(new Tab());
        mockedStatic2.when(() -> DataAccessUtilities.getDataAccessPane()).thenReturn(daPane);
    }
    // Mock request to return the selected text
    when(request.getText()).thenReturn("Select");
    // Return a valid response when results are added that match the expected
    when(response.addResult(Mockito.any(), Mockito.eq("Select Top N"))).thenReturn(true);
    when(response.addResult(Mockito.any(), Mockito.eq("Select All"))).thenReturn(true);
    DataAccessSearchProvider instance = new DataAccessSearchProvider();
    instance.evaluate(request, response);
    // Verify that addResult was called on the correct plugins
    verify(response, times(1)).addResult(Mockito.any(), Mockito.eq("Select Top N"));
    verify(response, times(1)).addResult(Mockito.any(), Mockito.eq("Select All"));
}
Also used : SearchRequest(org.netbeans.spi.quicksearch.SearchRequest) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Tab(javafx.scene.control.Tab) DataAccessUtilities(au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities) SearchResponse(org.netbeans.spi.quicksearch.SearchResponse) Test(org.testng.annotations.Test)

Example 5 with DataAccessUtilities

use of au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities 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

DataAccessUtilities (au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities)7 Test (org.testng.annotations.Test)7 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)5 Tab (javafx.scene.control.Tab)4 ShowDataAccessPluginTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.ShowDataAccessPluginTask)3 SearchRequest (org.netbeans.spi.quicksearch.SearchRequest)3 SearchResponse (org.netbeans.spi.quicksearch.SearchResponse)3 Notification (org.openide.awt.Notification)2 NotificationDisplayer (org.openide.awt.NotificationDisplayer)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)1 Platform (javafx.application.Platform)1