@Test
 public void canDeleteExistingUser() {
   String tmpUserId = createUserForDelete();
   db.setDeactivateOnDelete(false);
   db.delete(tmpUserId, 0);
   assertEquals(0, template.queryForList("select * from users where id=?", tmpUserId).size());
   assertEquals(0, db.query("username eq \"" + tmpUserId + "\"").size());
 }
 @Test(expected = ScimResourceAlreadyExistsException.class)
 public void cannotDeactivateExistingUserAndThenCreateHimAgain() {
   String tmpUserId = createUserForDelete();
   ScimUser deletedUser = db.delete(tmpUserId, 0);
   deletedUser.setActive(true);
   try {
     db.createUser(deletedUser, "foobarspam1234");
   } catch (ScimResourceAlreadyExistsException e) {
     removeUser(tmpUserId);
     throw e;
   }
 }
 @Test
 public void canDeactivateExistingUser() {
   String tmpUserId = createUserForDelete();
   ScimUser deletedUser = db.delete(tmpUserId, 0);
   assertEquals(
       1,
       template
           .queryForList("select * from users where id=? and active=?", tmpUserId, false)
           .size());
   assertFalse(deletedUser.isActive());
   assertEquals(1, db.query("username eq \"" + tmpUserId + "\" and active eq false").size());
   removeUser(tmpUserId);
 }
  @Test
  // (expected = ScimResourceAlreadyExistsException.class)
  public void canDeleteExistingUserAndThenCreateHimAgain() {
    String tmpUserId = createUserForDelete();
    db.setDeactivateOnDelete(false);
    ScimUser deletedUser = db.delete(tmpUserId, 0);
    assertEquals(0, template.queryForList("select * from users where id=?", tmpUserId).size());

    deletedUser.setActive(true);
    ScimUser user = db.createUser(deletedUser, "foobarspam1234");
    assertNotNull(user);
    assertNotNull(user.getId());
    assertNotSame(tmpUserId, user.getId());
    assertEquals(1, db.query("username eq \"" + tmpUserId + "\"").size());
    removeUser(user.getId());
  }
 @Test(expected = OptimisticLockingFailureException.class)
 public void deleteWithWrongVersionIsError() {
   db.setDeactivateOnDelete(false);
   ScimUser joe = db.delete(JOE_ID, 1);
   assertJoe(joe);
 }
 @Test(expected = ScimResourceNotFoundException.class)
 public void cannotDeleteNonexistentUser() {
   db.setDeactivateOnDelete(false);
   ScimUser joe = db.delete("9999", 0);
   assertJoe(joe);
 }