コード例 #1
0
  @Test
  public void testRenameAndLookup() {
    final LdapName name1 =
        LdapUtils.createLdapName(
            RECORD.getNodeTypeName(), "TestEren3",
            IOC.getNodeTypeName(), "TestEcon2",
            COMPONENT.getNodeTypeName(), "TestEcom2",
            FACILITY.getNodeTypeName(), EFAN_NAME,
            UNIT.getNodeTypeName(), UNIT.getUnitTypeValue());

    final LdapName name2 =
        LdapUtils.createLdapName(
            RECORD.getNodeTypeName(), "NedFlanders",
            IOC.getNodeTypeName(), "TestEcon2",
            COMPONENT.getNodeTypeName(), "TestEcom2",
            FACILITY.getNodeTypeName(), EFAN_NAME,
            UNIT.getNodeTypeName(), UNIT.getUnitTypeValue());

    try {
      LDAP_SERVICE.rename(name1, name2);
      Assert.assertNotNull(LDAP_SERVICE.lookup(name2));
      LDAP_SERVICE.rename(name2, name1);
      Assert.assertNotNull(LDAP_SERVICE.lookup(name1));
    } catch (final NamingException e) {
      Assert.fail("Rename failed");
    }
  }
コード例 #2
0
  @Test
  public void testLdapReaderJob() {
    final LdapName name =
        LdapUtils.createLdapName(
            FACILITY.getNodeTypeName(), EFAN_NAME, UNIT.getNodeTypeName(), UNIT.getUnitTypeValue());

    final Holder<Boolean> read = new Holder<Boolean>(Boolean.FALSE);
    final ILdapReaderJob job =
        LDAP_SERVICE.createLdapReaderJob(
            new LdapSearchParams(name, LdapUtils.any(RECORD.getNodeTypeName())),
            new ILdapReadCompletedCallback() {
              @Override
              public void onLdapReadComplete() {
                read.setValue(Boolean.TRUE);
              }
            });
    job.schedule();
    try {
      job.join();
    } catch (final InterruptedException e) {
      Assert.fail("Not supposed to be interrupted.");
    }
    Assert.assertTrue(read.getValue());
    Assert.assertEquals(4, job.getSearchResult().getAnswerSet().size());
  }
コード例 #3
0
  @Test
  public void testLdapContentModelBuilder() {
    final LdapName name =
        LdapUtils.createLdapName(
            FACILITY.getNodeTypeName(), EFAN_NAME, UNIT.getNodeTypeName(), UNIT.getUnitTypeValue());
    final ILdapSearchResult result =
        LDAP_SERVICE.retrieveSearchResultSynchronously(
            name, LdapUtils.any(RECORD.getNodeTypeName()), SearchControls.SUBTREE_SCOPE);
    Assert.assertNotNull(result);

    try {
      final ILdapContentModelBuilder<LdapEpicsControlsConfiguration> builder =
          LDAP_SERVICE.getLdapContentModelBuilder(VIRTUAL_ROOT, result);
      Assert.assertNotNull(builder);
      builder.build();
      final ContentModel<LdapEpicsControlsConfiguration> model = builder.getModel();
      final Map<String, INodeComponent<LdapEpicsControlsConfiguration>> records =
          model.getByType(RECORD);
      Assert.assertEquals(4, records.size());
    } catch (final CreateContentModelException e) {
      Assert.fail("Content model could not be created.");
    } catch (LdapServiceException e) {
      Assert.fail("Content model could not be created.");
    }
  }
コード例 #4
0
  /**
   * Tests the service method {@link ILdapService#removeComponent(Enum, LdapName)} and consequently
   * the {@link ILdapService#removeLeafComponent(LdapName)}.
   */
  @AfterClass
  public static void removeTestLdapStructure() {

    final LdapName name =
        LdapUtils.createLdapName(
            FACILITY.getNodeTypeName(), EFAN_NAME, UNIT.getNodeTypeName(), UNIT.getUnitTypeValue());
    try {
      Assert.assertTrue(LDAP_SERVICE.removeComponent(VIRTUAL_ROOT, name));
    } catch (final InvalidNameException e) {
      Assert.fail("Unexpected exception:\n" + e.getMessage());
    } catch (final CreateContentModelException e) {
      Assert.fail("Content model could not be created:\n" + e.getMessage());
    } catch (LdapServiceException e) {
      Assert.fail("Content model could not be created:\n" + e.getMessage());
    }
  }
コード例 #5
0
  @Test
  public void testAttributeAccess() {
    final LdapName name =
        LdapUtils.createLdapName(
            IOC.getNodeTypeName(),
            "TestEcon2",
            COMPONENT.getNodeTypeName(),
            "TestEcom2",
            FACILITY.getNodeTypeName(),
            EFAN_NAME,
            UNIT.getNodeTypeName(),
            UNIT.getUnitTypeValue());

    try {
      Attributes attrs = LDAP_SERVICE.getAttributes(name);
      Assert.assertNotNull(attrs);
      Attribute attr = attrs.get(ATTR_FIELD_RESPONSIBLE_PERSON);
      Assert.assertNotNull(attr);
      String value = (String) attr.get();
      Assert.assertEquals("*****@*****.**", value);

      ModificationItem[] items =
          new ModificationItem[] {new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr)};
      LDAP_SERVICE.modifyAttributes(name, items);

      attrs = LDAP_SERVICE.getAttributes(name);
      Assert.assertNotNull(attrs);
      final Attribute attrNull = attrs.get(ATTR_FIELD_RESPONSIBLE_PERSON);
      Assert.assertNull(attrNull);

      items = new ModificationItem[] {new ModificationItem(DirContext.ADD_ATTRIBUTE, attr)};
      LDAP_SERVICE.modifyAttributes(name, items);

      attrs = LDAP_SERVICE.getAttributes(name);
      Assert.assertNotNull(attrs);
      attr = attrs.get(ATTR_FIELD_RESPONSIBLE_PERSON);
      Assert.assertNotNull(attr);
      value = (String) attr.get();
      Assert.assertEquals("*****@*****.**", value);

    } catch (final NamingException e) {
      Assert.fail("Unexpected Exception on attribute modification.");
    }
  }