/**
   * Positive test: Ensure that the datastructure restored from the XML representation is identical
   * to the input. As an equals comparison is impossible on a perso this comparison is performed on
   * a second marshalled version.
   *
   * @throws Exception
   */
  @Test
  public void test_MarshallUnmarshallMarshall_StringBuffer() throws Exception {
    // instantiate marshaller
    Marshaller m = PersoSimJaxbContextProvider.getContext().createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // Write to String
    StringWriter strWriter = new StringWriter();
    m.marshal(testPerso, strWriter);
    String marshalledPerso = strWriter.toString();
    System.out.println(marshalledPerso);

    // unmarshall from string
    StringReader sr = new StringReader(marshalledPerso);
    Unmarshaller um = PersoSimJaxbContextProvider.getContext().createUnmarshaller();
    XmlPersonalization unmarshalledPerso = (XmlPersonalization) um.unmarshal(sr);

    // marshall again
    StringWriter sndStrWriter = new StringWriter();
    m.marshal(unmarshalledPerso, sndStrWriter);
    String sndMarshalledPerso = sndStrWriter.toString();

    // assert that both marschalled persos are the same
    assertEquals(marshalledPerso, sndMarshalledPerso);
  }
  /**
   * Positive test: Ensure that the unmarschalled Objects are of correct type
   *
   * <p>In order to allow For all (as far as this can be checked with generic methods)
   *
   * @throws Exception
   */
  @Test
  public void test_MarshallUnmarshall_StringBuffer_checkObjectTypes() throws Exception {
    // instantiate marshaller
    Marshaller m = PersoSimJaxbContextProvider.getContext().createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // Marshall/unmarshall through StringBuffer
    StringWriter strWriter = new StringWriter();
    m.marshal(testPerso, strWriter);
    StringReader sr = new StringReader(strWriter.toString());
    Unmarshaller um = PersoSimJaxbContextProvider.getContext().createUnmarshaller();
    XmlPersonalization unmarshalledPerso = (XmlPersonalization) um.unmarshal(sr);

    // check all CardObjects, their children and all Identifiers of the card objet tree
    assertObjectTypes(unmarshalledPerso.getObjectTree());
  }
  /**
   * Positive test test marshalling/unmarshalling the testPerso to/from a temporary file in the
   * filesystem.
   *
   * @throws Exception
   */
  @Test
  public void test_MarshallUnmarshall_File() throws Exception {
    // instantiate marshaller
    Marshaller m = PersoSimJaxbContextProvider.getContext().createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // Write to File
    File xmlFile = new File(XML_FILENAME);
    xmlFile.getParentFile().mkdirs();
    m.marshal(testPerso, xmlFile);

    // get variables from our xml file, created before
    Unmarshaller um = PersoSimJaxbContextProvider.getContext().createUnmarshaller();
    XmlPersonalization unmarshalledPerso =
        (XmlPersonalization) um.unmarshal(new FileReader(xmlFile));
    assertNotNull(unmarshalledPerso);
  }