Search in sources :

Example 16 with WritableGraph

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

the class CompareGraphPlugin method createComparisonGraph.

/**
 * Create the comparison graph using the original graph as the starting
 * point and add the result record store
 *
 * @param originalGraph
 * @param changes
 * @param initializeWithSchema
 * @param completeWithSchema
 * @return
 * @throws InterruptedException
 */
protected Graph createComparisonGraph(final Graph originalGraph, final GraphRecordStore changes) throws InterruptedException {
    Graph copy;
    final ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        try {
            final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
            final PluginParameters copyParams = copyGraphPlugin.createParameters();
            copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
            PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow(rg);
            copy = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
        } catch (final PluginException ex) {
            copy = null;
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
        if (copy == null) {
            // The copy failed, drop out now.
            return null;
        }
    } finally {
        rg.release();
    }
    final List<String> vertexIdAttributes = new ArrayList<>();
    vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
    final WritableGraph wgcopy = copy.getWritableGraph("Add changes", true);
    try {
        changes.reset();
        GraphRecordStoreUtilities.addRecordStoreToGraph(wgcopy, changes, false, false, null);
        final int vertexColorReferenceAttribute = VisualConcept.GraphAttribute.NODE_COLOR_REFERENCE.ensure(wgcopy);
        final int transactionColorReferenceAttribute = VisualConcept.GraphAttribute.TRANSACTION_COLOR_REFERENCE.ensure(wgcopy);
        wgcopy.setObjectValue(vertexColorReferenceAttribute, 0, VisualConcept.VertexAttribute.OVERLAY_COLOR.getName());
        wgcopy.setObjectValue(transactionColorReferenceAttribute, 0, VisualConcept.TransactionAttribute.OVERLAY_COLOR.getName());
    } finally {
        wgcopy.commit();
    }
    // only returning this so that this method can be tested
    return copy;
}
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) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin)

Example 17 with WritableGraph

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

the class GraphSavingNGTest method setUpMethod.

@BeforeMethod
public void setUpMethod() throws Exception {
    graph = new DualGraph(null);
    WritableGraph wg = graph.getWritableGraph("add", true);
    try {
        attrX = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0.0, null);
        if (attrX == Graph.NOT_FOUND) {
            fail();
        }
        attrY = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "y", "y", 0.0, null);
        if (attrY == Graph.NOT_FOUND) {
            fail();
        }
        attrZ = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "z", "z", 0.0, null);
        if (attrZ == Graph.NOT_FOUND) {
            fail();
        }
        vNameAttr = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
        if (vNameAttr == Graph.NOT_FOUND) {
            fail();
        }
        tNameAttr = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
        if (tNameAttr == Graph.NOT_FOUND) {
            fail();
        }
        vSelAttr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
        if (vSelAttr == Graph.NOT_FOUND) {
            fail();
        }
        tSelAttr = wg.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
        if (tSelAttr == Graph.NOT_FOUND) {
            fail();
        }
        vxId1 = wg.addVertex();
        wg.setFloatValue(attrX, vxId1, 1.0f);
        wg.setFloatValue(attrY, vxId1, 1.1f);
        wg.setBooleanValue(vSelAttr, vxId1, false);
        wg.setStringValue(vNameAttr, vxId1, "name1");
        vxId2 = wg.addVertex();
        wg.setFloatValue(attrX, vxId2, 2.0f);
        wg.setFloatValue(attrY, vxId2, 2.2f);
        wg.setBooleanValue(vSelAttr, vxId2, true);
        wg.setStringValue(vNameAttr, vxId2, "name2");
        vxId3 = wg.addVertex();
        wg.setFloatValue(attrX, vxId3, 3.0f);
        wg.setFloatValue(attrY, vxId3, 3.3f);
        wg.setBooleanValue(vSelAttr, vxId3, false);
        wg.setStringValue(vNameAttr, vxId3, "name3");
        vxId4 = wg.addVertex();
        wg.setFloatValue(attrX, vxId4, 4.0f);
        wg.setFloatValue(attrY, vxId4, 4.4f);
        wg.setBooleanValue(vSelAttr, vxId4, true);
        wg.setStringValue(vNameAttr, vxId4, "name4");
        vxId5 = wg.addVertex();
        wg.setFloatValue(attrX, vxId5, 5.0f);
        wg.setFloatValue(attrY, vxId5, 5.5f);
        wg.setBooleanValue(vSelAttr, vxId5, false);
        wg.setStringValue(vNameAttr, vxId5, "name5");
        vxId6 = wg.addVertex();
        wg.setFloatValue(attrX, vxId6, 6.0f);
        wg.setFloatValue(attrY, vxId6, 6.60f);
        wg.setBooleanValue(vSelAttr, vxId6, true);
        wg.setStringValue(vNameAttr, vxId6, "name6");
        vxId7 = wg.addVertex();
        wg.setFloatValue(attrX, vxId7, 7.0f);
        wg.setFloatValue(attrY, vxId7, 7.7f);
        wg.setBooleanValue(vSelAttr, vxId7, false);
        wg.setStringValue(vNameAttr, vxId7, "name7");
        txId1 = wg.addTransaction(vxId1, vxId2, false);
        wg.setBooleanValue(tSelAttr, txId1, false);
        wg.setStringValue(tNameAttr, txId1, "name101");
        txId2 = wg.addTransaction(vxId1, vxId3, false);
        wg.setBooleanValue(tSelAttr, txId2, true);
        wg.setStringValue(tNameAttr, txId2, "name102");
        txId3 = wg.addTransaction(vxId2, vxId4, true);
        wg.setBooleanValue(tSelAttr, txId3, false);
        wg.setStringValue(tNameAttr, txId3, "name103");
        txId4 = wg.addTransaction(vxId4, vxId2, true);
        wg.setBooleanValue(tSelAttr, txId4, true);
        wg.setStringValue(tNameAttr, txId4, "name104");
        txId5 = wg.addTransaction(vxId5, vxId6, false);
        wg.setBooleanValue(tSelAttr, txId5, false);
        wg.setStringValue(tNameAttr, txId5, "name105");
    } finally {
        wg.commit();
    }
}
Also used : DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with WritableGraph

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenarioInReverse.

