Search in sources :

Example 1 with Table

use of au.gov.asd.tac.constellation.views.tableview.components.Table 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 2 with Table

use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.

the class UpdateColumnsTaskNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    tableViewTopComponent = mock(TableViewTopComponent.class);
    tableView = mock(TableView.class);
    tablePane = mock(TablePane.class);
    table = mock(Table.class);
    activeTableReference = mock(ActiveTableReference.class);
    selectionModel = mock(TableViewSelectionModel.class);
    selectedItemProperty = mock(ReadOnlyObjectProperty.class);
    selectedItems = mock(ObservableList.class);
    tableSelectionListener = mock(ChangeListener.class);
    selectedOnlySelectionListener = mock(ListChangeListener.class);
    columnType1 = "source.";
    attribute1 = mock(Attribute.class);
    column1 = mock(TableColumn.class);
    columnType2 = "destination.";
    attribute2 = mock(Attribute.class);
    column2 = mock(TableColumn.class);
    columnType3 = "source.";
    attribute3 = mock(Attribute.class);
    column3 = mock(TableColumn.class);
    columnType4 = "transaction.";
    attribute4 = mock(Attribute.class);
    column4 = mock(TableColumn.class);
    columnType5 = "transaction.";
    attribute5 = mock(Attribute.class);
    column5 = mock(TableColumn.class);
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(columnType1, attribute1, column1));
    columnIndex.add(new Column(columnType2, attribute2, column2));
    columnIndex.add(new Column(columnType3, attribute3, column3));
    columnIndex.add(new Column(columnType4, attribute4, column4));
    columnIndex.add(new Column(columnType5, attribute5, column5));
    when(tableViewTopComponent.getTablePane()).thenReturn(tablePane);
    when(tablePane.getTable()).thenReturn(table);
    when(tablePane.getActiveTableReference()).thenReturn(activeTableReference);
    when(tablePane.getParentComponent()).thenReturn(tableViewTopComponent);
    when(activeTableReference.getColumnIndex()).thenReturn(columnIndex);
    when(table.getTableView()).thenReturn(tableView);
    when(table.getSelectedOnlySelectionListener()).thenReturn(selectedOnlySelectionListener);
    when(table.getTableSelectionListener()).thenReturn(tableSelectionListener);
    when(table.getParentComponent()).thenReturn(tablePane);
    when(tableView.getSelectionModel()).thenReturn(selectionModel);
    when(selectionModel.selectedItemProperty()).thenReturn(selectedItemProperty);
    when(selectionModel.getSelectedItems()).thenReturn(selectedItems);
    updateColumnsTask = spy(new UpdateColumnsTask(table));
}
Also used : Table(au.gov.asd.tac.constellation.views.tableview.components.Table) Attribute(au.gov.asd.tac.constellation.graph.Attribute) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) TableColumn(javafx.scene.control.TableColumn) ListChangeListener(javafx.collections.ListChangeListener) TableViewTopComponent(au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ObservableList(javafx.collections.ObservableList) TableColumn(javafx.scene.control.TableColumn) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ActiveTableReference(au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference) TableView(javafx.scene.control.TableView) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with Table

use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.

the class UpdateTableDataTaskNGTest method updateDataTask.

@Test
public void updateDataTask() {
    final TablePane tablePane = mock(TablePane.class);
    final Graph graph = mock(Graph.class);
    final TableViewState tableViewState = new TableViewState();
    final Table table = mock(Table.class);
    final ProgressBar progressBar = mock(ProgressBar.class);
    when(tablePane.getTable()).thenReturn(table);
    when(tablePane.getProgressBar()).thenReturn(progressBar);
    final TriggerDataUpdateTask updateTableDataTask = new TriggerDataUpdateTask(tablePane, graph, tableViewState);
    updateTableDataTask.run();
    verify(table).updateData(graph, tableViewState, progressBar);
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ProgressBar(au.gov.asd.tac.constellation.views.tableview.components.ProgressBar) TablePane(au.gov.asd.tac.constellation.views.tableview.panes.TablePane) Test(org.testng.annotations.Test)

Example 4 with Table

use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.

the class TablePaneNGTest method updateTableGraphIsNull.

@Test
public void updateTableGraphIsNull() throws InterruptedException, ExecutionException, TimeoutException {
    final Table table = mock(Table.class);
    final TableView<ObservableList<String>> tableView = mock(TableView.class);
    final TableViewState tableViewState = new TableViewState();
    final TableToolbar tableToolbar = mock(TableToolbar.class);
    final List<TableColumn<ObservableList<String>, String>> tableColumns = new ArrayList<>();
    tableColumns.add(mock(TableColumn.class));
    tableColumns.add(mock(TableColumn.class));
    final ObservableList<TableColumn<ObservableList<String>, String>> columns = FXCollections.observableList(tableColumns);
    when(tablePane.getTable()).thenReturn(table);
    when(table.getTableView()).thenReturn(tableView);
    doReturn(columns).when(tableView).getColumns();
    when(tablePane.getTableToolbar()).thenReturn(tableToolbar);
    tablePane.updateTable(null, tableViewState);
    try {
        tablePane.getFuture().get(30, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        fail("The update thread did not finish as expected within the allowed time. " + "Something went wrong");
    }
    verify(tableToolbar).updateToolbar(tableViewState);
    verify(table, times(0)).updateColumns(any(Graph.class), any(TableViewState.class));
    verify(table, times(0)).updateData(any(Graph.class), any(TableViewState.class), any(ProgressBar.class));
    verify(table, times(0)).updateSelection(any(Graph.class), any(TableViewState.class));
    // The future finished but maybe not the JavaFX thread
    WaitForAsyncUtils.waitForFxEvents();
    verify(table, times(0)).updateSortOrder();
    assertTrue(columns.isEmpty());
}
Also used : Table(au.gov.asd.tac.constellation.views.tableview.components.Table) TableToolbar(au.gov.asd.tac.constellation.views.tableview.components.TableToolbar) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Graph(au.gov.asd.tac.constellation.graph.Graph) ObservableList(javafx.collections.ObservableList) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ExecutionException(java.util.concurrent.ExecutionException) ProgressBar(au.gov.asd.tac.constellation.views.tableview.components.ProgressBar) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 5 with Table

use of au.gov.asd.tac.constellation.views.tableview.components.Table in project constellation by constellation-app.

the class TablePaneNGTest method updateTable_interrupt.

@Test
public void updateTable_interrupt() {
    final Graph graph = mock(Graph.class);
    final TableViewState tableViewState = new TableViewState();
    final Table table = mock(Table.class);
    final ProgressBar progressBar = mock(ProgressBar.class);
    final TableToolbar tableToolbar = mock(TableToolbar.class);
    when(tablePane.getTable()).thenReturn(table);
    when(tablePane.getProgressBar()).thenReturn(progressBar);
    when(tablePane.getTableToolbar()).thenReturn(tableToolbar);
    doAnswer(mockitoInvocation -> {
        System.out.println("Interrupt: " + Thread.currentThread().getName());
        Thread.currentThread().interrupt();
        return null;
    }).when(table).updateColumns(graph, tableViewState);
    tablePane.updateTable(graph, tableViewState);
    try {
        tablePane.getFuture().get(30, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        fail("The update thread did not finish as expected within the allowed time. " + "Something went wrong");
    }
    verify(tableToolbar).updateToolbar(tableViewState);
    // Update columns is called
    verify(table).updateColumns(graph, tableViewState);
    // Verify everything after that is not called
    verify(table, times(0)).updateData(graph, tableViewState, progressBar);
    verify(table, times(0)).updateSelection(graph, tableViewState);
    // The future finished but maybe not the JavaFX thread
    WaitForAsyncUtils.waitForFxEvents();
    verify(table, times(0)).updateSortOrder();
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) Table(au.gov.asd.tac.constellation.views.tableview.components.Table) TableToolbar(au.gov.asd.tac.constellation.views.tableview.components.TableToolbar) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ExecutionException(java.util.concurrent.ExecutionException) ProgressBar(au.gov.asd.tac.constellation.views.tableview.components.ProgressBar) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Aggregations

Table (au.gov.asd.tac.constellation.views.tableview.components.Table)7 Graph (au.gov.asd.tac.constellation.graph.Graph)6 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)6 Test (org.testng.annotations.Test)6 ProgressBar (au.gov.asd.tac.constellation.views.tableview.components.ProgressBar)5 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 TableToolbar (au.gov.asd.tac.constellation.views.tableview.components.TableToolbar)3 ObservableList (javafx.collections.ObservableList)2 TableColumn (javafx.scene.control.TableColumn)2 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 TableViewTopComponent (au.gov.asd.tac.constellation.views.tableview.TableViewTopComponent)1 ActiveTableReference (au.gov.asd.tac.constellation.views.tableview.api.ActiveTableReference)1 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)1 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)1 ArrayList (java.util.ArrayList)1