@Test
  public void testReadAlterAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals(OracleAuthentication.LOCAL, caAttributes.getAuth());
    Assert.assertNotNull("Password must not be null", caAttributes.getPassword());

    // verify that password is not set for alter when not set
    caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    attributes.clear();
    attributes.add(AttributeBuilder.buildPasswordExpired(true));
    reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertNull("Password must be null", caAttributes.getPassword());

    // try to update authentication to null
    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    try {
      reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Create attributes must fail for null authentication");
    } catch (IllegalArgumentException e) {
    }
  }
 @BeforeClass
 public static void before() {
   PropertyBag testProps = TestHelpers.getProperties(WrqConnection.class);
   HOST_NAME = testProps.getStringProperty("HOST_NAME");
   SYSTEM_PASSWORD = testProps.getStringProperty("SYSTEM_PASSWORD");
   SYSTEM_USER = testProps.getStringProperty("SYSTEM_USER");
   System.out.println("HOST_NAME=" + HOST_NAME);
   System.out.println("SYSTEM_USER=" + SYSTEM_USER);
 }
  /**
   * Test method for {@link
   * org.identityconnectors.oracle.OracleAttributesReader#readAuthAttributes(java.util.Set,
   * org.identityconnectors.oracle.OracleUserAttributes)}.
   */
  @Test
  public final void testReadCreateAuthAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals(OracleAuthentication.LOCAL, caAttributes.getAuth());
    Assert.assertNotNull("Password must not be null", caAttributes.getPassword());

    attributes.clear();
    caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertNull("Should not set authentication to any default value", caAttributes.getAuth());
    Assert.assertNull("Password must be null", caAttributes.getPassword());

    // Test for failures
    attributes.clear();
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, "invalid authentication"));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for invalid authentication");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_GLOBAL));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for missing global name");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_GLOBAL));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_GLOBAL_ATTR_NAME, ""));

    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty global name");
    } catch (RuntimeException e) {
    }
  }
  @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();
    }
  }
 @BeforeClass
 public static void before() {
   PropertyBag testProps = TestHelpers.getProperties(SpmlConnector.class);
   HOST_NAME = testProps.getStringProperty("HOST_NAME");
   SYSTEM_PASSWORD = testProps.getStringProperty("SYSTEM_PASSWORD");
   SYSTEM_USER = testProps.getStringProperty("SYSTEM_USER");
   TEST_USER = "******";
   Assert.assertNotNull("HOST_NAME must be specified", HOST_NAME);
   Assert.assertNotNull("SYSTEM_PASSWORD must be specified", SYSTEM_PASSWORD);
   Assert.assertNotNull("SYSTEM_USER must be specified", SYSTEM_USER);
 }
 @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();
    }
  }
 /**
  * @param configName
  * @throws NoSuchFieldException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  * @throws NoSuchMethodException
  * @throws SecurityException
  */
 public void loadConfiguration(final String configName, Configuration cfg) {
   Map<String, ? extends Object> propMap = getPropertyMap(configName);
   assertNotNull(propMap);
   TestHelpers.fillConfiguration(cfg, propMap);
 }
  /**
   * Test method for {@link
   * org.identityconnectors.oracle.OracleAttributesReader#readRestAttributes(java.util.Set,
   * org.identityconnectors.oracle.OracleUserAttributes)}.
   */
  @Test
  public final void testReadCreateRestAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.buildPasswordExpired(true));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME, "defts"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME, "tempts"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME, "myprofile"));
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_QUOTA_ATTR_NAME, "30M"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_QUOTA_ATTR_NAME, "100M"));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals("defts", caAttributes.getDefaultTableSpace());
    Assert.assertEquals(true, caAttributes.getExpirePassword());
    Assert.assertEquals("tempts", caAttributes.getTempTableSpace());
    Assert.assertEquals("myprofile", caAttributes.getProfile());
    Assert.assertEquals(true, caAttributes.getEnable());
    Assert.assertEquals("30M", caAttributes.getDefaultTSQuota());
    Assert.assertEquals("100M", caAttributes.getTempTSQuota());

    // Test for failures
    attributes.clear();
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_EXPIRED_NAME, "invalid"));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for invalid PASSWORD_EXPIRED_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_EXPIRED_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null PASSWORD_EXPIRED_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_DEF_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_DEF_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_TEMP_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_TEMP_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_PROFILE_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_PROFILE_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_QUOTA_ATTR_NAME));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    assertEquals("Must set 0 for null quota", "0", caAttributes.getDefaultTSQuota());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_QUOTA_ATTR_NAME, ""));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    assertEquals("Must set 0 for null quota", "0", caAttributes.getTempTSQuota());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildLockOut(true));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertFalse("Enabled must be false for lock_out(true)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildLockOut(false));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertTrue("Enabled must be true for lock_out(false)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(false));
    attributes.add(AttributeBuilder.buildLockOut(true));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertFalse(
        "Enabled must be false for enabled(false) and lock_out(true)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.buildLockOut(false));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertTrue(
        "Enabled must be true for enabled(true) and lock_out(false)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.buildLockOut(true));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Read attributes must fail for enabled(true) nad lockout(true)");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(false));
    attributes.add(AttributeBuilder.buildLockOut(false));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Read attributes must fail for enabled(false) nad lockout(false)");
    } catch (RuntimeException e) {
    }
  }