use of au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin in project constellation by constellation-app.
the class CompositesNGTest method ensureCompositeStateImmutabilityTest.
// This test checks that expanding composite node states that have been copied to another graph do not affect the
// composite node states in the original graph.
@Test
public void ensureCompositeStateImmutabilityTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
wg.getSchema().newGraph(wg);
int v0, v1, v2;
final String v0name, v1name, v2name;
final int nameAttr;
final int selectedAttr;
final Plugin copyPlugin;
try {
// Add three vertices
v0 = wg.addVertex();
wg.getSchema().newVertex(wg, v0);
v1 = wg.addVertex();
wg.getSchema().newVertex(wg, v1);
v2 = wg.addVertex();
wg.getSchema().newVertex(wg, v2);
// Store the names of these vertices
nameAttr = VisualConcept.VertexAttribute.LABEL.get(wg);
v0name = wg.getStringValue(nameAttr, v0);
v1name = wg.getStringValue(nameAttr, v1);
v2name = wg.getStringValue(nameAttr, v2);
// Add a transaction from v0 to v1
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
// Select v0 and v2, but not v1
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v2, true);
wg.setBooleanValue(selectedAttr, v1, false);
} finally {
wg.commit();
}
// Make a composite from the selection, then select everything, and copy to a new graph
copyPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
PluginExecutor.startWith(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION).followedBy(VisualGraphPluginRegistry.SELECT_ALL).followedBy(copyPlugin).executeNow(graph);
final WritableGraph copyWg = ((CopyToNewGraphPlugin) copyPlugin).getCopy().getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(copyWg);
} finally {
copyWg.commit();
}
// Now we check there has been no effect on the composite state on the original graph
// by expanding it and then checking it is the same as the orignal graph
final WritableGraph wg2 = graph.getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(wg2);
} finally {
wg2.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there are three vertices all with their original names
assertEquals(rg.getVertexCount(), 3);
for (int i = 0; i < 3; i++) {
final int id = rg.getVertex(i);
final String name = rg.getStringValue(nameAttr, id);
if (name.equals(v0name)) {
v0 = id;
} else if (name.equals(v1name)) {
v1 = id;
} else {
v2 = id;
}
}
assertEquals(rg.getStringValue(nameAttr, v0), v0name);
assertEquals(rg.getStringValue(nameAttr, v1), v1name);
assertEquals(rg.getStringValue(nameAttr, v2), v2name);
// Assert that the two transactions exist as expected and no others
assertEquals(rg.getTransactionCount(), 1);
final int l0_1 = rg.getLink(v0, v1);
assertEquals(rg.getLinkTransactionCount(l0_1), 1);
final int t0_1 = rg.getLinkTransaction(l0_1, 0);
assertFalse(rg.getTransactionDirection(t0_1) == Graph.FLAT);
assertEquals(rg.getTransactionSourceVertex(t0_1), v0);
final int l1_2 = rg.getLink(v1, v2);
assertEquals(l1_2, Graph.NOT_FOUND);
final int l0_2 = rg.getLink(v0, v2);
assertEquals(l0_2, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
Aggregations