Search in sources :

Example 1 with ThreeTuple

use of au.gov.asd.tac.constellation.utilities.datastructure.ThreeTuple in project constellation by constellation-app.

the class TableNGTest method updateColumnsStateColumnsNotSet.

@Test
public void updateColumnsStateColumnsNotSet() {
    final ChangeListener<ObservableList<String>> tableSelectionListener = mock(ChangeListener.class);
    final ListChangeListener selectedOnlySelectionListener = mock(ListChangeListener.class);
    doReturn(tableSelectionListener).when(table).getTableSelectionListener();
    doReturn(selectedOnlySelectionListener).when(table).getSelectedOnlySelectionListener();
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    when(graph.getReadableGraph()).thenReturn(readableGraph);
    // Set up the initial column index.
    final String columnType1 = "source.";
    final Attribute attribute1 = mock(Attribute.class);
    final TableColumn<ObservableList<String>, String> column1 = mock(TableColumn.class);
    when(column1.getText()).thenReturn("source.COLUMN_A");
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(columnType1, attribute1, column1));
    when(activeTableReference.getColumnIndex()).thenReturn(columnIndex);
    // This is a reference of the old column index that will be used whilst the new
    // index is being created. Because that creation is mocked this is used only as a
    // vertification that the parameter is being correctly constructed.
    final Map<String, TableColumn<ObservableList<String>, String>> columnReferenceMap = Map.of("source.COLUMN_A", column1);
    // Mock out the re-population of the column index from the graph
    final CopyOnWriteArrayList<ThreeTuple<String, Attribute, TableColumn<ObservableList<String>, String>>> sourceColumnIndex = new CopyOnWriteArrayList<>();
    sourceColumnIndex.add(ThreeTuple.create(columnType1, attribute1, column1));
    doReturn(sourceColumnIndex).when(table).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "source.", columnReferenceMap);
    // Set up the table state
    final TableViewState tableViewState = new TableViewState();
    tableViewState.setElementType(GraphElementType.VERTEX);
    // When this is null, the update is interrupted and the user is asked to select
    // which columns they want visible
    tableViewState.setColumnAttributes(null);
    // Don't want it trying to open the menu to select which columns to show
    doNothing().when(table).openColumnVisibilityMenu();
    try (final MockedStatic<Platform> platformMockedStatic = Mockito.mockStatic(Platform.class)) {
        platformMockedStatic.when(Platform::isFxApplicationThread).thenReturn(false);
        platformMockedStatic.when(() -> Platform.runLater(any(Runnable.class))).then(mockInvocation -> {
            assertTrue(mockInvocation.getArgument(0) instanceof UpdateColumnsTask);
            return null;
        });
        table.updateColumns(graph, tableViewState);
    }
    // Verify the new column index
    final CopyOnWriteArrayList<ThreeTuple<String, Attribute, TableColumn<ObservableList<String>, String>>> expectedColumnIndex = new CopyOnWriteArrayList<>();
    expectedColumnIndex.add(ThreeTuple.create(columnType1, attribute1, column1));
    assertEquals(expectedColumnIndex, columnIndex);
    // Because the state element type is set to vertex, only the source columns are populated
    verify(table, times(0)).createColumnIndexPart(readableGraph, GraphElementType.VERTEX, "destination.", columnReferenceMap);
    verify(table, times(0)).createColumnIndexPart(readableGraph, GraphElementType.TRANSACTION, "transaction.", columnReferenceMap);
    // Verify the menu open method was called
    verify(table).openColumnVisibilityMenu();
    // Verify that the new column index did not have its factories set
    verify(column1, times(0)).setCellValueFactory(any(Callback.class));
    verify(column1, times(0)).setCellFactory(any(Callback.class));
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Platform(javafx.application.Platform) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) UpdateColumnsTask(au.gov.asd.tac.constellation.views.tableview.tasks.UpdateColumnsTask) TableColumn(javafx.scene.control.TableColumn) ListChangeListener(javafx.collections.ListChangeListener) Callback(javafx.util.Callback) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) ThreeTuple(au.gov.asd.tac.constellation.utilities.datastructure.ThreeTuple) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 ThreeTuple (au.gov.asd.tac.constellation.utilities.datastructure.ThreeTuple)1 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)1 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)1 UpdateColumnsTask (au.gov.asd.tac.constellation.views.tableview.tasks.UpdateColumnsTask)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Platform (javafx.application.Platform)1 ListChangeListener (javafx.collections.ListChangeListener)1 ObservableList (javafx.collections.ObservableList)1 TableColumn (javafx.scene.control.TableColumn)1 Callback (javafx.util.Callback)1 Test (org.testng.annotations.Test)1