/**
   * Write a modify request using an exclusion filter attribute.
   *
   * @throws Exception
   */
  @Test
  public void testWriteModifyRequestFilterAttributesExcluded() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

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

    writer.setExcludeAttribute(AttributeDescription.valueOf("work-phone"));
    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.size()).isEqualTo(3);
    assertThat(actual.get(0)).isEqualTo("dn: cn=scarter,dc=example,dc=com");
    assertThat(actual.get(1)).isEqualTo("changetype: modify");
    assertThat(actual.get(2)).isEqualTo("");
  }
  /**
   * Test SetIncludeAttribute method of LDIFChangeRecordWriter. Inserting attribute cn (common name)
   * & sn (surname).
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testSetIncludeAttributeWithMatch() throws Exception {
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    final AddRequest changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());

    writer.setIncludeAttribute(AttributeDescription.valueOf("cn"));
    writer.setIncludeAttribute(AttributeDescription.valueOf("sn"));
    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.get(0)).isEqualTo("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.get(1)).isEqualTo("changetype: add");
    assertThat(actual.get(2)).contains("sn: Carter");
    assertThat(actual.get(3)).contains("cn: ");
    assertThat(actual.get(4)).contains("");
  }
  /**
   * Test to write an LDIFChangeRecordWriter with attribute exclusions. In this case, vip attribute
   * is not present in the example. All lines must be written.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test
  public void testSetExcludeAttributeWithNoMatch() throws Exception {
    final AttributeDescription attribute = AttributeDescription.valueOf("vip");
    final List<String> actual = new ArrayList<>();
    final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);

    final AddRequest changeRequest = Requests.newAddRequest(getAddLDIFChangeRecord());
    writer.setExcludeAttribute(attribute);
    writer.writeChangeRecord(changeRequest);
    writer.close();

    assertThat(actual.get(0)).isEqualTo("dn: uid=scarter,ou=People,dc=example,dc=com");
    assertThat(actual.size()).isEqualTo(14);
    for (String line : actual) {
      // we have excluded this attribute especially.
      assertThat(line).doesNotContain("vip");
    }
  }