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();
}
}
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));
}
}
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));
}
}
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();
}
}
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));
}
}
Aggregations