use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class ReplaceTabNGTest 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);
/**
* Get the label and the identifier vertex attributes and add them
* to the attributes list
*/
GraphElementType elementType = GraphElementType.VERTEX;
// The label attribute
int attributeInt = wg.getAttribute(elementType, 1);
labelAttributeV = new GraphAttribute(wg, attributeInt);
replaceTab.attributes.add(labelAttributeV);
// The identifier attribute
attributeInt = wg.getAttribute(elementType, 2);
identifierAttributeV = new GraphAttribute(wg, attributeInt);
replaceTab.attributes.add(identifierAttributeV);
elementType = GraphElementType.TRANSACTION;
attributeInt = wg.getAttribute(elementType, 1);
labelAttributeT = new GraphAttribute(wg, attributeInt);
attributeInt = wg.getAttribute(elementType, 2);
identifierAttributeT = new GraphAttribute(wg, attributeInt);
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 BooleanCriteriaPanelNGTest 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 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);
dimV = VisualConcept.VertexAttribute.DIMMED.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.setFloatValue(xV, vxId1, 1);
wg.setBooleanValue(dimV, vxId1, true);
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 FindViewControllerNGTest method setupGraph.
/**
* Set up a graph with two vertices and two transactions on layer 1.
*/
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);
int[] vertexList = { vxId1, vxId2, vxId3, vxId4 };
for (int vertex : vertexList) {
vertex = wg.addVertex();
wg.setBooleanValue(selectedV, vertex, false);
wg.setStringValue(labelV, vertex, "label name");
wg.setStringValue(identifierV, vertex, "identifer name");
wg.setIntValue(xV, vertex, 1);
}
int[] transactionList = { txId1, txId2, txId3, txId4 };
int count = 0;
for (int transaction : transactionList) {
int vertex = vertexList[count];
transaction = wg.addTransaction(vxId1, vertex, false);
wg.setBooleanValue(selectedT, transaction, false);
wg.setStringValue(labelT, transaction, "label name");
wg.setStringValue(identiferT, transaction, "identifer name");
wg.setIntValue(widthT, transaction, 1);
if (count != vertexList.length) {
count++;
}
}
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 FindViewControllerNGTest method testReplaceMatchingElements.
// // Populate the attribute list with the attributes of the given type
// for (Graph graph : gm.getAllGraphs().values()) {
// try {
// System.out.println("in for graph try");
//
// WritableGraph wg = graph.getWritableGraph("", true);
// for (int i = 0; i < stringAttributeList.size(); i++) {
// int attributeInt = wg.getAttribute(type, stringAttributeList.get(i));
// attributes.add(new GraphAttribute(wg, attributeInt));
// System.out.println(attributes.get(i).getName() + " = attribute name");
//
// }
//
// instance.updateBasicFindParameters(parameters);
//
// System.out.println("before method call");
//
// instance.retriveMatchingElements(true, false);
//
// System.out.println("before assert");
// System.out.println(wg.getStringValue(labelV, vxId1));
//
// System.out.println(wg.getBooleanValue(selectedV, vxId1));
// assertEquals(wg.getBooleanValue(selectedV, vxId1), true);
// System.out.println("after equals");
//
// wg.commit();
//
// } catch (final InterruptedException ex) {
// Exceptions.printStackTrace(ex);
// Thread.currentThread().interrupt();
// }
//
// }
//
// }
/**
* Test of replaceMatchingElements method, of class FindViewController.
*/
@Test
public void testReplaceMatchingElements() {
System.out.println("replaceMatchingElements");
/**
* Set up the graph with 4 vertexs, 4 transactions, 3 vertex attributes
* (2 of type string), 3 transaction attributes (2 of type string)
*/
setupGraph();
/**
* Create a mock of the top component, get an instance of the
* controller, create a mock of the graph manager, when getAllGraphs is
* called return the graphMap created in this class
*/
final FindViewTopComponent findViewTopComponent = mock(FindViewTopComponent.class);
FindViewController instance = FindViewController.getDefault().init(findViewTopComponent);
final GraphManager gm = Mockito.mock(GraphManager.class);
when(gm.getAllGraphs()).thenReturn(graphMap);
when(gm.getActiveGraph()).thenReturn(graph);
System.out.println("before try");
try (MockedStatic<GraphManager> mockedStatic = Mockito.mockStatic(GraphManager.class)) {
mockedStatic.when(() -> GraphManager.getDefault()).thenReturn(gm);
System.out.println("in try");
try (MockedStatic<PluginExecution> mockedStaticPlugin = Mockito.mockStatic(PluginExecution.class)) {
PluginExecution pluginExecution = mock(PluginExecution.class);
/**
* The first test should execute the plugin once on graph as the
* parameters are not set to look at all graphs
*/
when(pluginExecution.executeLater(Mockito.eq(graph))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution).executeLater(Mockito.eq(graph));
/**
* Set the parameters to find in all graphs and repeat the same
* process. The plugin should be executed on graph a second
* time, and should be executed on graph2 for the first time.
*/
instance.updateBasicReplaceParameters(parametersAllGraphs);
when(pluginExecution.executeLater(Mockito.any(Graph.class))).thenReturn(null);
mockedStaticPlugin.when(() -> PluginExecution.withPlugin(Mockito.any(Plugin.class))).thenReturn(pluginExecution);
instance.replaceMatchingElements(true, false);
verify(pluginExecution, times(2)).executeLater(Mockito.eq(graph));
verify(pluginExecution).executeLater(Mockito.eq(graph2));
}
}
}
use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.
the class StringCriteriaPanelNGTest 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.setFloatValue(xV, vxId1, 1);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
Aggregations