use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class ExtractWordsFromTextPluginNGTest method testUpdateParameters.
/**
* Test updateParameters
*/
@Test
public void testUpdateParameters() {
ExtractWordsFromTextPlugin instance = new ExtractWordsFromTextPlugin();
PluginParameters parameters = new PluginParameters();
final PluginParameter<SingleChoiceParameterValue> attributeType = SingleChoiceParameterType.build(ATTRIBUTE_PARAMETER_ID);
parameters.addParameter(attributeType);
final PluginParameter<StringParameterValue> textParameter = StringParameterType.build(WORDS_PARAMETER_ID);
textParameter.setStringValue("text");
parameters.addParameter(textParameter);
final PluginParameter<BooleanParameterValue> useRegexParameter = BooleanParameterType.build(USE_REGEX_PARAMETER_ID);
useRegexParameter.setBooleanValue(true);
parameters.addParameter(useRegexParameter);
Graph graph1 = new DualGraph(graph.getSchema(), graph);
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 3);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.ATTRIBUTE_PARAMETER_ID));
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.WORDS_PARAMETER_ID).getStringValue(), "text");
assertEquals(parameters.getParameters().get(ExtractWordsFromTextPlugin.USE_REGEX_PARAMETER_ID).getBooleanValue(), true);
assertFalse(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
parameters = instance.createParameters();
instance.updateParameters(graph1, parameters);
assertEquals(parameters.getParameters().size(), 11);
assertTrue(parameters.hasParameter(ExtractWordsFromTextPlugin.SELECTED_ONLY_PARAMETER_ID));
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class SelectAllPluginNGTest method testEdit0.
/**
* Test of edit method, of class SelectAllPlugin. select all edit with only
* attributes on graph
*/
@Test
public void testEdit0() throws Exception {
System.out.println("select all edit with nothing on graph but attributes");
// Open a new graph
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
int vxCount = 0;
int txCount = 0;
final WritableGraph wg = graph.getWritableGraph("TEST", true);
try {
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
} finally {
wg.commit();
}
// run select all plugin
PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
// Verify no extra elements are added
final ReadableGraph rg = graph.getReadableGraph();
try {
assertEquals(rg.getVertexCount(), vxCount);
assertEquals(rg.getTransactionCount(), txCount);
} finally {
rg.close();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class SelectAllPluginNGTest method testEdit4.
/**
* Test of edit method, of class SelectAllPlugin. select all edit with a
* graph that has no selected element via its schema, but contains elements.
*
* Should throw a pluginexception
*/
@Test(expectedExceptions = PluginException.class)
public void testEdit4() throws Exception {
System.out.println("select all edit with no selected attribute on graph, but with elements");
// Open a new graph
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(BareSchemaFactory.NAME).createSchema());
int vxCount = 0;
int txCount = 0;
final WritableGraph wg = graph.getWritableGraph("TEST", true);
try {
// Add vertices
vxId1 = wg.addVertex();
vxId2 = wg.addVertex();
// Add transactions
txId1 = wg.addTransaction(vxId1, vxId2, true);
txId2 = wg.addTransaction(vxId2, vxId1, false);
vxCount = wg.getVertexCount();
txCount = wg.getTransactionCount();
// ensure both values are stored
assertEquals(vxCount, 2);
assertEquals(txCount, 2);
} finally {
wg.commit();
}
// run select all plugin
PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class SelectAllPluginNGTest method testEdit2.
/**
* Test of edit method, of class SelectAllPlugin. select all edit with both
* vx and tx on graph
*/
@Test
public void testEdit2() throws Exception {
System.out.println("select all edit with vx and tx on graph");
// Open a new graph
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
int vxCount = 0;
int txCount = 0;
final WritableGraph wg = graph.getWritableGraph("TEST", true);
try {
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
// Add vertices
vxId1 = wg.addVertex();
vxId2 = wg.addVertex();
// Add transactions
txId1 = wg.addTransaction(vxId1, vxId2, true);
txId2 = wg.addTransaction(vxId2, vxId1, false);
// check default value is unselected
assertFalse(wg.getBooleanValue(selectedV, vxId1));
assertFalse(wg.getBooleanValue(selectedV, vxId2));
assertFalse(wg.getBooleanValue(selectedV, txId1));
assertFalse(wg.getBooleanValue(selectedV, txId2));
vxCount = wg.getVertexCount();
txCount = wg.getTransactionCount();
} finally {
wg.commit();
}
// run select all plugin
PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
// Verify both selected and same amount of vx and tx are present
final ReadableGraph rg = graph.getReadableGraph();
try {
assertTrue(rg.getBooleanValue(selectedV, vxId1));
assertTrue(rg.getBooleanValue(selectedV, vxId2));
assertTrue(rg.getBooleanValue(selectedV, txId1));
assertTrue(rg.getBooleanValue(selectedV, txId2));
assertEquals(rg.getVertexCount(), vxCount);
assertEquals(rg.getTransactionCount(), txCount);
} finally {
rg.close();
}
// rerun plugin to ensure values are not only toggled, but are set explicitly as selected
// run select all plugin
PluginExecution.withPlugin(new SelectAllPlugin()).executeNow(graph);
// Verify both selected and same amount of vx and tx are present
final ReadableGraph rg2 = graph.getReadableGraph();
try {
assertTrue(rg2.getBooleanValue(selectedV, vxId1));
assertTrue(rg2.getBooleanValue(selectedV, vxId2));
assertTrue(rg.getBooleanValue(selectedV, txId1));
assertTrue(rg.getBooleanValue(selectedV, txId2));
assertEquals(rg2.getVertexCount(), vxCount);
assertEquals(rg.getTransactionCount(), txCount);
} finally {
rg2.close();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class RecordStoreQueryPluginNGTest method testEdit.
/**
* Test of edit method, of class RecordStoreQueryPlugin.
*/
@Test
public void testEdit() throws InterruptedException, PluginException {
System.out.println("edit");
final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
// only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
final Graph graph = new DualGraph(schema);
final PluginInteraction interaction = null;
final PluginParameters parameters = null;
ReadableGraph rg = graph.getReadableGraph();
try {
instance.read(rg, interaction, parameters);
instance.query(interaction, parameters);
} finally {
rg.release();
}
GraphRecordStore query;
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getAll(rg, false, false);
} finally {
rg.release();
}
final WritableGraph wg = graph.getWritableGraph("", true);
try {
VisualConcept.VertexAttribute.X.ensure(wg);
VisualConcept.VertexAttribute.Y.ensure(wg);
VisualConcept.VertexAttribute.Z.ensure(wg);
VisualConcept.GraphAttribute.CAMERA.ensure(wg);
instance.edit(wg, interaction, parameters);
} finally {
wg.commit();
}
rg = graph.getReadableGraph();
try {
query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
} finally {
rg.release();
}
// verify nothing has moved
query.reset();
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
query.next();
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
Aggregations