@Test public void testWriteAttributeValues() throws GraphIOException, IOException { Schema s = GraphIO.loadSchemaFromFile(GenericGraphImplTest.SCHEMAFOLDER + "DefaultValueTestSchema.tg"); Graph g = s.createGraph(ImplementationType.GENERIC); InternalVertex v = g.createVertex(g.getGraphClass().getVertexClass("TestVertex")); for (Attribute a : v.getAttributedElementClass().getAttributeList()) { GenericGraphImplTest.testDefaultValue(v.getAttribute(a.getName()), a); } GraphIO io = GraphIO.createStringWriter(v.getSchema()); v.writeAttributeValues(io); // Default values count as unset, so everything's u assertEquals("u u u u u u u u u u u u u", io.getStringWriterResult()); // Now explicity set every attribute to its current default value, // so that it becomes set. for (Attribute a : v.getAttributedElementClass().getAttributeList()) { v.setAttribute(a.getName(), v.getAttribute(a.getName())); } io = GraphIO.createStringWriter(v.getSchema()); v.writeAttributeValues(io); assertEquals( "t" + "[[t][f][t]]" + "{[t]-{t}[f]-{f}}" + "{{t}{f}}" + "1.1 " + "FIRST " + "1" + "[t f t]" + "1" + "{1 - t 2 - f 3 - t}" + "(t 1.1 FIRST 1[t f t]1{1 - t 2 - f 3 - t}{t f}\"test\")" + "{t f}\"test\"", io.getStringWriterResult()); }
@Test public void testAccessAttributesAfterSaveAndLoad() throws GraphIOException, IOException { Schema schema = GraphIO.loadSchemaFromFile(GenericGraphImplTest.SCHEMAFOLDER + "DefaultValueTestSchema.tg"); Graph g = schema.createGraph(ImplementationType.GENERIC); Vertex v = g.createVertex(g.getGraphClass().getVertexClass("TestVertex")); File tmp = File.createTempFile("graph", "tg"); g.save(tmp.getPath()); g = GraphIO.loadGraphFromFile(tmp.getPath(), ImplementationType.GENERIC, null); v = g.getFirstVertex(); for (Attribute a : v.getAttributedElementClass().getAttributeList()) { GraphIO io = GraphIO.createStringWriter(g.getSchema()); a.getDomain().serializeGenericAttribute(io, v.getAttribute(a.getName())); assertEquals(a.getDefaultValueAsString(), io.getStringWriterResult()); } }