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

      deleteUser(TEST_USER, info);

      info.create(ObjectClass.ACCOUNT, attrs, null);

      ConnectorObject user = getUser(TEST_USER);
      Assert.assertNotNull(user);

      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, "asdhjfdaslfh alsk fhasldk ")),
          handler,
          null);
      Assert.assertFalse(handler.iterator().hasNext());

      handler = new TestHandler();
      String[] attributesToGet = {"firstname"};
      Map<String, Object> optionsMap = new HashMap<String, Object>();
      optionsMap.put(OperationOptions.OP_ATTRIBUTES_TO_GET, attributesToGet);
      OperationOptions options = new OperationOptions(optionsMap);
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, TEST_USER)),
          handler,
          options);
      Assert.assertTrue(handler.iterator().hasNext());
      ConnectorObject object = handler.iterator().next();
      Assert.assertNotNull(object.getAttributeByName("firstname"));
      Assert.assertNull(object.getAttributeByName("lastname"));
    } finally {
      info.dispose();
    }
  }
 @Test // @Ignore
 public void testListAllUsers() throws Exception {
   SpmlConfiguration config = createConfiguration();
   SpmlConnector info = createConnector(config);
   try {
     TestHandler handler = new TestHandler();
     TestHelpers.search(info, ObjectClass.ACCOUNT, null, handler, null);
     for (ConnectorObject user : handler) {
       System.out.println("Read User:" + user.getUid().getValue());
     }
   } finally {
     info.dispose();
   }
 }
 @Test
 public void testNegative() throws Exception {
   SpmlConfiguration config = createConfiguration();
   config.setPassword(new GuardedString("bogus".toCharArray()));
   try {
     createConnector(config);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   config = createConfiguration();
   config.setPostConnectCommand(null);
   SpmlConnector info = createConnector(config);
   try {
     Set<Attribute> attrs = fillInSampleUser(TEST_USER);
     info.create(ObjectClass.ACCOUNT, attrs, null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     info.delete(ObjectClass.ACCOUNT, new Uid(TEST_USER), null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     Set<Attribute> attrs = fillInSampleUser(TEST_USER);
     info.update(ObjectClass.ACCOUNT, attrs, null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     TestHandler handler = new TestHandler();
     TestHelpers.search(
         info,
         ObjectClass.ACCOUNT,
         new EqualsFilter(AttributeBuilder.build(Uid.NAME, "asdhjfdaslfh alsk fhasldk ")),
         handler,
         null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
 }
  private ConnectorObject getUser(String accountId, OperationOptions options) throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);

    try {
      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Name.NAME, accountId)),
          handler,
          options);
      if (!handler.iterator().hasNext()) return null;
      return handler.iterator().next();
    } catch (UnknownUidException e) {
      return null;
    } finally {
      info.dispose();
    }
  }
  @Test // @Ignore
  public void testSearchSpecifiedUser() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      deleteUser(TEST_USER, info);
      Uid createdUserUid = info.create(ObjectClass.ACCOUNT, attrs, null);

      // Simple test of EqualsFilter
      //
      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      boolean found = false;
      int count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count == 1);
      Assert.assertTrue(found);

      // Simple test of StartsWithFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new StartsWithFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME))
                .startsWith("User"));
      }
      Assert.assertTrue(found);

      // Simple test of EndsWithFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EndsWithFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME)).endsWith("User"));
      }
      Assert.assertTrue(found);

      // Simple test of ContainsFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new ContainsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME)).contains("User"));
      }
      Assert.assertTrue(found);

      // Simple test of EqualsFilter
      //
      {
        handler = new TestHandler();
        TestHelpers.search(
            info, ObjectClass.ACCOUNT, new EqualsFilter(createdUserUid), handler, null);
        found = false;
        count = 0;
        for (ConnectorObject user : handler) {
          if (TEST_USER.equals(user.getName().getNameValue())) found = true;
          count++;
        }
        Assert.assertTrue(count == 1);
        Assert.assertTrue(found);
      }

      // Test of And
      //
      handler = new TestHandler();
      Filter filter =
          new AndFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }

      Assert.assertTrue(count == 1);
      Assert.assertTrue(found);

      // Change the first name
      //
      ConnectorObject updateUser = getUser(TEST_USER);
      Set<Attribute> changed = new HashSet<Attribute>();
      changed.add(AttributeBuilder.build(ATTR_FIRSTNAME, "abel"));
      changed.add(updateUser.getUid());
      info.update(ObjectClass.ACCOUNT, changed, null);

      // Test of And, which should fail, since firstname has changed
      //
      handler = new TestHandler();
      filter =
          new AndFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count == 0);
      Assert.assertTrue(!found);

      // Test of Or, which should succeed, since lastname has not changed
      //
      handler = new TestHandler();
      filter =
          new OrFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count > 0);
      Assert.assertTrue(found);

    } finally {
      info.dispose();
    }
  }