Search in sources :

Example 6 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class FindViewTopComponentNGTest method testDisableFindView.

/**
 * Test of disableFindView method, of class FindViewTopComponent.
 */
@Test
public void testDisableFindView() {
    System.out.println("disableFindView");
    setupGraph();
    final GraphManager gm = Mockito.mock(GraphManager.class);
    when(gm.getAllGraphs()).thenReturn(graphMap);
    // create a static mock for the graph manager
    try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
        mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
        /**
         * Call to disable the view when no graphs are present. Verify that
         * the pane is disabled.
         */
        spyTopComponent.disableFindView();
        assertEquals(spyPane.isDisabled(), false);
    // verify(spyTopComponent, times(1)).disableFindView();
    // /**
    // * SetUp the graph then repeat the same process. Verify that the
    // * pane is no longer disabled
    // */
    // spyPane.setDisable(true);
    // assertEquals(spyPane.isDisabled(), true);
    // verify(spyTopComponent, times(2)).disableFindView();
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Test(org.testng.annotations.Test)

Example 7 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class LayersViewTopComponentNGTest method testSetPaneStatus.

/**
 * Test of setPaneStatus method, of class LayersViewTopComponent.
 */
@Test
public void testSetPaneStatus() {
    System.out.println("setPaneStatus");
    layersViewTopComponent = new LayersViewTopComponent();
    final GraphManager graphManager = mock(GraphManager.class);
    when(graphManager.getActiveGraph()).thenReturn(null);
    final LayersViewTopComponent spiedTopComponent = spy(layersViewTopComponent);
    final LayersViewPane lvp = mock(LayersViewPane.class);
    doNothing().when(lvp).setEnabled(Mockito.anyBoolean());
    when(spiedTopComponent.createContent()).thenReturn(lvp);
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        spiedTopComponent.setPaneStatus();
        verify(spiedTopComponent).createContent();
        verify(lvp).setEnabled(Mockito.eq(false));
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Test(org.testng.annotations.Test)

Example 8 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class LayersViewTopComponentNGTest method testSetPaneStatusTrue.

/**
 * Test of setPaneStatus method, of class LayersViewTopComponent.
 */
@Test
public void testSetPaneStatusTrue() {
    System.out.println("setPaneStatusTrue");
    layersViewTopComponent = new LayersViewTopComponent();
    final GraphManager graphManager = mock(GraphManager.class);
    final Graph graph = mock(Graph.class);
    when(graphManager.getActiveGraph()).thenReturn(graph);
    final LayersViewTopComponent spiedTopComponent = spy(layersViewTopComponent);
    final LayersViewPane lvp = mock(LayersViewPane.class);
    doNothing().when(lvp).setEnabled(Mockito.anyBoolean());
    when(spiedTopComponent.createContent()).thenReturn(lvp);
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        spiedTopComponent.setPaneStatus();
        verify(spiedTopComponent).createContent();
        verify(lvp).setEnabled(Mockito.eq(true));
    }
}
Also used : GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Graph(au.gov.asd.tac.constellation.graph.Graph) Test(org.testng.annotations.Test)

Example 9 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class PreferenceMenuNGTest method verifyLoadPreferencesAction.

/**
 * Verifies that when the load preferences button is clicked, the load
 * preferences method is called and the tables pagination is updated with
 * any necessary changes. If the current active graph is null, then no
 * preferences will be loaded.
 *
 * @param loadPreferencesMenu the load userTablePreferences menu
 * @param isActiveGraphNull true if the active graph is null, false
 * otherwise
 * @throws InterruptedException if there is a an issue waiting for the
 * JavaFX thread work to complete
 */
private void verifyLoadPreferencesAction(final MenuItem loadPreferencesMenu, final boolean isActiveGraphNull) throws InterruptedException {
    clearInvocations(preferencesMenu, activeTableReference, tablePane);
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class)) {
        final GraphManager graphManager = mock(GraphManager.class);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        final ActionEvent actionEvent = mock(ActionEvent.class);
        if (isActiveGraphNull) {
            when(graphManager.getActiveGraph()).thenReturn(null);
            loadPreferencesMenu.getOnAction().handle(actionEvent);
            verify(preferencesMenu, times(0)).loadPreferences();
        } else {
            final UserTablePreferences userTablePreferences = new UserTablePreferences();
            userTablePreferences.setMaxRowsPerPage(42);
            final Graph graph = mock(Graph.class);
            final Pagination pagination = mock(Pagination.class);
            when(graphManager.getActiveGraph()).thenReturn(graph);
            when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
            when(activeTableReference.getPagination()).thenReturn(pagination);
            doNothing().when(preferencesMenu).loadPreferences();
            loadPreferencesMenu.getOnAction().handle(actionEvent);
            final CountDownLatch latch = new CountDownLatch(1);
            Platform.runLater(() -> latch.countDown());
            latch.await();
            verify(activeTableReference).updatePagination(42, tablePane);
            verify(preferencesMenu).loadPreferences();
        }
        verify(actionEvent).consume();
    }
}
Also used : Pagination(javafx.scene.control.Pagination) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ActionEvent(javafx.event.ActionEvent) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with GraphManager

