@Test
  public void testModifyAttributesWithException() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    try {
      // Perform test
      dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
      fail("DummyException expected");
    } catch (DummyException expected) {
      assertTrue(true);
    }

    // Verify result - check that the operation was properly rolled back
    Object result =
        ldapTemplate.lookup(
            dn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                assertEquals("Person", attributes.get("sn").get());
                assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
                return new Object();
              }
            });

    assertNotNull(result);
  }
  @Test
  public void testUpdateAndRenameWithException() {
    String dn = "cn=Some Person2,ou=company1,ou=Sweden";
    String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
    try {
      // Perform test
      dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
      fail("DummyException expected");
    } catch (DummyException expected) {
      assertTrue(true);
    }

    // Verify that entry was not moved.
    try {
      ldapTemplate.lookup(newDn);
      fail("NameNotFoundException expected");
    } catch (NameNotFoundException expected) {
      assertTrue(true);
    }

    // Verify that original entry was not updated.
    Object object =
        ldapTemplate.lookup(
            dn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
                return new Object();
              }
            });
    assertNotNull(object);
  }
  @Test
  public void testUpdateWithException() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    try {
      dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
      fail("DummyException expected");
    } catch (DummyException expected) {
      assertTrue(true);
    }

    log.debug("Verifying result");

    Object ldapResult =
        ldapTemplate.lookup(
            dn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                assertEquals("Person", attributes.get("sn").get());
                assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
                return new Object();
              }
            });

    assertNotNull(ldapResult);
  }
  @Test
  public void testCreate() {
    dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");

    log.debug("Verifying result");
    String expectedDn = "cn=some testperson, ou=company1, ou=Sweden";
    Object ldapResult = ldapTemplate.lookup(expectedDn);
    assertNotNull(ldapResult);

    ldapTemplate.unbind(expectedDn);
  }
  @Test
  public void testUpdateAndRename() {
    String dn = "cn=Some Person2,ou=company1,ou=Sweden";
    String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
    // Perform test
    dummyDao.updateAndRename(dn, newDn, "Updated description");

    // Verify that entry was moved and updated.
    Object object =
        ldapTemplate.lookup(
            newDn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                assertEquals("Updated description", attributes.get("description").get());
                return new Object();
              }
            });

    assertNotNull(object);
    dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
  }
  @Test
  public void testUnbind() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    // Perform test
    dummyDao.unbind(dn, "Some Person");

    try {
      // Verify result - check that the operation was not rolled back
      ldapTemplate.lookup(dn);
      fail("NameNotFoundException expected");
    } catch (NameNotFoundException expected) {
      assertTrue(true);
    }
  }
  @Test
  public void testCreateWithException() {
    try {
      dummyDao.createWithException(
          "Sweden", "company1", "some testperson", "testperson", "some description");
      fail("DummyException expected");
    } catch (DummyException expected) {
      assertTrue(true);
    }

    log.debug("Verifying result");

    // Verify that no entry was created
    try {
      ldapTemplate.lookup("cn=some testperson, ou=company1, ou=Sweden");
      fail("NameNotFoundException expected");
    } catch (NameNotFoundException expected) {
      assertTrue(true);
    }
  }
  @Test
  public void testModifyAttributes() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    // Perform test
    dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");

    // Verify result - check that the operation was not rolled back
    Object result =
        ldapTemplate.lookup(
            dn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                assertEquals("Updated lastname", attributes.get("sn").get());
                assertEquals("Updated description", attributes.get("description").get());
                return new Object();
              }
            });

    assertNotNull(result);
  }
  @Test
  public void testUnbindWithException() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    try {
      // Perform test
      dummyDao.unbindWithException(dn, "Some Person");
      fail("DummyException expected");
    } catch (DummyException expected) {
      assertTrue(true);
    }

    // Verify result - check that the operation was properly rolled back
    Object ldapResult =
        ldapTemplate.lookup(
            dn,
            new AttributesMapper() {
              public Object mapFromAttributes(Attributes attributes) throws NamingException {
                // Just verify that the entry still exists.
                return new Object();
              }
            });

    assertNotNull(ldapResult);
  }