private void importLDIF(String fileName) throws Exception {
    InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
    CoreSession rootDSE = service.getAdminSession();

    for (LdifEntry ldifEntry : new LdifReader(is)) {
      DefaultServerEntry entry =
          new DefaultServerEntry(
              rootDSE.getDirectoryService().getRegistries(), ldifEntry.getEntry());

      if (!rootDSE.exists(entry.getDn())) {
        rootDSE.add(entry);
      }
    }
  }
 private static void injectEntry(LdifEntry entry, DirectoryService service) throws Exception {
   if (entry.isChangeAdd()) {
     ServerEntry serverEntry = service.newEntry(entry.getDn());
     for (EntryAttribute entryAttribute : entry.getEntry()) {
       List<Value> allValue = new ArrayList<Value>();
       for (Value<?> value : entryAttribute) {
         allValue.add(value);
       }
       serverEntry.add(entryAttribute.getId(), allValue.toArray(new Value[0]));
     }
     service.getAdminSession().add(serverEntry);
     // service.getAdminSession().add( new DefaultServerEntry( service.getSchemaManager(),
     // entry.getEntry() ) );
   } else if (entry.isChangeModify()) {
     // not used, not tested ...
     service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
   } else {
     throw new IllegalArgumentException("bug");
   }
 }