Search in sources :

Example 46 with GraphRecordStore

use of au.gov.asd.tac.constellation.graph.processing.GraphRecordStore in project constellation by constellation-app.

the class GraphRecordStoreUtilitiesNGTest method addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema.

@Test
public void addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema() {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "vx1");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + GraphRecordStoreUtilities.DIRECTED_KEY, false);
    // the communication type is directed
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + AnalyticConcept.TransactionAttribute.TYPE, AnalyticConcept.TransactionType.COMMUNICATION);
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = false;
    final List<String> vertexIdAttributes = new ArrayList<>();
    final Map<String, Integer> vertexMap = new HashMap<>();
    final Map<String, Integer> transactionMap = new HashMap<>();
    final List<Integer> veritices = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes, vertexMap, transactionMap);
    assertEquals(2, veritices.size());
    assertEquals(2, graph.getVertexCount());
    assertEquals(1, graph.getTransactionCount());
    // try {
    // SaveGraphUtilities.saveGraphToTemporaryDirectory(graph, "testAddedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema");
    // } catch (IOException ex) {
    // Assert.fail(ex.getLocalizedMessage());
    // }
    final int transactionTypeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    SchemaTransactionType type = (SchemaTransactionType) graph.getObjectValue(transactionTypeId, 0);
    Assert.assertFalse(type.isDirected());
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Example 47 with GraphRecordStore

use of au.gov.asd.tac.constellation.graph.processing.GraphRecordStore in project constellation by constellation-app.

the class GraphRecordStoreUtilitiesNGTest method testAddRecordStoreToGraphIncludesAllRecords.

@Test
public void testAddRecordStoreToGraphIncludesAllRecords() {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx3");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Removed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Changed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + "CustomAttribute", "Removed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx5");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Added");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx5");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + "CustomAttribute", "Added");
    // add recordstore to graph
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = false;
    final List<String> vertexIdAttributes = new ArrayList<>();
    vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
    final List<Integer> veritices = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes);
    // check counts
    assertEquals(veritices.size(), 6);
    final int vxCount = graph.getVertexCount();
    assertEquals(vxCount, 6);
    final int txCount = graph.getTransactionCount();
    assertEquals(txCount, 4);
    // check that all vertices start with vx
    final int vxNameAttribute = VisualConcept.VertexAttribute.LABEL.get(graph);
    for (int i = 0; i < vxCount; i++) {
        int vxId = graph.getVertex(i);
        assertEquals(graph.getStringValue(vxNameAttribute, vxId), String.valueOf("vx" + vxId));
    }
// try {
// SaveGraphUtilities.saveGraphToTemporaryDirectory(graph, "testAddRecordStoreToGraphIncludesAllRecords");
// } catch (IOException ex) {
// Assert.fail(ex.getLocalizedMessage());
// }
}
Also used : RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Aggregations

GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)47 Test (org.testng.annotations.Test)33 ArrayList (java.util.ArrayList)24 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)19 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)19 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)15 Graph (au.gov.asd.tac.constellation.graph.Graph)12 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)11 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)10 HashSet (java.util.HashSet)10 DefaultPluginInteraction (au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction)9 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)8 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)8 HashMap (java.util.HashMap)8 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)7 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)7 IOException (java.io.IOException)5 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)3 File (java.io.File)3