Search in sources :

Example 1 with TablePane

use of au.gov.asd.tac.constellation.views.tableview.panes.TablePane in project constellation by constellation-app.

the class TableViewTopComponentNGTest method handleGraphClosed.

@Test
public void handleGraphClosed() throws InterruptedException {
    final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
    final TablePane tablePane = mock(TablePane.class);
    final ActiveTableReference activeTableReference = mock(ActiveTableReference.class);
    final Pagination pagination = mock(Pagination.class);
    final UserTablePreferences userTablePreferences = new UserTablePreferences();
    userTablePreferences.setMaxRowsPerPage(42);
    when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
    when(tablePane.getActiveTableReference()).thenReturn(activeTableReference);
    when(activeTableReference.getUserTablePreferences()).thenReturn(userTablePreferences);
    when(activeTableReference.getPagination()).thenReturn(pagination);
    doCallRealMethod().when(tableViewTopComponent).handleGraphClosed(any(Graph.class));
    tableViewTopComponent.handleGraphClosed(mock(Graph.class));
    verify(activeTableReference).updatePagination(42, null, tablePane);
}
Also used : Pagination(javafx.scene.control.Pagination) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) UserTablePreferences(au.gov.asd.tac.constellation.views.tableview.api.UserTablePreferences) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Example 2 with TablePane

use of au.gov.asd.tac.constellation.views.tableview.panes.TablePane in project constellation by constellation-app.

the class TableViewTopComponentNGTest method showSelected.

@Test
public void showSelected() {
    final TableViewTopComponent tableViewTopComponent = mock(TableViewTopComponent.class);
    final TableViewState currentState = new TableViewState();
    final Graph currentGraph = mock(Graph.class);
    final TableViewState expectedNewState = new TableViewState();
    expectedNewState.setElementType(GraphElementType.META);
    expectedNewState.setSelectedOnly(true);
    final TablePane tablePane = mock(TablePane.class);
    final Table table = mock(Table.class);
    doCallRealMethod().when(tableViewTopComponent).showSelected(any(GraphElementType.class), anyInt());
    when(tableViewTopComponent.getCurrentState()).thenReturn(currentState);
    when(tableViewTopComponent.getCurrentGraph()).thenReturn(currentGraph);
    when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
    when(tableViewTopComponent.getExecutorService()).thenReturn(Executors.newSingleThreadExecutor());
    when(tablePane.getTable()).thenReturn(table);
    try (final MockedStatic<PluginExecution> pluginExecutionMockedStatic = Mockito.mockStatic(PluginExecution.class)) {
        final PluginExecution pluginExecution = mock(PluginExecution.class);
        when(pluginExecution.executeLater(any(Graph.class))).thenReturn(CompletableFuture.completedFuture(null));
        pluginExecutionMockedStatic.when(() -> PluginExecution.withPlugin(any(UpdateStatePlugin.class))).thenAnswer(mockitoInvocation -> {
            final UpdateStatePlugin plugin = (UpdateStatePlugin) mockitoInvocation.getArgument(0);
            assertEquals(expectedNewState, plugin.getTableViewState());
            // Change the mock now that the "Update Plugin" has run
            when(tableViewTopComponent.getCurrentState()).thenReturn(expectedNewState);
            return pluginExecution;
        });
        final Future<?> updateTask = tableViewTopComponent.showSelected(GraphElementType.META, 42);
        // Ensure that the update selection task is completed
        try {
            updateTask.get(5, TimeUnit.SECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException ex) {
            fail("The submitted task in show selected did not complete in the " + "allowed time. Something is probably wrong.");
        }
        verify(pluginExecution).executeLater(currentGraph);
        verify(table).updateSelection(currentGraph, expectedNewState);
    }
}
Also used : PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) UpdateStatePlugin(au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ExecutionException(java.util.concurrent.ExecutionException) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 3 with TablePane

use of au.gov.asd.tac.constellation.views.tableview.panes.TablePane in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updatePaginationNoNewRowList.

@Test
public void updatePaginationNoNewRowList() {
    final Pagination pagination = mock(Pagination.class);
    final TablePane tablePane = mock(TablePane.class);
    doReturn(pagination).when(activeTableReference).updatePagination(eq(22), same(sortedRowList), same(tablePane));
    assertSame(pagination, activeTableReference.updatePagination(22, tablePane));
}
Also used : Pagination(javafx.scene.control.Pagination) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Example 4 with TablePane

use of au.gov.asd.tac.constellation.views.tableview.panes.TablePane in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updatePaginationNewRowListNull.

@Test
public void updatePaginationNewRowListNull() throws InterruptedException {
    final List<ObservableList<String>> newRowList = null;
    final TablePane tablePane = mock(TablePane.class);
    final Pagination pagination = activeTableReference.updatePagination(22, newRowList, tablePane);
    assertEquals(1, pagination.getPageCount());
    assertSame(pageFactory, pagination.getPageFactory());
    verify(pageFactory).update(same(newRowList), eq(22));
    // This verification is dependent on code completing in the UI thread so
    // the following ensures that the verification does not occur until
    // the required code is run.
    final CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> latch.countDown());
    latch.await();
    verify(tablePane).setCenter(same(pagination));
}
Also used : Pagination(javafx.scene.control.Pagination) ObservableList(javafx.collections.ObservableList) CountDownLatch(java.util.concurrent.CountDownLatch) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Example 5 with TablePane

use of au.gov.asd.tac.constellation.views.tableview.panes.TablePane in project constellation by constellation-app.

the class ActiveTableReferenceNGTest method updatePaginationNewRowListEmpty.

@Test
public void updatePaginationNewRowListEmpty() throws InterruptedException {
    final List<ObservableList<String>> newRowList = new ArrayList<>();
    final TablePane tablePane = mock(TablePane.class);
    final Pagination pagination = activeTableReference.updatePagination(22, newRowList, tablePane);
    assertEquals(1, pagination.getPageCount());
    assertSame(pageFactory, pagination.getPageFactory());
    verify(pageFactory).update(same(newRowList), eq(22));
    // This verification is dependent on code completing in the UI thread so
    // the following ensures that the verification does not occur until
    // the required code is run.
    final CountDownLatch latch = new CountDownLatch(1);
    Platform.runLater(() -> latch.countDown());
    latch.await();
    verify(tablePane).setCenter(same(pagination));
}
Also used : Pagination(javafx.scene.control.Pagination) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Aggregations

TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)10 Test (org.testng.annotations.Test)8 Graph (au.gov.asd.tac.constellation.graph.Graph)6 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)5 Pagination (javafx.scene.control.Pagination)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)4 ObservableList (javafx.collections.ObservableList)4 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TableColumn (javafx.scene.control.TableColumn)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)2 TableViewTopComponent (au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent)2 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)2 ProgressBar (au.gov.asd.tac.constellation.views.tableview.components.ProgressBar)2 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2