Beispiel #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");
    }
  }
Beispiel #2
0
  @SuppressWarnings("unchecked")
  private void resolveAllProxies() {
    boolean beansResolved = false;

    final Iterator<Map.Entry<BeanRef, List<ProxyResolver>>> unresolvedIterator =
        new LinkedHashMap<BeanRef, List<ProxyResolver>>(unresolvedProxies).entrySet().iterator();

    final int initialSize = unresolvedProxies.size();

    while (unresolvedIterator.hasNext()) {
      final Map.Entry<BeanRef, List<ProxyResolver>> entry = unresolvedIterator.next();
      if (wired.containsKey(entry.getKey())) {
        final Object wiredInst = wired.get(entry.getKey());
        for (final ProxyResolver pr : entry.getValue()) {
          pr.resolve(wiredInst);
        }

        final Iterator<Tuple<Object, InitializationCallback>> initCallbacks =
            initializationCallbacks.iterator();
        while (initCallbacks.hasNext()) {
          final Tuple<Object, InitializationCallback> tuple = initCallbacks.next();
          if (tuple.getKey() == wiredInst) {
            tuple.getValue().init(tuple.getKey());
            initCallbacks.remove();
          }
        }

        unresolvedIterator.remove();
      } else {
        final IOCBeanDef<?> iocBeanDef =
            IOC.getBeanManager()
                .lookupBean(entry.getKey().getClazz(), entry.getKey().getAnnotations());

        if (iocBeanDef != null) {
          if (!wired.containsKey(entry.getKey())) {
            addBean(
                getBeanReference(entry.getKey().getClazz(), entry.getKey().getAnnotations()),
                iocBeanDef.getInstance(this));
          }

          beansResolved = true;
        }
      }
    }

    if (beansResolved) {
      resolveAllProxies();
    } else if (!unresolvedProxies.isEmpty() && initialSize != unresolvedProxies.size()) {
      throw new RuntimeException(
          "unresolved proxy: " + unresolvedProxies.entrySet().iterator().next().getKey());
    }
  }
Beispiel #3
0
  /**
   * Obtains an instance of the bean within the creational context based on the specified bean type
   * and qualifiers.
   *
   * @param beanType the type of the bean
   * @param qualifiers the qualifiers fo the bean
   * @param <T> the type of the bean
   * @return the actual instance of the bean
   */
  @SuppressWarnings("unchecked")
  public <T> T getBeanInstance(final Class<T> beanType, final Annotation[] qualifiers) {
    final T t = (T) wired.get(getBeanReference(beanType, qualifiers));
    if (t == null) {
      // see if the instance is available in the bean manager
      final Collection<IOCBeanDef<T>> beanList =
          IOC.getBeanManager().lookupBeans(beanType, qualifiers);

      if (!beanList.isEmpty()) {
        final IOCBeanDef<T> bean = beanList.iterator().next();
        if (bean != null && bean instanceof IOCSingletonBean) {
          return bean.getInstance();
        }
      }
    }
    return t;
  }
Beispiel #4
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.");
    }
  }