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);
}
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));
}
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);
}
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));
}
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);
}
Aggregations