use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class GraphAttributePluginNGTest method setupGraph.
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graphMap.put(graph.getId(), graph);
graphMap.put(graph2.getId(), graph2);
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
xV = VisualConcept.VertexAttribute.X.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
vxId1 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId1, false);
wg.setStringValue(labelV, vxId1, "label name");
wg.setStringValue(identifierV, vxId1, "identifer name");
wg.setIntValue(xV, vxId1, 1);
vxId2 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId2, false);
wg.setStringValue(labelV, vxId2, "label name");
wg.setStringValue(identifierV, vxId2, "identifer name");
wg.setIntValue(xV, vxId1, 1);
vxId3 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId3, false);
wg.setStringValue(labelV, vxId3, "label name");
wg.setStringValue(identifierV, vxId3, "identifer name");
wg.setIntValue(xV, vxId3, 1);
vxId4 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId4, false);
wg.setStringValue(labelV, vxId4, "label name");
wg.setStringValue(identifierV, vxId4, "identifer name");
wg.setIntValue(xV, vxId4, 1);
txId1 = wg.addTransaction(vxId1, vxId1, false);
wg.setBooleanValue(selectedT, txId1, false);
wg.setStringValue(labelT, txId1, "label name");
wg.setStringValue(identiferT, txId1, "identifer name");
wg.setIntValue(widthT, txId1, 1);
txId2 = wg.addTransaction(vxId1, vxId2, false);
wg.setBooleanValue(selectedT, txId2, false);
wg.setStringValue(labelT, txId2, "label name");
wg.setStringValue(identiferT, txId2, "identifer name");
wg.setIntValue(widthT, txId2, 1);
txId3 = wg.addTransaction(vxId1, vxId3, false);
wg.setBooleanValue(selectedT, txId3, false);
wg.setStringValue(labelT, txId3, "label name");
wg.setStringValue(identiferT, txId3, "identifer name");
wg.setIntValue(widthT, txId3, 1);
txId4 = wg.addTransaction(vxId1, vxId4, false);
wg.setBooleanValue(selectedT, txId4, false);
wg.setStringValue(labelT, txId4, "label name");
wg.setStringValue(identiferT, txId4, "identifer name");
wg.setIntValue(widthT, txId4, 1);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class GraphAttributePluginNGTest method testRead.
/**
* Test of read method, of class GraphAttributePlugin.
*/
@Test
public void testRead() throws Exception {
System.out.println("read");
setupGraph();
PluginInteraction interaction = mock(PluginInteraction.class);
PluginParameters pluginParameters = mock(PluginParameters.class);
WritableGraph wg = graph.getWritableGraph("", true);
GraphElementType type = GraphElementType.VERTEX;
GraphAttributePlugin graphAttributePlugin = new GraphAttributePlugin(type, attributeList, amc);
int selectedInt = wg.getAttribute(type, 0);
Attribute selectedAttribute = new GraphAttribute(wg, selectedInt);
int labelInt = wg.getAttribute(type, 1);
Attribute labelAttribute = new GraphAttribute(wg, labelInt);
int identifierInt = wg.getAttribute(type, 2);
Attribute identifierAttribute = new GraphAttribute(wg, identifierInt);
int xInt = wg.getAttribute(type, 3);
Attribute xAttribute = new GraphAttribute(wg, xInt);
List<Attribute> expectedList = new ArrayList<>();
expectedList.add(selectedAttribute);
expectedList.add(labelAttribute);
expectedList.add(identifierAttribute);
expectedList.add(xAttribute);
/**
* The attributeList should contain all the avalible attributes of the
* given type that exist on the graph. It should contain the selected,
* label, identifier and x attributes as they are the vertex attributes
* the graph has been set with.
*/
graphAttributePlugin.read(wg, interaction, pluginParameters);
assertEquals(attributeList, expectedList);
wg.commit();
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ReplacePluginNGTest method testEdit.
/**
* Test of edit method, of class ReplacePlugin.
*/
@Test
public void testEdit() throws Exception {
System.out.println("edit");
setupGraph();
attributeList.addAll(getAttributes());
ReplacePlugin replacePlugin = new ReplacePlugin(parameters, true, false);
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
ReadableGraph rg = graph.getReadableGraph();
/**
* Testing replace all elements with the label name "label name" with
* "replaced", Should replace vxId1,2,3,4
*/
assertEquals(rg.getStringValue(labelV, vxId1), "replaced");
assertEquals(rg.getStringValue(labelV, vxId2), "replaced");
assertEquals(rg.getStringValue(labelV, vxId3), "replaced");
assertEquals(rg.getStringValue(labelV, vxId4), "replaced");
rg.close();
/**
* Testing replacing next for the word "replaced" and replacing it with
* "next". vxId1 label should now be "next"
*/
replacePlugin = new ReplacePlugin(parametersReplaceNext, false, true);
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
rg = graph.getReadableGraph();
assertEquals(rg.getStringValue(labelV, vxId1), "next");
assertEquals(rg.getStringValue(labelV, vxId2), "replaced");
assertEquals(rg.getStringValue(labelV, vxId3), "replaced");
assertEquals(rg.getStringValue(labelV, vxId4), "replaced");
rg.close();
/**
* Testing the same as above. vxId2 label should now be "next"
*/
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
rg = graph.getReadableGraph();
assertEquals(rg.getStringValue(labelV, vxId1), "next");
assertEquals(rg.getStringValue(labelV, vxId2), "next");
assertEquals(rg.getStringValue(labelV, vxId3), "replaced");
assertEquals(rg.getStringValue(labelV, vxId4), "replaced");
rg.close();
/**
* Replace anything with "ne*" in regEx format with "test" vxId1 and 2
* labels should convert from "next" to "testxt"
*/
replacePlugin = new ReplacePlugin(parametersReplaceRegEx, true, false);
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
rg = graph.getReadableGraph();
assertEquals(rg.getStringValue(labelV, vxId1), "testxt");
assertEquals(rg.getStringValue(labelV, vxId2), "testxt");
assertEquals(rg.getStringValue(labelV, vxId3), "replaced");
assertEquals(rg.getStringValue(labelV, vxId4), "replaced");
rg.close();
/**
* Replacing the word "lowercase" ignoring the if lower or upper case to
* the word "test". vxId1 and 2 should be changed to "test"
*/
WritableGraph wg = graph.getWritableGraph("", true);
wg.setStringValue(labelV, vxId1, "lowercase");
wg.setStringValue(labelV, vxId2, "LOWERCASE");
wg.setStringValue(labelV, vxId3, "test");
wg.setStringValue(labelV, vxId4, "test");
wg.commit();
replacePlugin = new ReplacePlugin(parametersReplaceIgnoreCase, true, false);
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
rg = graph.getReadableGraph();
assertEquals(rg.getStringValue(labelV, vxId1), "test");
assertEquals(rg.getStringValue(labelV, vxId2), "test");
assertEquals(rg.getStringValue(labelV, vxId3), "test");
assertEquals(rg.getStringValue(labelV, vxId4), "test");
rg.close();
/**
* Testing replacing the word "test" with the word "replaced" only in
* elements that are selected. vxId1 and 2 should change to "replaced"
*/
wg = graph.getWritableGraph("", true);
wg.setBooleanValue(selectedV, vxId1, true);
wg.setBooleanValue(selectedV, vxId2, true);
wg.setBooleanValue(selectedV, vxId3, false);
wg.setBooleanValue(selectedV, vxId4, false);
wg.commit();
replacePlugin = new ReplacePlugin(parametersReplaceInSelected, true, false);
PluginExecution.withPlugin(replacePlugin).executeNow(graph);
rg = graph.getReadableGraph();
assertEquals(rg.getStringValue(labelV, vxId1), "replaced");
assertEquals(rg.getStringValue(labelV, vxId2), "replaced");
assertEquals(rg.getStringValue(labelV, vxId3), "test");
assertEquals(rg.getStringValue(labelV, vxId4), "test");
rg.close();
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ReplacePluginNGTest method setupGraph.
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graphMap.put(graph.getId(), graph);
graphMap.put(graph2.getId(), graph2);
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
xV = VisualConcept.VertexAttribute.X.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
vxId1 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId1, false);
wg.setStringValue(labelV, vxId1, "label name");
wg.setStringValue(identifierV, vxId1, "identifer name");
wg.setIntValue(xV, vxId1, 1);
vxId2 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId2, false);
wg.setStringValue(labelV, vxId2, "label name");
wg.setStringValue(identifierV, vxId2, "identifer name");
wg.setIntValue(xV, vxId1, 1);
vxId3 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId3, false);
wg.setStringValue(labelV, vxId3, "label name");
wg.setStringValue(identifierV, vxId3, "identifer name");
wg.setIntValue(xV, vxId3, 1);
vxId4 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId4, false);
wg.setStringValue(labelV, vxId4, "label name");
wg.setStringValue(identifierV, vxId4, "identifer name");
wg.setIntValue(xV, vxId4, 1);
vxId5UpperCase = wg.addVertex();
wg.setBooleanValue(selectedV, vxId5UpperCase, false);
wg.setStringValue(labelV, vxId5UpperCase, "LABEL NAME");
wg.setStringValue(identifierV, vxId5UpperCase, "IDENTIFIER NAME");
wg.setIntValue(xV, vxId5UpperCase, 1);
vxId6 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId6, false);
wg.setStringValue(labelV, vxId6, "test");
wg.setStringValue(identifierV, vxId6, "a vertex");
wg.setIntValue(xV, vxId6, 1);
vxId7 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId7, false);
wg.setStringValue(labelV, vxId7, "experiment");
wg.setStringValue(identifierV, vxId7, "a vertex");
wg.setIntValue(xV, vxId7, 1);
vxId8 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId8, false);
wg.setStringValue(labelV, vxId8, "test");
wg.setStringValue(identifierV, vxId8, "a node");
wg.setIntValue(xV, vxId8, 1);
txId1 = wg.addTransaction(vxId1, vxId1, false);
wg.setBooleanValue(selectedT, txId1, false);
wg.setStringValue(labelT, txId1, "label name");
wg.setStringValue(identiferT, txId1, "identifer name");
wg.setIntValue(widthT, txId1, 1);
txId2 = wg.addTransaction(vxId1, vxId2, false);
wg.setBooleanValue(selectedT, txId2, false);
wg.setStringValue(labelT, txId2, "label name");
wg.setStringValue(identiferT, txId2, "identifer name");
wg.setIntValue(widthT, txId2, 1);
txId3 = wg.addTransaction(vxId1, vxId3, false);
wg.setBooleanValue(selectedT, txId3, false);
wg.setStringValue(labelT, txId3, "label name");
wg.setStringValue(identiferT, txId3, "identifer name");
wg.setIntValue(widthT, txId3, 1);
txId4 = wg.addTransaction(vxId1, vxId4, false);
wg.setBooleanValue(selectedT, txId4, false);
wg.setStringValue(labelT, txId4, "label name");
wg.setStringValue(identiferT, txId4, "identifer name");
wg.setIntValue(widthT, txId4, 1);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ModCountNGTest method setTransactionDestinationToSourceModCounts.
/**
* Tests that the mod counts on the two graphs in a DualGraph match after a
* transactions is added between two vertices and then its destination
* vertex is set to its source vertex to create a loop.
*/
@Test
public void setTransactionDestinationToSourceModCounts() {
final DualGraph g = new DualGraph(null);
try {
long modCount;
WritableGraph wg = g.getWritableGraph("", true);
int vertex0, vertex1;
int trans;
try {
vertex0 = wg.addVertex();
vertex1 = wg.addVertex();
trans = wg.addTransaction(vertex0, vertex1, true);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 2);
assertEquals(wg.getTransactionCount(), 1);
assertEquals(wg.getTransactionSourceVertex(trans), vertex0);
assertEquals(wg.getTransactionDestinationVertex(trans), vertex1);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
wg.setTransactionDestinationVertex(trans, vertex0);
modCount = wg.getGlobalModificationCounter();
} finally {
wg.commit();
}
wg = g.getWritableGraph("", true);
try {
assertEquals(wg.getVertexCount(), 2);
assertEquals(wg.getTransactionCount(), 1);
assertEquals(wg.getTransactionSourceVertex(trans), vertex0);
assertEquals(wg.getTransactionDestinationVertex(trans), vertex0);
assertEquals(modCount, wg.getGlobalModificationCounter());
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
assertTrue(ex.toString(), false);
}
}
Aggregations