use of au.gov.asd.tac.constellation.graph.manager.GraphManager in project constellation by constellation-app.

the class DataAccessTabPaneNGTest method runTabs.

@Test
public void runTabs() {
    final String graphId = "graphId";
    try (final MockedStatic<GraphManager> graphManagerMockedStatic = Mockito.mockStatic(GraphManager.class);
        final MockedStatic<DataAccessTabPane> datPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class);
        final MockedStatic<CompletableFuture> futureMockedStatic = Mockito.mockStatic(CompletableFuture.class, Mockito.CALLS_REAL_METHODS)) {
        // Set up the active graph
        final GraphManager graphManager = mock(GraphManager.class);
        final Graph graph = mock(Graph.class);
        graphManagerMockedStatic.when(GraphManager::getDefault).thenReturn(graphManager);
        when(graphManager.getActiveGraph()).thenReturn(graph);
        when(graph.getId()).thenReturn(graphId);
        // No need to actually call, storeParameterValues. We will just verify
        // that it is called.
        doNothing().when(dataAccessTabPane).storeParameterValues();
        // Set up our fake tab pane
        final TabPane tabPane = mock(TabPane.class);
        final Tab tab1 = mock(Tab.class);
        final Tab tab2 = mock(Tab.class);
        final Tab tab3 = mock(Tab.class);
        final Tab tab4 = mock(Tab.class);
        final Tab tab5 = mock(Tab.class);
        doReturn(tabPane).when(dataAccessTabPane).getTabPane();
        when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(tab1, tab2, tab3, tab4, tab5));
        // No need for a different query pane per tab, so just return the same
        // one for all of them
        final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
        datPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(any(Tab.class))).thenReturn(queryPhasePane);
        final List<Future<?>> barrier1 = List.of(CompletableFuture.completedFuture("Future 1 Complete"));
        final List<Future<?>> barrier2 = List.of(CompletableFuture.completedFuture("Future 2 Complete"));
        final List<Future<?>> barrier3 = List.of(CompletableFuture.completedFuture("Future 3 Complete"));
        when(queryPhasePane.runPlugins(null)).thenReturn(barrier1);
        when(queryPhasePane.runPlugins(barrier1)).thenReturn(barrier2);
        when(queryPhasePane.runPlugins(barrier2)).thenReturn(barrier3);
        futureMockedStatic.when(() -> CompletableFuture.runAsync(any(Runnable.class), any(ExecutorService.class))).thenAnswer(iom -> {
            WaitForQueriesToCompleteTask task = iom.getArgument(0);
            assertEquals(task.getDataAccessPane(), dataAccessPane);
            assertEquals(task.getGraphId(), graphId);
            return null;
        });
        dataAccessTabPane.runTabs(1, 3);
        verify(dataAccessTabPane).storeParameterValues();
        verify(dataAccessPane).setExecuteButtonToStop(false);
        verify(dataAccessTabPane).storeParameterValues();
        datPaneMockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(tab1), never());
        datPaneMockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(tab2));
        datPaneMockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(tab3));
        datPaneMockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(tab4));
        datPaneMockedStatic.verify(() -> DataAccessTabPane.getQueryPhasePane(tab5), never());
        // Verify that run plugins was called only 3 times
        verify(queryPhasePane, times(1)).runPlugins(isNull());
        verify(queryPhasePane, times(2)).runPlugins(any(List.class));
        // Verify that the futures of the last run is passed into the next
        verify(queryPhasePane).runPlugins(null);
        verify(queryPhasePane).runPlugins(barrier1);
        verify(queryPhasePane).runPlugins(barrier2);
        // Verify the query is running state has been set to true
        assertTrue(DataAccessPaneState.isQueriesRunning(graphId));
    }
}
Also used : TabPane(javafx.scene.control.TabPane) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) WaitForQueriesToCompleteTask(au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) CompletableFuture(java.util.concurrent.CompletableFuture) Graph(au.gov.asd.tac.constellation.graph.Graph) Tab(javafx.scene.control.Tab) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Aggregations

GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)20 Test (org.testng.annotations.Test)15 Graph (au.gov.asd.tac.constellation.graph.Graph)11 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)4 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)4 ArrayList (java.util.ArrayList)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)3 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 SimplePlugin (au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)2 WaitForQueriesToCompleteTask (au.gov.asd.tac.constellation.views.dataaccess.tasks.WaitForQueriesToCompleteTask)2 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)2 FindViewTopComponent (au.gov.asd.tac.constellation.views.find2.FindViewTopComponent)2 UserTablePreferences (au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2