Search in sources :

Example 1 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress 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 2 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress 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 3 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param file The graph file
 * @throws IOException
 */
public static void saveGraphToTemporaryDirectory(final StoreGraph graph, final File file) throws IOException {
    makeGraphInteractable(graph);
    final GraphJsonWriter writer = new GraphJsonWriter();
    writer.writeGraphToZip(graph, file.getPath(), new TextIoProgress(false));
}
Also used : GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)

Example 4 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class SaveGraphUtilities method saveGraphToTemporaryDirectory.

/**
 * Save the graph to the temporary directory for debugging.
 * <p>
 * The main use case of this method is debugging unit tests and so this
 * method does extra checks to make sure one can interact with the graph
 * build from a crude unit test.
 *
 * @param graph The graph
 * @param filename The filename excluding the file extension
 * @throws IOException
 */
public static void saveGraphToTemporaryDirectory(final StoreGraph graph, final String filename) throws IOException {
    final File saveCreatedGraph = File.createTempFile(filename, FileExtensionConstants.STAR);
    makeGraphInteractable(graph);
    final GraphJsonWriter writer = new GraphJsonWriter();
    writer.writeGraphToZip(graph, saveCreatedGraph.getPath(), new TextIoProgress(false));
}
Also used : GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File)

Example 5 with TextIoProgress

use of au.gov.asd.tac.constellation.utilities.gui.TextIoProgress in project constellation by constellation-app.

the class AutosaveGraphPluginNGTest method testExecute.

/**
 * Test of execute method, of class AutosaveGraphPlugin.
 *
 * @throws java.lang.Exception
 */
@Test
public void testExecute() throws Exception {
    final File saveDir = AutosaveUtilities.getAutosaveDir();
    final File saveFile = new File(saveDir, graph.getId() + FileExtensionConstants.STAR);
    // check the autosave file doesn't exist before running the plugin
    assertEquals(saveFile.exists(), false);
    TopComponent tc = new TopComponent();
    tc.setName("TestName");
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject("graph", true);
    final GraphNode graphNode = new GraphNode(graph, gdo, tc, null);
    AutosaveGraphPlugin instance = new AutosaveGraphPlugin();
    PluginExecution.withPlugin(instance).executeNow(graph);
    // check that the autosave file does now exist
    assertEquals(saveFile.exists(), true);
    final Graph openSavedGraph = new GraphJsonReader().readGraphZip(saveFile, new TextIoProgress(false));
    final ReadableGraph rg = openSavedGraph.getReadableGraph();
    try {
        // check that the graph from the autosave matches the original graph
        assertEquals(rg.getVertexCount(), 7);
        assertEquals(rg.getStringValue(vAttrId, vxId1), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId2), "true");
        assertEquals(rg.getStringValue(vAttrId, vxId3), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId4), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId5), "true");
        assertEquals(rg.getTransactionCount(), 5);
    } finally {
        rg.release();
        // deleting the file afterwards
        AutosaveUtilities.deleteAutosave(saveFile);
        graphNode.destroy();
    }
}
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) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) TopComponent(org.openide.windows.TopComponent) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader) Test(org.testng.annotations.Test)

Aggregations

TextIoProgress (au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)7 File (java.io.File)6 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)4 GraphJsonWriter (au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter)4 GraphJsonReader (au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader)2 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)2 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 Config (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.io.Config)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TopComponent (org.openide.windows.TopComponent)1