@Test
  public void testReadAttributeValues() throws GraphIOException {
    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);
    }

    v.readAttributeValues(
        GraphIO.createStringReader(
            "f "
                + "[[f]] "
                + "{[t t] - {f} [f f] - {t f}} "
                + "{{f}} "
                + "12.34 "
                + "SECOND "
                + "42"
                + "[t t] "
                + "987654321 "
                + "{1 - f 2 - t} "
                + "(f 2.2 THIRD 42 [f t] 987654321 {1 - f 2 - t} {t} \"some String\") "
                + "{f} "
                + "\"some String\"",
            v.getSchema()));

    // parse values different from the default ones
    assertEquals(false, v.getAttribute("boolVertex"));
    assertEquals(
        JGraLab.vector().plus(JGraLab.vector().plus(false)), v.getAttribute("complexListVertex"));
    assertEquals(
        JGraLab.map()
            .plus(JGraLab.vector().plus(true).plus(true), JGraLab.set().plus(false))
            .plus(JGraLab.vector().plus(false).plus(false), JGraLab.set().plus(true).plus(false)),
        v.getAttribute("complexMapVertex"));
    assertEquals(JGraLab.set().plus(JGraLab.set().plus(false)), v.getAttribute("complexSetVertex"));
    assertEquals(12.34, v.getAttribute("doubleVertex"), 0.001);
    assertEquals("SECOND", v.getAttribute("enumVertex"));
    assertEquals(42, (int) v.getAttribute("intVertex"));
    assertEquals(JGraLab.vector().plus(true).plus(true), v.getAttribute("listVertex"));
    assertEquals(987654321l, (long) v.getAttribute("longVertex"));
    assertEquals(JGraLab.map().plus(1, false).plus(2, true), v.getAttribute("mapVertex"));
    assertEquals(
        RecordImpl.empty()
            .plus("boolRecord", false)
            .plus("doubleRecord", 2.2d)
            .plus("enumRecord", "THIRD")
            .plus("intRecord", 42)
            .plus("listRecord", JGraLab.vector().plus(false).plus(true))
            .plus("longRecord", 987654321l)
            .plus("mapRecord", JGraLab.map().plus(1, false).plus(2, true))
            .plus("setRecord", JGraLab.set().plus(true))
            .plus("stringRecord", "some String"),
        v.getAttribute("recordVertex"));
    assertEquals(JGraLab.set().plus(false), v.getAttribute("setVertex"));
    assertEquals("some String", v.getAttribute("stringVertex"));
  }
  /**
   * Creates an Attribute map out of an Attribute set.
   *
   * @param attributeList Set of Attribute object, of which a map of Attributes should be created.
   * @return Map of Attribute objects with their QualifiedName as key.
   */
  private final Map<String, de.uni_koblenz.jgralab.schema.Attribute> getAttributeMap(
      SortedSet<de.uni_koblenz.jgralab.schema.Attribute> attributeList) {

    Map<String, de.uni_koblenz.jgralab.schema.Attribute> attributes =
        new HashMap<String, de.uni_koblenz.jgralab.schema.Attribute>();

    for (de.uni_koblenz.jgralab.schema.Attribute attribute : attributeList) {
      attributes.put(attribute.getName(), attribute);
    }

    return attributes;
  }
  @Test
  public void testWriteAttributeValueToString()
      throws NoSuchAttributeException, IOException, GraphIOException {
    Schema s =
        GraphIO.loadSchemaFromFile(GenericGraphImplTest.SCHEMAFOLDER + "DefaultValueTestSchema.tg");
    Graph g = s.createGraph(ImplementationType.GENERIC);
    InternalVertex v = g.createVertex(g.getGraphClass().getVertexClass("TestSubVertex"));
    for (Attribute a : v.getAttributedElementClass().getAttributeList()) {
      GenericGraphImplTest.testDefaultValue(v.getAttribute(a.getName()), a);
    }
    // Default values count as unset, so everything's u
    assertEquals("u", v.writeAttributeValueToString("boolVertex"));
    assertEquals("u", v.writeAttributeValueToString("complexListVertex"));
    assertEquals("u", v.writeAttributeValueToString("complexMapVertex"));
    assertEquals("u", v.writeAttributeValueToString("complexSetVertex"));
    assertEquals("u", v.writeAttributeValueToString("doubleVertex"));
    assertEquals("u", v.writeAttributeValueToString("enumVertex"));
    assertEquals("u", v.writeAttributeValueToString("intVertex"));
    assertEquals("u", v.writeAttributeValueToString("listVertex"));
    assertEquals("u", v.writeAttributeValueToString("longVertex"));
    assertEquals("u", v.writeAttributeValueToString("mapVertex"));
    assertEquals("u", v.writeAttributeValueToString("recordVertex"));
    assertEquals("u", v.writeAttributeValueToString("setVertex"));
    assertEquals("u", v.writeAttributeValueToString("stringVertex"));

    // 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()));
    }
    assertEquals("t", v.writeAttributeValueToString("boolVertex"));
    assertEquals("[[t][f][t]]", v.writeAttributeValueToString("complexListVertex"));
    assertEquals("{[t]-{t}[f]-{f}}", v.writeAttributeValueToString("complexMapVertex"));
    assertEquals("{{t}{f}}", v.writeAttributeValueToString("complexSetVertex"));
    assertEquals("1.1", v.writeAttributeValueToString("doubleVertex"));
    assertEquals("FIRST", v.writeAttributeValueToString("enumVertex"));
    assertEquals("1", v.writeAttributeValueToString("intVertex"));
    assertEquals("[t f t]", v.writeAttributeValueToString("listVertex"));
    assertEquals("1", v.writeAttributeValueToString("longVertex"));
    assertEquals("{1 - t 2 - f 3 - t}", v.writeAttributeValueToString("mapVertex"));
    assertEquals(
        "(t 1.1 FIRST 1[t f t]1{1 - t 2 - f 3 - t}{t f}\"test\")",
        v.writeAttributeValueToString("recordVertex"));
    assertEquals("{t f}", v.writeAttributeValueToString("setVertex"));
    assertEquals("\"test\"", v.writeAttributeValueToString("stringVertex"));
  }
  @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());
    }
  }
  @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());
  }