Search in sources :

Example 21 with ReadableGraph

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

the class FindNGTest method findSingleNodeCaseSensitiveNoFindTest.

@Test
public void findSingleNodeCaseSensitiveNoFindTest() throws InterruptedException, PluginException {
    ArrayList<FindRule> rules = new ArrayList<>();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        // setup find criteria / rules
        HashMap<String, Object> values = new HashMap<>();
        values.put("string_content", "Name1");
        values.put("string_case_sensitive", true);
        values.put("string_use_list", false);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.STRING, new GraphAttribute(rg, rg.getAttribute(GraphElementType.VERTEX, vNameAttr)), FindTypeOperators.Operator.IS, values);
        rules.add(rule1);
        // perform find search
        // need to create temporary GraphNode and skip the RemoteInit portion of the initialisation
        GraphNode aGraphNode = new GraphNode(graph, null, new TopComponent(), null);
        final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(GraphElementType.VERTEX, rules, false);
        PluginExecution.withPlugin(queryPlugin).executeNow(graph);
        final List<FindResult> results = queryPlugin.getResults();
        // validate results
        assertEquals("result size", 0, results.size());
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AdvancedFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin) HashMap(java.util.HashMap) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) ArrayList(java.util.ArrayList) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TopComponent(org.openide.windows.TopComponent) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult) Test(org.testng.annotations.Test)

Example 22 with ReadableGraph

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

the class GraphSavingNGTest method writeGraphTest.

@Test
public void writeGraphTest() throws Exception {
    final String name = "tmp1";
    File graphFile = File.createTempFile(name, ".star");
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(rg, graphFile.getPath(), new TextIoProgress(false));
    } finally {
        rg.release();
    }
    assertTrue("file created", graphFile.exists());
    graphFile.delete();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) Test(org.testng.annotations.Test)

Example 23 with ReadableGraph

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

the class IONGTest method attributeMergerSaveTest.

/**
 * Tests that saving and loading a Constellation file preserves the
 * attribute mergers specified on each attribute, both in the null case, and
 * the non-null case.
 *
 * @throws IOException
 * @throws InterruptedException
 * @throws GraphParseException
 */
@Test
public void attributeMergerSaveTest() throws IOException, InterruptedException, GraphParseException {
    final StoreGraph storeGraph = new StoreGraph();
    storeGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "defaultMergerAttribute", null, null, GraphAttributeMerger.getDefault().getId());
    storeGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "customMergerAttribute", null, null, ConcatenatedSetGraphAttributeMerger.ID);
    storeGraph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "noMergerAttribute", null, null, null);
    final GraphJsonWriter writer = new GraphJsonWriter();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.writeGraphToStream(storeGraph, out, false, Arrays.asList(GraphElementType.GRAPH, GraphElementType.VERTEX, GraphElementType.TRANSACTION, GraphElementType.META));
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    GraphJsonReader reader = new GraphJsonReader();
    final Graph graph = reader.readGraph("test", in, -1, null);
    ReadableGraph rg = graph.getReadableGraph();
    try {
        final int defaultMergerAttributeId = rg.getAttribute(GraphElementType.VERTEX, "defaultMergerAttribute");
        assert rg.getAttributeMerger(defaultMergerAttributeId) == GraphAttributeMerger.getDefault();
        final int customMergerAttributeId = rg.getAttribute(GraphElementType.VERTEX, "customMergerAttribute");
        assert rg.getAttributeMerger(customMergerAttributeId) == GraphAttributeMerger.getMergers().get(ConcatenatedSetGraphAttributeMerger.ID);
        final int noMergerAttributeId = rg.getAttribute(GraphElementType.VERTEX, "noMergerAttribute");
        assert rg.getAttributeMerger(noMergerAttributeId) == null;
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 24 with ReadableGraph

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

the class IONGTest method saveLoadNonNullDefault.

/**
 * Saving and loading an attribute with a non-null default value.
 */
@Test
public void saveLoadNonNullDefault() {
    final String name = UUID.randomUUID().toString();
    File graphFile = null;
    try {
        graphFile = File.createTempFile(name, ".star");
    } catch (IOException ex) {
        Assert.fail("Create file", ex);
    }
    final String nameAttrLabel = "name";
    final String nndAttrLabel = "nnd";
    final String defaultValue = "A non-null value";
    try {
        final StoreGraph graph = new StoreGraph();
        final int nameAttrId = graph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, nameAttrLabel, nameAttrLabel, "", null);
        final int nndAttrId = graph.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, nndAttrLabel, "All nulls", defaultValue, null);
        final int v0 = graph.addVertex();
        Assert.assertEquals(graph.getStringValue(nameAttrId, v0), "");
        Assert.assertNotNull(graph.getStringValue(nndAttrId, v0));
        Assert.assertEquals(graph.getStringValue(nndAttrId, v0), defaultValue);
        final int v1 = graph.addVertex();
        graph.setStringValue(nameAttrId, v1, "V1");
        graph.setStringValue(nndAttrId, v1, null);
        Assert.assertNull(graph.getStringValue(nndAttrId, v1));
        GraphJsonWriter writer = new GraphJsonWriter();
        writer.writeGraphToZip(graph, graphFile.getPath(), new TextIoProgress(false));
    } catch (IOException ex) {
        Assert.fail("Graph write", ex);
    }
    try {
        final Graph newGraph = new GraphJsonReader().readGraphZip(graphFile, new TextIoProgress(false));
        final ReadableGraph rg = newGraph.getReadableGraph();
        final int nameAttrId = rg.getAttribute(GraphElementType.VERTEX, nameAttrLabel);
        final int nattrId = rg.getAttribute(GraphElementType.VERTEX, nndAttrLabel);
        final int v0 = rg.getVertex(0);
        Assert.assertEquals(rg.getStringValue(nameAttrId, v0), "");
        final String val0 = rg.getStringValue(nattrId, v0);
        Assert.assertEquals(val0, defaultValue);
        final int v1 = rg.getVertex(1);
        Assert.assertEquals(rg.getStringValue(nameAttrId, v1), "V1");
        final String nval1 = rg.getStringValue(nattrId, v1);
        Assert.assertNull(nval1, "Expecting the default non-null value");
    } catch (IOException ex) {
        Assert.fail("Graph read", ex);
    } catch (GraphParseException ex) {
        Assert.fail("Graph parse", ex);
    } finally {
        graphFile.delete();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) IOException(java.io.IOException) File(java.io.File) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 25 with ReadableGraph

use of au.gov.asd.tac.constellation.graph.ReadableGraph 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)

Aggregations

ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)167 Test (org.testng.annotations.Test)62 Graph (au.gov.asd.tac.constellation.graph.Graph)57 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)43 ArrayList (java.util.ArrayList)40 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)26 HashMap (java.util.HashMap)16 Attribute (au.gov.asd.tac.constellation.graph.Attribute)14 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)12 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)12 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)12 HashSet (java.util.HashSet)12 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)11 List (java.util.List)10 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)9 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)9 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 File (java.io.File)9