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();
}
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();
}
}
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));
}
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));
}
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();
}
}
Aggregations