Search in sources :

Example 11 with DataAccessTabPane

use of au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane in project constellation by constellation-app.

the class DataAccessPaneNGTest method searchTextFieldListener.

/**
 * I suspect this doesn't work because the action handler is initialized during
 * the constructor and the spy is not applied until after the construction is
 * complete.
 */
@Test(enabled = false)
public void searchTextFieldListener() {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(queryPhasePane);
    dataAccessPane.getSearchPluginTextField().setText("example");
    verify(queryPhasePane).showMatchingPlugins("example");
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) Test(org.testng.annotations.Test)

Example 12 with DataAccessTabPane

use of au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane in project constellation by constellation-app.

the class DataAccessPaneNGTest method verifyUpdateWithGraphId.

/**
 * Verifies the graph ID is set and the correct execute button setting is made.
 *
 * @param graphId the graph ID
 * @param tabPaneValid
 * @param queriesRunning true if the queries are running, false otherwise
 * @param verification a function with verifications to make after the code is run
 */
private void verifyUpdateWithGraphId(final String graphId, final boolean disableExecuteButton, final boolean queriesRunning, final Consumer<Boolean> verification) {
    final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
    when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
    when(dataAccessPane.determineExecuteButtonDisableState(anyBoolean())).thenReturn(disableExecuteButton);
    when(dataAccessTabPane.isTabPaneExecutable()).thenReturn(true);
    DataAccessPaneState.setQueriesRunning(graphId, queriesRunning);
    dataAccessPane.update(graphId);
    verification.accept(disableExecuteButton);
    verify(dataAccessTabPane).updateTabMenus();
}
Also used : DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)

Example 13 with DataAccessTabPane

use of au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane 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 14 with DataAccessTabPane

use of au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane 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)

Example 15 with DataAccessTabPane

use of au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane in project constellation by constellation-app.

the class DataAccessSearchProviderNGTest method testEvaluateFail.

/**
 * Test of evaluate method, of class DataAccessSearchProvider. Pass in an
 * unmatchable search string
 */
@Test
public void testEvaluateFail() {
    System.out.println("evaluate fail");
    // 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 the request text to be an unmatchable string
    when(request.getText()).thenReturn("nothignshouldmatchthisstring");
    when(response.addResult(Mockito.any(), Mockito.anyString())).thenReturn(true);
    DataAccessSearchProvider instance = new DataAccessSearchProvider();
    instance.evaluate(request, response);
    // Verify that addResult was never called.
    // This should mean that no plugin name matched the input
    verify(response, never()).addResult(Mockito.any(), Mockito.anyString());
}
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)

Aggregations

DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)19 Test (org.testng.annotations.Test)17 Tab (javafx.scene.control.Tab)12 Graph (au.gov.asd.tac.constellation.graph.Graph)8 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)7 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)5 DataAccessUtilities (au.gov.asd.tac.constellation.views.dataaccess.utilities.DataAccessUtilities)4 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)3 SearchRequest (org.netbeans.spi.quicksearch.SearchRequest)3 SearchResponse (org.netbeans.spi.quicksearch.SearchResponse)3 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)2 DataAccessState (au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)2 TabPane (javafx.scene.control.TabPane)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)1