@Test // @Ignore
  public void testResolve() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);
      try {
        info.resolveUsername(ObjectClass.ACCOUNT, TEST_USER, new OperationOptions(new HashMap()));
        Assert.fail("exception expected");
      } catch (UnknownUidException ue) {
        // expected
      }

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");
      Uid retrievedUid =
          info.resolveUsername(ObjectClass.ACCOUNT, TEST_USER, new OperationOptions(new HashMap()));
      Assert.assertEquals(newUid, retrievedUid);
    } finally {
      info.dispose();
    }
  }
  @Test // @Ignore
  public void testCreate() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    Set<Attribute> attrs = fillInSampleUser(TEST_USER);

    try {
      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");
      try {
        info.create(ObjectClass.ACCOUNT, attrs, null);
        Assert.fail("should have thrown exception");
      } catch (AlreadyExistsException aee) {
        // expected
      }
    } finally {
      info.dispose();
    }
  }
  @Test // @Ignore
  public void testChangePassword() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");

      ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
      builder.setUid(newUid);
      Attribute password =
          AttributeBuilder.build(
              OperationalAttributes.PASSWORD_NAME, new GuardedString("xyzzy123".toCharArray()));
      builder.addAttribute(password);
      builder.addAttribute(new Name(TEST_USER));
      ConnectorObject newUser = builder.build();
      info.update(newUser.getObjectClass(), newUser.getAttributes(), null);
    } finally {
      info.dispose();
    }
  }
  @Test // @Ignore
  public void testEnableDisable() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");

      // Test disabling the user
      {
        ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
        builder.setUid(newUid);
        Attribute password =
            AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.FALSE);
        builder.addAttribute(password);
        builder.addAttribute(new Name(TEST_USER));
        ConnectorObject newUser = builder.build();
        info.update(newUser.getObjectClass(), newUser.getAttributes(), null);

        Map map = new HashMap<String, Object>();
        map.put(
            OperationOptions.OP_ATTRIBUTES_TO_GET,
            new String[] {OperationalAttributes.ENABLE_NAME});
        OperationOptions options = new OperationOptions(map);

        ConnectorObject user = getUser(TEST_USER, options);
        Attribute enabled = user.getAttributeByName(OperationalAttributes.ENABLE_NAME);
        Assert.assertNotNull(enabled);
        Assert.assertFalse(AttributeUtil.getBooleanValue(enabled));
      }

      // Test enabling the user
      {
        ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
        builder.setUid(newUid);
        Attribute password =
            AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.TRUE);
        builder.addAttribute(password);
        builder.addAttribute(new Name(TEST_USER));
        ConnectorObject newUser = builder.build();
        info.update(newUser.getObjectClass(), newUser.getAttributes(), null);

        Attribute enabled = newUser.getAttributeByName(OperationalAttributes.ENABLE_NAME);
        Assert.assertNotNull(enabled);
        Assert.assertTrue(AttributeUtil.getBooleanValue(enabled));
      }
    } finally {
      info.dispose();
    }
  }
 public void delete(ObjectClass objectClass, Uid uid, OperationOptions options) {
   if (null == uid.getRevision()) {
     throw new PreconditionRequiredException("Version is required for MVCC");
   } else if (config.getGuid().toString().equals(uid.getRevision())) {
     // Delete
   } else {
     throw new PreconditionFailedException(
         "Current version of resource is 0 and not match with: " + uid.getRevision());
   }
 }
  private Uid doUpdate() throws IOException, JSchException {

    if (uid == null || StringUtil.isBlank(uid.getUidValue())) {
      throw new IllegalArgumentException("No Uid attribute provided in the attributes");
    }

    LOG.info("Update user: "******"Wrong object class");
    }

    if (objectClass.equals(ObjectClass.ACCOUNT)) {
      if (!EvaluateCommandsResultOutput.evaluateUserOrGroupExists(
          unixConnection.execute(
              UnixConnector.getCommandGenerator().userExists(uid.getUidValue())))) {
        throw new ConnectorException("User " + uid + " do not exists");
      }
      for (Attribute attr : attrs) {
        if (attr.is(Name.NAME) || attr.is(Uid.NAME)) {
          newUserName = (String) attr.getValue().get(0);
        } else if (attr.is(OperationalAttributes.PASSWORD_NAME)) {
          password = Utilities.getPlainPassword((GuardedString) attr.getValue().get(0));
        } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
          status = Boolean.parseBoolean(attr.getValue().get(0).toString());
        } else if (attr.is(configuration.getCommentAttribute())) {
          comment = attr.getValue().get(0).toString();
        } else if (attr.is(configuration.getShellAttribute())) {
          shell = (String) attr.getValue().get(0).toString();
        } else if (attr.is(configuration.getHomeDirectoryAttribute())) {
          homeDirectory = (String) attr.getValue().get(0).toString();
        }
      }
      unixConnection.execute(
          UnixConnector.getCommandGenerator()
              .updateUser(
                  uid.getUidValue(), newUserName, password, status, comment, shell, homeDirectory));
      //            unixConnection.execute("mv /home/" + uid.getUidValue() + " /home/" +
      // newUserName);
      unixConnection.execute(
          UnixConnector.getCommandGenerator().moveHomeDirectory(uid.getUidValue(), newUserName));
      if (!status) {
        unixConnection.execute(UnixConnector.getCommandGenerator().lockUser(uid.getUidValue()));
      } else {
        unixConnection.execute(UnixConnector.getCommandGenerator().unlockUser(uid.getUidValue()));
      }
      if (StringUtil.isNotBlank(newUserName) && StringUtil.isNotEmpty(newUserName)) {
        unixConnection.execute(
            UnixConnector.getCommandGenerator().updateGroup(uid.getUidValue(), newUserName));
      }
    } else if (objectClass.equals(ObjectClass.GROUP)) {
      if (!EvaluateCommandsResultOutput.evaluateUserOrGroupExists(
          unixConnection.execute(UnixConnector.getCommandGenerator().groupExists(newUserName)))) {
        throw new ConnectorException("Group do not exists");
      }
      unixConnection.execute(
          UnixConnector.getCommandGenerator().updateGroup(uid.getUidValue(), newUserName));
    }
    return uid;
  }
  private Uid doUpdate(
      ObjectClass objClass,
      Uid uid,
      Map<String, MdObjectAttribute> changedAttributes,
      OperationOptions arg3) {
    if (!isAccount(objClass)) {
      throw new ConnectorException(
          "Could not delete record from object class : "
              + objClass
              + ". Expected account object class.");
    }

    LOG.ok("Update object start");

    String objId = uid.getUidValue();
    LOG.ok("Updating object with uid {0}", uid.getUidValue());

    try {
      MdObjectStore objectStore = createObjectStore();
      CMetadata metadata = getOmiUtil().getFullObject(objectStore, MetadataObjects.PERSON, objId);
      if (metadata == null) {
        throw new NoSuchObjectException("Object with the identifier " + objId + " does not exist.");
      }

      String xmlSelect = getXmlSelectForName(metadata.getName());
      int exist =
          getOmiUtil().doesObjectExist(getFoundationRepoId(), MetadataObjects.PERSON, xmlSelect);
      if (exist == 0) {
        throw new NoSuchObjectException(
            "Object with name " + metadata.getName() + " does not exist.");
      }

      metadata =
          createComplexMetadataObject(
              objectStore, metadata.getName(), MetadataObjects.PERSON, objId);
      LOG.ok("Found metadata object {0}", metadata.toString());

      metadata.setAttrs(changedAttributes);
      metadata.updateMetadataAll();
      String uidAfterChange = metadata.getId();
      objectStore.dispose();
      return new Uid(uidAfterChange);
    } catch (java.rmi.ConnectException e) {
      throw new ConnectorException(e);
    } catch (RemoteException e) {
      throw new ConnectorException(e);
    } catch (MdException e) {
      throw new ConnectorException(e);
    }
  }
  private Uid doUpdate() throws IOException {

    if (!objectClass.equals(ObjectClass.ACCOUNT) && (!objectClass.equals(ObjectClass.GROUP))) {
      throw new IllegalStateException("Wrong object class");
    }

    if (!userExists(
        uid.getUidValue(), configuration.getOpenamRealm(), adminToken.getToken(), connection)) {
      LOG.error("User " + uid.getUidValue() + " do not exists");
      throw new ConnectorException("User " + uid.getUidValue() + " do not exists");
    }

    try {
      connection.update(createUpdateQueryString(uid, attrs, adminToken).toString());
      LOG.ok("User " + uid.getUidValue() + " updated");
    } catch (HttpClientErrorException hcee) {
      throw hcee;
    }
    return uid;
  }
  public void delete(ObjectClass objClass, Uid uid, OperationOptions arg2) {

    try {

      if (!isAccount(objClass)) {
        throw new ConnectorException(
            "Could not delete record from object class : "
                + objClass
                + ". Expected account object class.");
      }

      LOG.ok("Attempt to delete object with uid {0}", uid.getUidValue());

      getOmiUtil().deleteMetadataObject(MetadataObjects.PERSON, uid.getUidValue());
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    } catch (MdException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    }
  }
  @Test // @Ignore
  public void testDelete() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    Set<Attribute> attrs = fillInSampleUser(TEST_USER);

    try {
      // Create the account if it doesn't already exist
      //
      ConnectorObject user = getUser(TEST_USER);
      Uid newUid = null;
      if (user == null) {
        try {
          newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
          System.out.println(newUid.getValue() + " created");
        } catch (AlreadyExistsException rte) {
          // ignore
        }
      } else {
        newUid = user.getUid();
      }

      // Delete the account
      //
      info.delete(ObjectClass.ACCOUNT, newUid, null);
      System.out.println(newUid.getValue() + " deleted");

      try {
        info.delete(ObjectClass.ACCOUNT, newUid, null);
        Assert.fail("Should have seen exception");
      } catch (UnknownUidException uue) {
        // expected
      }
    } finally {
      info.dispose();
    }
  }