Search in sources :

Example 31 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableViewUtilitiesNGTest method getSelectedIdsForTransactions.

@Test
public void getSelectedIdsForTransactions() {
    final Graph graph = mock(Graph.class);
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    when(readableGraph.getAttribute(GraphElementType.TRANSACTION, "selected")).thenReturn(5);
    when(readableGraph.getTransactionCount()).thenReturn(3);
    when(readableGraph.getTransaction(0)).thenReturn(100);
    when(readableGraph.getTransaction(1)).thenReturn(101);
    when(readableGraph.getTransaction(2)).thenReturn(102);
    when(readableGraph.getBooleanValue(5, 100)).thenReturn(true);
    when(readableGraph.getBooleanValue(5, 101)).thenReturn(false);
    when(readableGraph.getBooleanValue(5, 102)).thenReturn(true);
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.TRANSACTION);
    assertEquals(List.of(100, 102), TableViewUtilities.getSelectedIds(graph, tableViewState));
    verify(readableGraph).release();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) 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) Test(org.testng.annotations.Test)

Example 32 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TableViewUtilitiesNGTest method getSelectedIdsForVertecies.

@Test
public void getSelectedIdsForVertecies() {
    final Graph graph = mock(Graph.class);
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    when(readableGraph.getAttribute(GraphElementType.VERTEX, "selected")).thenReturn(5);
    when(readableGraph.getVertexCount()).thenReturn(3);
    when(readableGraph.getVertex(0)).thenReturn(100);
    when(readableGraph.getVertex(1)).thenReturn(101);
    when(readableGraph.getVertex(2)).thenReturn(102);
    when(readableGraph.getBooleanValue(5, 100)).thenReturn(true);
    when(readableGraph.getBooleanValue(5, 101)).thenReturn(false);
    when(readableGraph.getBooleanValue(5, 102)).thenReturn(true);
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.VERTEX);
    assertEquals(List.of(100, 102), TableViewUtilities.getSelectedIds(graph, tableViewState));
    verify(readableGraph).release();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) 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) Test(org.testng.annotations.Test)

Example 33 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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 34 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState 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)

Example 35 with TableViewState

use of au.gov.asd.tac.constellation.views.tableview.state.TableViewState in project constellation by constellation-app.

the class TablePaneNGTest method updateTable.

@Test
public void updateTable() {
    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);
    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);
    verify(table).updateColumns(graph, tableViewState);
    verify(table).updateData(graph, tableViewState, progressBar);
    verify(table).updateSelection(graph, tableViewState);
    // The future finished but maybe not the JavaFX thread
    WaitForAsyncUtils.waitForFxEvents();
    verify(table).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

TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)65 Test (org.testng.annotations.Test)50 Graph (au.gov.asd.tac.constellation.graph.Graph)24 Platform (javafx.application.Platform)19 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)14 ObservableList (javafx.collections.ObservableList)14 Attribute (au.gov.asd.tac.constellation.graph.Attribute)13 UpdateStatePlugin (au.gov.asd.tac.constellation.views.tableview.plugins.UpdateStatePlugin)12 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)10 TableColumn (javafx.scene.control.TableColumn)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 TablePane (au.gov.asd.tac.constellation.views.tableview.panes.TablePane)7 ListChangeListener (javafx.collections.ListChangeListener)7 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)6 TableViewUtilities (au.gov.asd.tac.constellation.views.tableview.utilities.TableViewUtilities)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)5 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)5 Table (au.gov.asd.tac.constellation.views.tableview.components.Table)5 ArrayList (java.util.ArrayList)5