/**
   * Write an ChangeRecord Moddn LDIF.
   *
   * @throws Exception
   */
  @Test
  public void testWriteModdnRequest() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    // @formatter:off
    final ModifyDNRequest changeRequest =
        Requests.newModifyDNRequest("uid=scarter,ou=People,dc=example,dc=com", "cn=carter");
    // @formatter:on

    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.size()).isEqualTo(5);
    assertThat(actual.get(0)).isEqualTo("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.get(1)).isEqualTo("changetype: modrdn");
    assertThat(actual.get(2)).isEqualTo("newrdn: cn=carter");
    assertThat(actual.get(3)).isEqualTo("deleteoldrdn: 0");
  }
  /**
   * Write a full example containing multiple change records.
   *
   * @throws Exception
   */
  @Test
  public void testWriteMultipleChangeRecords() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
    final ChangeRecord changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());

    // @formatter:off
    final ModifyDNRequest changeRequest2 =
        Requests.newModifyDNRequest("cn=scarter,dc=example,dc=com", "cn=Susan Jacobs")
            .setDeleteOldRDN(false);
    // @formatter:on

    // @formatter:off
    final ModifyRequest changeRequest3 =
        Requests.newModifyRequest(
            "version: 1",
            "",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modify",
            "replace: work-phone",
            "work-phone: 555-555-1155");
    // @formatter:on

    // @formatter:off
    final AddRequest changeRequest4 =
        Requests.newAddRequest(
            "version: 1",
            "dn: uid=scarter,ou=People,dc=example,dc=com",
            "changetype: add",
            "sn: Carter");
    // @formatter:on

    final File file = File.createTempFile("sdk", null);
    final String url = file.toURI().toURL().toString();

    // @formatter:off
    final AddRequest changeRequest5 =
        Requests.newAddRequest(
            "version: 1",
            "# Add a new record",
            "dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com",
            "changetype: add",
            "objectclass: top",
            "objectclass: person",
            "objectclass: organizationalPerson",
            "cn: Fiona Jensen",
            "sn: Jensen",
            "uid: fiona",
            "telephonenumber: +1 408 555 1212",
            "jpegphoto:< " + url);
    // @formatter:on

    writer.writeChangeRecord(changeRequest);
    writer.writeChangeRecord(changeRequest2);
    writer.writeChangeRecord(changeRequest3);
    writer.writeChangeRecord(changeRequest4);
    writer.writeComment("A comment...");
    writer.writeChangeRecord(changeRequest5);
    writer.close();

    assertThat(actual.size()).isGreaterThan(10);
    assertThat(actual.get(0)).isEqualTo("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.get(actual.size() - 1)).isEqualTo("");

    file.delete();
  }