Search in sources :

Example 36 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCreateComparisonGraphWithAddedTransactionInReverse.

/**
 * Test of createComparisonGraph method, of class CompareGraphPlugin.
 *
 * @throws java.lang.Exception
 */
@Test
public void testCreateComparisonGraphWithAddedTransactionInReverse() throws Exception {
    int vx0, vx1, tx0, tx1;
    int labelAttribute, uniqueIdAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    originalGraph.setStringValue(labelAttribute, vx0, "vx0");
    originalGraph.setStringValue(labelAttribute, vx1, "vx1");
    originalGraph.setStringValue(uniqueIdAttribute, tx0, "1");
    final StoreGraph compareGraph = new StoreGraph(schema);
    labelAttribute = VisualConcept.VertexAttribute.LABEL.ensure(compareGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(compareGraph);
    compareGraph.setPrimaryKey(GraphElementType.VERTEX, labelAttribute);
    compareGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = compareGraph.addVertex();
    vx1 = compareGraph.addVertex();
    tx0 = compareGraph.addTransaction(vx1, vx0, true);
    compareGraph.setStringValue(labelAttribute, vx0, "vx0");
    compareGraph.setStringValue(labelAttribute, vx1, "vx1");
    originalGraph.setStringValue(uniqueIdAttribute, tx0, "2");
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final GraphRecordStore compareAll = GraphRecordStoreUtilities.getAll(compareGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = false;
    final Graph finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    System.out.println("changes ==>\n" + changes.toStringVerbose());
    final ReadableGraph rg = finalGraph.getReadableGraph();
    try {
        assertEquals(rg.getVertexCount(), 2);
        assertEquals(rg.getTransactionCount(), 2);
        vx0 = rg.getVertex(0);
        vx1 = rg.getVertex(1);
        tx0 = rg.getTransaction(0);
        tx1 = rg.getTransaction(1);
        labelAttribute = rg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.LABEL.getName());
        assertEquals(rg.getStringValue(labelAttribute, vx0), "vx0");
        assertEquals(rg.getStringValue(labelAttribute, vx1), "vx1");
        assertEquals(rg.getTransactionSourceVertex(tx0), vx0);
        assertEquals(rg.getTransactionSourceVertex(tx1), vx1);
    } finally {
        rg.release();
    }
    SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
    SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph");
    SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "testCreateComparisonGraphWithAddedTransactionInReverse", true);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 37 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCompareGraphsWithMissingNodeInChain.

@Test
public void testCompareGraphsWithMissingNodeInChain() throws Exception {
    // mimic GraphRecordStoreUtilities.getAll()
    final GraphRecordStore original = new GraphRecordStore();
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER, "1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx2");
    original.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER, "2");
    final GraphRecordStore compare = new GraphRecordStore();
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    final Set<String> vertexPrimaryKeys = new HashSet<>();
    vertexPrimaryKeys.add(VisualConcept.VertexAttribute.LABEL.getName());
    final Set<String> transactionPrimaryKeys = new HashSet<>();
    transactionPrimaryKeys.add(VisualConcept.TransactionAttribute.IDENTIFIER.getName());
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", original, compare, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    System.out.println("original ==>\n" + original.toStringVerbose());
    System.out.println("compare ==>\n" + compare.toStringVerbose());
    System.out.println("changes ==>\n" + changes.toStringVerbose());
    assertEquals(changes.size(), 5);
    changes.reset();
    changes.next();
    assertEquals("vx0", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.UNCHANGED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals("vx1", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals("vx2", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.UNCHANGED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals("vx0", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals("vx1", changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL));
    assertEquals("1", changes.get(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER));
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals("vx1", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals("vx2", changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL));
    assertEquals("2", changes.get(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER));
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE));
}
Also used : ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 38 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCompareGraphsWithDuplicateChanges.

@Test
public void testCompareGraphsWithDuplicateChanges() throws Exception {
    // mimic GraphRecordStoreUtilities.getAll()
    final GraphRecordStore original = new GraphRecordStore();
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    final GraphRecordStore compare = new GraphRecordStore();
    final Set<String> vertexPrimaryKeys = new HashSet<>();
    vertexPrimaryKeys.add(VisualConcept.VertexAttribute.LABEL.getName());
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", original, compare, vertexPrimaryKeys, new HashSet<>(), ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    System.out.println("original ==>\n" + original.toStringVerbose());
    System.out.println("compare ==>\n" + compare.toStringVerbose());
    System.out.println("changes ==>\n" + changes.toStringVerbose());
    assertEquals(changes.size(), 2);
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
}
Also used : ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 39 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCompareGraphsWithMissingNodeOnCompareGraph.

@Test
public void testCompareGraphsWithMissingNodeOnCompareGraph() throws Exception {
    // mimic GraphRecordStoreUtilities.getAll()
    final GraphRecordStore original = new GraphRecordStore();
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    final GraphRecordStore compare = new GraphRecordStore();
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    final Set<String> vertexPrimaryKeys = new HashSet<>();
    vertexPrimaryKeys.add(VisualConcept.VertexAttribute.LABEL.getName());
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", original, compare, vertexPrimaryKeys, new HashSet<>(), ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    System.out.println("changes=>" + changes.toStringVerbose());
    assertEquals(changes.size(), 3);
    changes.reset();
    changes.next();
    assertEquals("vx0", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.UNCHANGED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals("vx1", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
    changes.next();
    assertEquals(CompareGraphPlugin.REMOVED, changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE));
}
Also used : ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 40 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCompareGraphsWithMissingTransactions.

@Test
public void testCompareGraphsWithMissingTransactions() throws Exception {
    // mimic GraphRecordStoreUtilities.getAll()
    final GraphRecordStore original = new GraphRecordStore();
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER, "1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER, "2");
    final GraphRecordStore compare = new GraphRecordStore();
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    compare.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    compare.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.IDENTIFIER, "1");
    final Set<String> vertexPrimaryKeys = new HashSet<>();
    vertexPrimaryKeys.add(VisualConcept.VertexAttribute.LABEL.getName());
    final Set<String> transactionPrimaryKeys = new HashSet<>();
    transactionPrimaryKeys.add(VisualConcept.TransactionAttribute.IDENTIFIER.getName());
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", original, compare, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    System.out.println("original ==>\n" + original.toStringVerbose());
    System.out.println("compare ==>\n" + compare.toStringVerbose());
    System.out.println("changes ==>\n" + changes.toStringVerbose());
    assertEquals(changes.size(), 3);
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    // TODO: missing 1 more which is an unchanged for vx1 ??
    // changes.next();
    // assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx1");
    // assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
}
Also used : ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet) 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