Search in sources :

Example 6 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph 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();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 7 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph 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");
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 8 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class BasicFindPluginNGTest 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, vxId2, 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();
    }
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 9 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class ResetStatePluginNGTest method setupGraph.

private void setupGraph() {
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    try {
        WritableGraph wg = graph.getWritableGraph("", true);
        final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(wg);
        ArrayList<Attribute> attributeList = new ArrayList<>();
        BasicFindReplaceParameters parameters = new BasicFindReplaceParameters("label name", "", GraphElementType.GRAPH.VERTEX, attributeList, true, false, false, false, false, false, false, false, false);
        FindResultsList foundResult = new FindResultsList(2, parameters, graph.getId());
        wg.setObjectValue(stateId, 0, foundResult);
        wg.commit();
    } catch (final InterruptedException ex) {
        Exceptions.printStackTrace(ex);
        Thread.currentThread().interrupt();
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) ArrayList(java.util.ArrayList) BasicFindReplaceParameters(au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters) FindResultsList(au.gov.asd.tac.constellation.views.find2.utilities.FindResultsList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 10 with WritableGraph

use of au.gov.asd.tac.constellation.graph.WritableGraph in project constellation by constellation-app.

the class AdvancedSearchPluginNGTest 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);
        dimV = VisualConcept.VertexAttribute.DIMMED.ensure(wg);
        colorV = VisualConcept.VertexAttribute.COLOR.ensure(wg);
        iconV = VisualConcept.VertexAttribute.BACKGROUND_ICON.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);
        dateTimeT = TemporalConcept.TransactionAttribute.DATETIME.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.setObjectValue(colorV, vxId1, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId1, IconManager.getIcon("Flag.Australia"));
        vxId2 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId2, false);
        wg.setStringValue(labelV, vxId2, "label name");
        wg.setStringValue(identifierV, vxId2, "identifer name");
        wg.setFloatValue(xV, vxId2, 1);
        wg.setBooleanValue(dimV, vxId2, true);
        wg.setObjectValue(colorV, vxId2, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId2, IconManager.getIcon("Flag.Australia"));
        vxId3 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId3, false);
        wg.setStringValue(labelV, vxId3, "label name");
        wg.setStringValue(identifierV, vxId3, "identifer name");
        wg.setFloatValue(xV, vxId3, 1);
        wg.setBooleanValue(dimV, vxId3, true);
        wg.setObjectValue(colorV, vxId3, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId3, IconManager.getIcon("Flag.Australia"));
        vxId4 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId4, false);
        wg.setStringValue(labelV, vxId4, "label name");
        wg.setStringValue(identifierV, vxId4, "identifer name");
        wg.setFloatValue(xV, vxId4, 1);
        wg.setBooleanValue(dimV, vxId4, true);
        wg.setObjectValue(colorV, vxId4, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId4, IconManager.getIcon("Flag.Australia"));
        vxId5UpperCase = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId5UpperCase, false);
        wg.setStringValue(labelV, vxId5UpperCase, "LABEL NAME");
        wg.setStringValue(identifierV, vxId5UpperCase, "IDENTIFIER NAME");
        wg.setFloatValue(xV, vxId5UpperCase, 1);
        wg.setBooleanValue(dimV, vxId5UpperCase, true);
        wg.setObjectValue(colorV, vxId5UpperCase, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId5UpperCase, IconManager.getIcon("Flag.Australia"));
        vxId6 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId6, false);
        wg.setStringValue(labelV, vxId6, "test");
        wg.setStringValue(identifierV, vxId6, "a vertex");
        wg.setFloatValue(xV, vxId6, 1);
        wg.setBooleanValue(dimV, vxId6, true);
        wg.setObjectValue(colorV, vxId6, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId6, IconManager.getIcon("Flag.England"));
        vxId7 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId7, false);
        wg.setStringValue(labelV, vxId7, "experiment");
        wg.setStringValue(identifierV, vxId7, "identifer name");
        wg.setFloatValue(xV, vxId7, 1);
        wg.setBooleanValue(dimV, vxId7, true);
        wg.setObjectValue(colorV, vxId7, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId7, IconManager.getIcon("Flag.England"));
        vxId8 = wg.addVertex();
        wg.setBooleanValue(selectedV, vxId8, false);
        wg.setStringValue(labelV, vxId8, "test");
        wg.setStringValue(identifierV, vxId8, "a node");
        wg.setFloatValue(xV, vxId8, 1);
        wg.setBooleanValue(dimV, vxId8, true);
        wg.setObjectValue(colorV, vxId8, ConstellationColor.BLUE);
        wg.setObjectValue(iconV, vxId8, IconManager.getIcon("Flag.Australia"));
        txId1 = wg.addTransaction(vxId1, vxId1, false);
        wg.setBooleanValue(selectedT, txId1, false);
        wg.setStringValue(labelT, txId1, "label name");
        wg.setStringValue(identiferT, txId1, "identifer name");
        wg.setFloatValue(widthT, txId1, 1);
        wg.setObjectValue(dateTimeT, txId1, testTime);
        txId2 = wg.addTransaction(vxId1, vxId2, false);
        wg.setBooleanValue(selectedT, txId2, false);
        wg.setStringValue(labelT, txId2, "label name");
        wg.setStringValue(identiferT, txId2, "identifer name");
        wg.setFloatValue(widthT, txId2, 1);
        wg.setObjectValue(dateTimeT, txId2, testTime);
        txId3 = wg.addTransaction(vxId1, vxId3, false);
        wg.setBooleanValue(selectedT, txId3, false);
        wg.setStringValue(labelT, txId3, "label name");
        wg.setStringValue(identiferT, txId3, "identifer name");
        wg.setFloatValue(widthT, txId3, 1);
        wg.setObjectValue(dateTimeT, txId3, plus1YearTestTime);
        txId4 = wg.addTransaction(vxId1, vxId4, false);
        wg.setBooleanValue(selectedT, txId4, false);
        wg.setStringValue(labelT, txId4, "label name");
        wg.setStringValue(identiferT, txId4, "identifer name");
        wg.setFloatValue(widthT, txId4, 1);
        wg.setObjectValue(dateTimeT, txId4, plus2YearTestTime);
        wg.commit();
    } catch (final InterruptedException ex) {
        Exceptions.printStackTrace(ex);
        Thread.currentThread().interrupt();
    }
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Aggregations

WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)116 Test (org.testng.annotations.Test)77 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)39 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)37 Graph (au.gov.asd.tac.constellation.graph.Graph)20 ArrayList (java.util.ArrayList)14 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)8 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)6 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 Attribute (au.gov.asd.tac.constellation.graph.Attribute)5 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)3 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)3