@Test
 public void eventBusElementTrueMBeans() {
   BeanDefinition beanDefinition = beanFactory.getBeanDefinition("eventBusTrueMBeans");
   assertNotNull("Bean definition not created", beanDefinition);
   assertEquals(
       "Wrong bean class", SimpleEventBus.class.getName(), beanDefinition.getBeanClassName());
   assertEquals(
       "wrong amount of constructor arguments",
       1,
       beanDefinition.getConstructorArgumentValues().getArgumentCount());
   Object constructorValue =
       beanDefinition.getConstructorArgumentValues().getArgumentValue(0, Boolean.class).getValue();
   assertTrue("constructor value is wrong", Boolean.parseBoolean((String) constructorValue));
   SimpleEventBus eventBus = beanFactory.getBean("eventBusTrueMBeans", SimpleEventBus.class);
   assertNotNull(eventBus);
 }
  @SuppressWarnings("unchecked")
  public BeanDefinitionHolder decorate(
      Node node, BeanDefinitionHolder holder, ParserContext parserContext) {
    BeanDefinition filterChainProxy = holder.getBeanDefinition();

    ManagedList<BeanMetadataElement> securityFilterChains = new ManagedList<BeanMetadataElement>();
    Element elt = (Element) node;

    MatcherType matcherType = MatcherType.fromElement(elt);

    List<Element> filterChainElts = DomUtils.getChildElementsByTagName(elt, Elements.FILTER_CHAIN);

    for (Element chain : filterChainElts) {
      String path = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
      String filters = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS);

      if (!StringUtils.hasText(path)) {
        parserContext
            .getReaderContext()
            .error(
                "The attribute '"
                    + HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN
                    + "' must not be empty",
                elt);
      }

      if (!StringUtils.hasText(filters)) {
        parserContext
            .getReaderContext()
            .error(
                "The attribute '"
                    + HttpSecurityBeanDefinitionParser.ATT_FILTERS
                    + "'must not be empty",
                elt);
      }

      BeanDefinition matcher = matcherType.createMatcher(parserContext, path, null);

      if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) {
        securityFilterChains.add(createSecurityFilterChain(matcher, new ManagedList(0)));
      } else {
        String[] filterBeanNames = StringUtils.tokenizeToStringArray(filters, ",");
        ManagedList filterChain = new ManagedList(filterBeanNames.length);

        for (String name : filterBeanNames) {
          filterChain.add(new RuntimeBeanReference(name));
        }

        securityFilterChains.add(createSecurityFilterChain(matcher, filterChain));
      }
    }

    filterChainProxy.getConstructorArgumentValues().addGenericArgumentValue(securityFilterChains);

    return holder;
  }
  @Test
  public void eventBusElementWithTerminal() {
    BeanDefinition beanDefinition = beanFactory.getBeanDefinition("eventBusTerminal");
    assertNotNull("Bean definition not created", beanDefinition);
    assertEquals(
        "Wrong bean class", SimpleEventBus.class.getName(), beanDefinition.getBeanClassName());
    assertEquals(
        "wrong amount of constructor arguments",
        1,
        beanDefinition.getConstructorArgumentValues().getArgumentCount());

    BeanReference terminalRef =
        (BeanReference)
            beanDefinition
                .getConstructorArgumentValues()
                .getArgumentValue(0, BeanReference.class)
                .getValue();
    assertEquals("constructor value is wrong", "terminal", terminalRef.getBeanName());
    assertNotNull(beanFactory.getBean("eventBusTerminal", EventBus.class));
  }
  /** @see DATAMONGO-1218 */
  @Test
  public void setsUpMongoDbFactoryUsingAMongoClientUri() {

    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-client-uri.xml"));
    BeanDefinition definition = factory.getBeanDefinition("mongoDbFactory");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();

    assertThat(constructorArguments.getArgumentCount(), is(1));
    ValueHolder argument = constructorArguments.getArgumentValue(0, MongoClientURI.class);
    assertThat(argument, is(notNullValue()));
  }
  @Test
  public void eventBusElement() {
    BeanDefinition beanDefinition = beanFactory.getBeanDefinition("eventBus");
    assertNotNull("Bean definition not created", beanDefinition);
    assertEquals(
        "Wrong bean class", SimpleEventBus.class.getName(), beanDefinition.getBeanClassName());
    assertEquals(
        "wrong amount of constructor arguments",
        0,
        beanDefinition.getConstructorArgumentValues().getArgumentCount());

    EventBus eventBus = beanFactory.getBean("eventBus", EventBus.class);
    assertNotNull(eventBus);
  }
  /** @see DATAMONGO-306 */
  @Test
  public void setsUpMongoDbFactoryUsingAMongoUriWithoutCredentials() {

    reader.loadBeanDefinitions(new ClassPathResource("namespace/mongo-uri-no-credentials.xml"));
    BeanDefinition definition = factory.getBeanDefinition("mongoDbFactory");
    ConstructorArgumentValues constructorArguments = definition.getConstructorArgumentValues();

    assertThat(constructorArguments.getArgumentCount(), is(1));
    ValueHolder argument = constructorArguments.getArgumentValue(0, MongoURI.class);
    assertThat(argument, is(notNullValue()));

    MongoDbFactory dbFactory = factory.getBean("mongoDbFactory", MongoDbFactory.class);
    DB db = dbFactory.getDb();
    assertThat(db.getName(), is("database"));
  }
 /**
  * Register the specified entity scan packages with the system.
  *
  * @param registry the source registry
  * @param packageNames the package names to register
  */
 public static void register(BeanDefinitionRegistry registry, Collection<String> packageNames) {
   Assert.notNull(registry, "Registry must not be null");
   Assert.notNull(packageNames, "PackageNames must not be null");
   if (registry.containsBeanDefinition(BEAN)) {
     BeanDefinition beanDefinition = registry.getBeanDefinition(BEAN);
     ConstructorArgumentValues constructorArguments =
         beanDefinition.getConstructorArgumentValues();
     constructorArguments.addIndexedArgumentValue(
         0, addPackageNames(constructorArguments, packageNames));
   } else {
     GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
     beanDefinition.setBeanClass(EntityScanPackages.class);
     beanDefinition
         .getConstructorArgumentValues()
         .addIndexedArgumentValue(0, packageNames.toArray(new String[packageNames.size()]));
     beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
     registry.registerBeanDefinition(BEAN, beanDefinition);
   }
 }
  @Test
  public void parseInternal_withCustomAmazonSnsClient_shouldPassItAsConstructorArg()
      throws Exception {
    // Arrange
    SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);

    // Act
    reader.loadBeanDefinitions(
        new ClassPathResource(getClass().getSimpleName() + "-custom-amazon-sns.xml", getClass()));

    // Assert
    BeanDefinition notificationMessagingTemplateBeanDefinition =
        registry.getBeanDefinition("notificationMessagingTemplate");
    assertEquals(
        "mySnsClient",
        ((RuntimeBeanReference)
                notificationMessagingTemplateBeanDefinition
                    .getConstructorArgumentValues()
                    .getArgumentValue(0, RuntimeBeanReference.class)
                    .getValue())
            .getBeanName());
  }