use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method destroyExpandedCompositeTest.
@Test
public void destroyExpandedCompositeTest() 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 int compositeAttr;
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 transactions from v0 to v1, and from v1 to v2
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
final int t1_2 = wg.addTransaction(v1, v2, true);
wg.getSchema().newTransaction(wg, t1_2);
// Select v0 and v1, but not v2
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v1, true);
wg.setBooleanValue(selectedAttr, v2, false);
// Make a composite from the selection, exapnd all composites, then destroy all composites
PluginExecutor.startWith(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).followedBy(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg);
compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
CompositeUtilities.destroyAllComposites(wg);
} finally {
wg.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there are three vertices, all with null composite states and 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);
assertNull(rg.getObjectValue(compositeAttr, v0));
assertEquals(rg.getStringValue(nameAttr, v1), v1name);
assertNull(rg.getObjectValue(compositeAttr, v1));
assertEquals(rg.getStringValue(nameAttr, v2), v2name);
assertNull(rg.getObjectValue(compositeAttr, v2));
// Assert that the two transactions exist as expected and no others
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(rg.getLinkTransactionCount(l1_2), 1);
final int t1_2 = rg.getLinkTransaction(l1_2, 0);
assertFalse(rg.getTransactionDirection(t1_2) == Graph.FLAT);
assertEquals(rg.getTransactionSourceVertex(t1_2), v1);
final int l0_2 = rg.getLink(v0, v2);
assertEquals(l0_2, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method makeDeleteTransactionExpandTest.
@Test
public void makeDeleteTransactionExpandTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
wg.getSchema().newGraph(wg);
final int v0, v1, v2;
final String v0name, v1name, v2name;
final int nameAttr;
final int selectedAttr;
final int compositeAttr;
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 transactions from v0 to v1, and from v1 to v2
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
final int t1_2 = wg.addTransaction(v1, v2, true);
wg.getSchema().newTransaction(wg, t1_2);
// Select v0 and v1, but not v2
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v1, true);
wg.setBooleanValue(selectedAttr, v2, false);
// Make a composite from the selection
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
// Delete the transaction between the composite and the non-composite then expand all composites
final int compositeNode = wg.getVertex(0) != v2 ? wg.getVertex(0) : wg.getVertex(1);
final int compositeLink = wg.getLink(compositeNode, v2);
final int compositeTransaction = wg.getLinkTransaction(compositeLink, 0);
wg.removeTransaction(compositeTransaction);
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg);
} finally {
wg.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there are three nodes, that v2 is the same with a null composite state,
// and that the other two have expanded composite states
assertEquals(rg.getVertexCount(), 3);
assertEquals(rg.getStringValue(nameAttr, v2), v2name);
assertNull(rg.getObjectValue(compositeAttr, v2));
final int v2pos = rg.getVertexPosition(v2);
final int comp0 = v2pos != 0 ? rg.getVertex(0) : rg.getVertex(2);
final int comp1 = v2pos != 1 ? rg.getVertex(1) : rg.getVertex(2);
final int expanded_v0 = rg.getStringValue(nameAttr, comp0).equals(v0name) ? comp0 : comp1;
final int expanded_v1 = expanded_v0 == comp0 ? comp1 : comp0;
final CompositeNodeState compositeState0 = (CompositeNodeState) rg.getObjectValue(compositeAttr, expanded_v0);
final CompositeNodeState compositeState1 = (CompositeNodeState) rg.getObjectValue(compositeAttr, expanded_v1);
assertNotNull(compositeState0);
assertEquals(compositeState0.getNumberOfNodes(), 2);
assertTrue(compositeState0.comprisesAComposite());
assertEquals(rg.getStringValue(nameAttr, expanded_v0), v0name);
assertNotNull(compositeState1);
assertEquals(compositeState1.getNumberOfNodes(), 2);
assertTrue(compositeState1.comprisesAComposite());
assertEquals(rg.getStringValue(nameAttr, expanded_v1), v1name);
// Assert that only the transaction between v0 and v1 exists and no others.
assertEquals(rg.getTransactionCount(), 1);
final int l0_1 = rg.getLink(expanded_v0, expanded_v1);
assertEquals(rg.getLinkTransactionCount(l0_1), 1);
final int t0_1 = rg.getLinkTransaction(l0_1, 0);
assertEquals(rg.getTransactionSourceVertex(t0_1), expanded_v0);
assertFalse(rg.getTransactionDirection(t0_1) == Graph.FLAT);
final int l0_2 = rg.getLink(expanded_v0, v2);
assertEquals(l0_2, Graph.NOT_FOUND);
final int l1_2 = rg.getLink(expanded_v1, v2);
assertEquals(l1_2, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method expandCompositesNoCompositesTest.
@Test
public void expandCompositesNoCompositesTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
// Add two vertices then expand all composites
try {
wg.addVertex();
wg.addVertex();
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(wg);
} finally {
wg.commit();
}
// Assert that nothing happened to the graph since there were no composites
ReadableGraph rg = graph.getReadableGraph();
try {
final int compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(rg);
assertEquals(rg.getVertexCount(), 2);
assertEquals(compositeAttr, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method compositeTwoCompositesTest.
@Test
public void compositeTwoCompositesTest() throws InterruptedException, PluginException {
final WritableGraph wg = graph.getWritableGraph("test", true);
wg.getSchema().newGraph(wg);
int v0, v1, v2, v3;
final String v0name, v1name, v2name, v3name;
final int nameAttr;
final int selectedAttr;
final int compositeAttr;
try {
// Add four 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);
v3 = wg.addVertex();
wg.getSchema().newVertex(wg, v3);
// 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);
v3name = wg.getStringValue(nameAttr, v3);
// Add transactions from v0 to v1, and from v1 to v2
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
final int t1_2 = wg.addTransaction(v1, v2, true);
wg.getSchema().newTransaction(wg, t1_2);
// Select v0 and v1, but not v2 or v3
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v1, true);
wg.setBooleanValue(selectedAttr, v2, false);
wg.setBooleanValue(selectedAttr, v3, false);
// Make a composite from the selection then deselect all
PluginExecutor.startWith(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).followedBy(PluginRegistry.get(DeselectAllPlugin.class.getName())).executeNow(wg);
compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
// Select v2 and v3
wg.setBooleanValue(selectedAttr, v2, true);
wg.setBooleanValue(selectedAttr, v3, true);
// Make a composite from the selection
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
// Select all and composite the two composites
PluginExecutor.startWith(VisualGraphPluginRegistry.SELECT_ALL).followedBy(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
} finally {
wg.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there is one vertex that is a composite node containing four nodes,
assertEquals(rg.getVertexCount(), 1);
final int compositeNode = rg.getVertex(0);
final CompositeNodeState compositeState = (CompositeNodeState) rg.getObjectValue(compositeAttr, compositeNode);
assertNotNull(compositeState);
assertEquals(compositeState.getNumberOfNodes(), 4);
assertTrue(compositeState.isComposite());
// Assert that there are no transactions on the graph
assertEquals(rg.getTransactionCount(), 0);
} finally {
rg.release();
}
final WritableGraph wg2 = graph.getWritableGraph("test", true);
try {
// Expand all composites
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg2);
} finally {
wg2.commit();
}
final ReadableGraph rg2 = graph.getReadableGraph();
try {
// Assert that the original four vertices exist in expanded composite form
assertEquals(rg2.getVertexCount(), 4);
v0 = Graph.NOT_FOUND;
v1 = Graph.NOT_FOUND;
v2 = Graph.NOT_FOUND;
v3 = Graph.NOT_FOUND;
for (int i = 0; i < 4; 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 if (name.equals(v2name)) {
v2 = id;
} else {
v3 = id;
}
}
assertEquals(rg2.getStringValue(nameAttr, v0), v0name);
final CompositeNodeState compositeState0 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v0);
assertNotNull(compositeState0);
assertEquals(compositeState0.getNumberOfNodes(), 4);
assertTrue(compositeState0.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v1), v1name);
final CompositeNodeState compositeState1 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v1);
assertNotNull(compositeState1);
assertEquals(compositeState1.getNumberOfNodes(), 4);
assertTrue(compositeState1.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v2), v2name);
final CompositeNodeState compositeState2 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v2);
assertNotNull(compositeState2);
assertEquals(compositeState2.getNumberOfNodes(), 4);
assertTrue(compositeState2.comprisesAComposite());
assertEquals(rg2.getStringValue(nameAttr, v3), v3name);
final CompositeNodeState compositeState3 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v3);
assertNotNull(compositeState3);
assertEquals(compositeState3.getNumberOfNodes(), 4);
assertTrue(compositeState3.comprisesAComposite());
// assert that the original transactions exist and none others
assertEquals(rg.getTransactionCount(), 2);
final int l0_1 = rg2.getLink(v0, v1);
assertEquals(rg2.getLinkTransactionCount(l0_1), 1);
final int t0_1 = rg2.getLinkTransaction(l0_1, 0);
assertFalse(rg2.getTransactionDirection(t0_1) == Graph.FLAT);
assertEquals(rg2.getTransactionSourceVertex(t0_1), v0);
final int l1_2 = rg2.getLink(v1, v2);
assertEquals(rg2.getLinkTransactionCount(l1_2), 1);
final int t1_2 = rg2.getLinkTransaction(l1_2, 0);
assertFalse(rg2.getTransactionDirection(t1_2) == Graph.FLAT);
assertEquals(rg2.getTransactionSourceVertex(t1_2), v1);
} finally {
rg2.release();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class CompositesNGTest method destroyContractedCompositeTest.
@Test
public void destroyContractedCompositeTest() 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 int compositeAttr;
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 transactions from v0 to v1, and from v1 to v2
final int t0_1 = wg.addTransaction(v0, v1, true);
wg.getSchema().newTransaction(wg, t0_1);
final int t1_2 = wg.addTransaction(v1, v2, true);
wg.getSchema().newTransaction(wg, t1_2);
// Select v0 and v1, but not v2
selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
wg.setBooleanValue(selectedAttr, v0, true);
wg.setBooleanValue(selectedAttr, v1, true);
wg.setBooleanValue(selectedAttr, v2, false);
// Make a composite from the selection then destroy all composites
PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
CompositeUtilities.destroyAllComposites(wg);
} finally {
wg.commit();
}
final ReadableGraph rg = graph.getReadableGraph();
try {
// Assert that there are three vertices, all with null composite states and their original names
assertEquals(rg.getVertexCount(), 3);
v0 = Graph.NOT_FOUND;
v1 = Graph.NOT_FOUND;
v2 = Graph.NOT_FOUND;
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);
assertNull(rg.getObjectValue(compositeAttr, v0));
assertEquals(rg.getStringValue(nameAttr, v1), v1name);
assertNull(rg.getObjectValue(compositeAttr, v1));
assertEquals(rg.getStringValue(nameAttr, v2), v2name);
assertNull(rg.getObjectValue(compositeAttr, v2));
// Assert that the two transactions exist as expected and no others
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(rg.getLinkTransactionCount(l1_2), 1);
final int t1_2 = rg.getLinkTransaction(l1_2, 0);
assertFalse(rg.getTransactionDirection(t1_2) == Graph.FLAT);
assertEquals(rg.getTransactionSourceVertex(t1_2), v1);
final int l0_2 = rg.getLink(v0, v2);
assertEquals(l0_2, Graph.NOT_FOUND);
} finally {
rg.release();
}
}
Aggregations