Search in sources :

Example 1 with AbstractAttributeInteraction

use of au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction in project constellation by constellation-app.

the class TableNGTest method getRowDataForVertex.

@Test
public void getRowDataForVertex() {
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    final Map<Integer, ObservableList<String>> elementIdToRowIndex = new HashMap<>();
    final Map<ObservableList<String>, Integer> rowToElementIdIndex = new HashMap<>();
    doReturn(elementIdToRowIndex).when(activeTableReference).getElementIdToRowIndex();
    doReturn(rowToElementIdIndex).when(activeTableReference).getRowToElementIdIndex();
    final int vertexId = 42;
    // Set up the attributes for each column
    when(readableGraph.getAttribute(GraphElementType.VERTEX, "COLUMN_A")).thenReturn(101);
    when(readableGraph.getAttributeName(101)).thenReturn("COLUMN_A");
    when(readableGraph.getAttributeElementType(101)).thenReturn(GraphElementType.VERTEX);
    when(readableGraph.getAttributeType(101)).thenReturn("string");
    final Object objectValue1 = new Object();
    when(readableGraph.getObjectValue(101, vertexId)).thenReturn(objectValue1);
    final Attribute attribute1 = new GraphAttribute(readableGraph, 101);
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column(null, attribute1, null));
    when(table.getColumnIndex()).thenReturn(columnIndex);
    try (final MockedStatic<AbstractAttributeInteraction> attrInteractionMockedStatic = Mockito.mockStatic(AbstractAttributeInteraction.class)) {
        final AbstractAttributeInteraction interaction = mock(AbstractAttributeInteraction.class);
        attrInteractionMockedStatic.when(() -> AbstractAttributeInteraction.getInteraction("string")).thenReturn(interaction);
        when(interaction.getDisplayText(objectValue1)).thenReturn("column1Value");
        assertEquals(FXCollections.observableArrayList("column1Value"), table.getRowDataForVertex(readableGraph, vertexId));
        assertEquals(Map.of(vertexId, FXCollections.observableArrayList("column1Value")), elementIdToRowIndex);
        assertEquals(Map.of(FXCollections.observableArrayList("column1Value"), vertexId), rowToElementIdIndex);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HashMap(java.util.HashMap) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) AbstractAttributeInteraction(au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Example 2 with AbstractAttributeInteraction

use of au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction in project constellation by constellation-app.

the class TableNGTest method getRowDataForTransaction.

@Test
public void getRowDataForTransaction() {
    final ReadableGraph readableGraph = mock(ReadableGraph.class);
    final Map<Integer, ObservableList<String>> elementIdToRowIndex = new HashMap<>();
    final Map<ObservableList<String>, Integer> rowToElementIdIndex = new HashMap<>();
    doReturn(elementIdToRowIndex).when(activeTableReference).getElementIdToRowIndex();
    doReturn(rowToElementIdIndex).when(activeTableReference).getRowToElementIdIndex();
    final int transactionId = 42;
    final int sourceVertexId = 52;
    final int destinationVertexId = 62;
    // Set up the attributes for each column
    when(readableGraph.getAttribute(GraphElementType.VERTEX, "COLUMN_1")).thenReturn(101);
    when(readableGraph.getAttributeName(101)).thenReturn("COLUMN_1");
    when(readableGraph.getAttributeElementType(101)).thenReturn(GraphElementType.VERTEX);
    when(readableGraph.getAttributeType(101)).thenReturn("string");
    final Attribute attribute1 = new GraphAttribute(readableGraph, 101);
    when(readableGraph.getAttribute(GraphElementType.TRANSACTION, "COLUMN_2")).thenReturn(102);
    when(readableGraph.getAttributeName(102)).thenReturn("COLUMN_2");
    when(readableGraph.getAttributeElementType(102)).thenReturn(GraphElementType.TRANSACTION);
    when(readableGraph.getAttributeType(102)).thenReturn("string");
    final Attribute attribute2 = new GraphAttribute(readableGraph, 102);
    // There are 2 columns. One called COLUMN_1 and the other COLUMN_2. COLUMN_1
    // is present on source and destination verticies. COLUMN_2 is present on transactions
    final CopyOnWriteArrayList<Column> columnIndex = new CopyOnWriteArrayList<>();
    columnIndex.add(new Column("source.", attribute1, null));
    columnIndex.add(new Column("destination.", attribute1, null));
    columnIndex.add(new Column("transaction.", attribute2, null));
    when(table.getColumnIndex()).thenReturn(columnIndex);
    // When looking at a source vertex column, it gets the source vertex of
    // the transaction and extracts the value for the column from that vertex
    final Object sourceVertexCoulmnValue = new Object();
    when(readableGraph.getTransactionSourceVertex(transactionId)).thenReturn(sourceVertexId);
    when(readableGraph.getObjectValue(101, sourceVertexId)).thenReturn(sourceVertexCoulmnValue);
    // When looking at a destination vertex column, it gets the destination vertex of
    // the transaction and extracts the value for the column from that vertex
    final Object destinationVertexCoulmnValue = new Object();
    when(readableGraph.getTransactionDestinationVertex(transactionId)).thenReturn(destinationVertexId);
    when(readableGraph.getObjectValue(101, destinationVertexId)).thenReturn(destinationVertexCoulmnValue);
    // When looking at a transaction column, it extracts the value from the passed transaction
    final Object transactionCoulmnValue = new Object();
    when(readableGraph.getObjectValue(102, transactionId)).thenReturn(transactionCoulmnValue);
    try (final MockedStatic<AbstractAttributeInteraction> attrInteractionMockedStatic = Mockito.mockStatic(AbstractAttributeInteraction.class)) {
        final AbstractAttributeInteraction interaction = mock(AbstractAttributeInteraction.class);
        attrInteractionMockedStatic.when(() -> AbstractAttributeInteraction.getInteraction("string")).thenReturn(interaction);
        when(interaction.getDisplayText(sourceVertexCoulmnValue)).thenReturn("sourceVertex_COLUMN_1_Value");
        when(interaction.getDisplayText(destinationVertexCoulmnValue)).thenReturn("destinationVertext_COLUMN_1_Value");
        when(interaction.getDisplayText(transactionCoulmnValue)).thenReturn("transaction_COLUMN_2_Value");
        assertEquals(FXCollections.observableArrayList("sourceVertex_COLUMN_1_Value", "destinationVertext_COLUMN_1_Value", "transaction_COLUMN_2_Value"), table.getRowDataForTransaction(readableGraph, transactionId));
        assertEquals(Map.of(transactionId, FXCollections.observableArrayList("sourceVertex_COLUMN_1_Value", "destinationVertext_COLUMN_1_Value", "transaction_COLUMN_2_Value")), elementIdToRowIndex);
        assertEquals(Map.of(FXCollections.observableArrayList("sourceVertex_COLUMN_1_Value", "destinationVertext_COLUMN_1_Value", "transaction_COLUMN_2_Value"), transactionId), rowToElementIdIndex);
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) HashMap(java.util.HashMap) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ObservableList(javafx.collections.ObservableList) Column(au.gov.asd.tac.constellation.views.tableview.api.Column) TableColumn(javafx.scene.control.TableColumn) AbstractAttributeInteraction(au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.testng.annotations.Test)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 AbstractAttributeInteraction (au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction)2 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)2 HashMap (java.util.HashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ObservableList (javafx.collections.ObservableList)2 TableColumn (javafx.scene.control.TableColumn)2 Test (org.testng.annotations.Test)2