// @Test(expectedExceptions = DuplicateKeyException.class)
@Test
public void testReadWithDuplicateGraphScenarioInReverse() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, vertexTypeAttribute, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.ensure(originalGraph);
    transactionDateTimeAttribute = TemporalConcept.TransactionAttribute.DATETIME.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute, vertexTypeAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute);
    originalGraph.validateKeys();
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "Vertex #0");
    originalGraph.setStringValue(identifierAttribute, vx1, "Vertex #1");
    // mimic creating nodes on visual schema which will create a DuplicateKeyException - i.e. this is a known issue
    originalGraph.setStringValue(identifierAttribute, vx2, "Vertex #2");
    originalGraph.setStringValue(vertexTypeAttribute, vx0, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx1, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx2, "Unknown");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyGraphParams = copyGraphPlugin.createParameters();
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyGraphParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyGraphParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    Set<String> vertexPrimaryKeys = null;
    Set<String> transactionPrimaryKeys = null;
    final ReadableGraph rg2 = compareGraph.getReadableGraph();
    try {
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.TRANSACTION);
    } finally {
        rg2.release();
    }
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", compareAll, originalAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        // assertEquals(changes.size(), 3);
        finalGraph = instance.createComparisonGraph(compareGraph, changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    // }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 19 with WritableGraph

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenario.

@Test
public void testReadWithDuplicateGraphScenario() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, typeAttribute, uniqueIdAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    // typeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "vx0");
    originalGraph.setStringValue(identifierAttribute, vx1, "vx1");
    originalGraph.setStringValue(identifierAttribute, vx2, "vx2");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyParams = copyGraphPlugin.createParameters();
        copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        Assert.assertEquals(wg.getTransactionCount(), 2);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
        Assert.assertEquals(wg.getTransactionCount(), 0);
    } finally {
        wg.commit();
    }
    ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 5);
        finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    rg = finalGraph.getReadableGraph();
    try {
        int vxCount = rg.getVertexCount();
        int txCount = rg.getTransactionCount();
        assertEquals(vxCount, 3);
        assertEquals(txCount, 2);
    } finally {
        rg.release();
    }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 20 with WritableGraph

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

the class ModCountNGTest method setStringValueModCounts.

/**
 * Tests that the mod counts on the two graphs in a DualGraph match after a
 * string value is set on a graph with a single vertex.
 */
@Test
public void setStringValueModCounts() {
    final DualGraph g = new DualGraph(null);
    try {
        long modCount;
        WritableGraph wg = g.getWritableGraph("", true);
        int attribute, vertex;
        final String value = "s", defaultValue = "";
        try {
            vertex = wg.addVertex();
            attribute = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "description", defaultValue, null);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(defaultValue, wg.getStringValue(attribute, vertex));
            assertEquals(modCount, wg.getGlobalModificationCounter());
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            wg.setStringValue(attribute, vertex, value);
            modCount = wg.getGlobalModificationCounter();
        } finally {
            wg.commit();
        }
        wg = g.getWritableGraph("", true);
        try {
            assertEquals(value, wg.getStringValue(attribute, vertex));
            assertEquals(modCount, wg.getGlobalModificationCounter());
        } finally {
            wg.commit();
        }
    } catch (InterruptedException ex) {
        assertTrue(ex.toString(), false);
    }
}
Also used : WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

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