@Test(expected = NoSuchBeanDefinitionException.class) public void testGetAbstractContextSourceFromApplicationContextTwoContextSources() throws Exception { when(applicationContextMock .getBeanNamesForType(BaseLdapPathSource.class)).thenReturn(new String[2]); tested.getBaseLdapPathSourceFromApplicationContext(); }
BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() { if (StringUtils.hasLength(baseLdapPathSourceName)) { return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class); } Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values(); if (beans.isEmpty()) { throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found"); } else if (beans.size() == 1) { return beans.iterator().next(); } else { BaseLdapPathSource found = null; for (BaseLdapPathSource bean : beans) { if(bean instanceof AbstractContextSource) { if(found != null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use. Please specify 'baseLdapPathSourceName'"); } found = bean; } } if(found == null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use (one of them should be an AbstractContextSource instance). " + "Please specify 'baseLdapPathSourceName'"); } return found; } }
BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered { BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() { if (StringUtils.hasLength(baseLdapPathSourceName)) { return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class); } Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values(); if (beans.isEmpty()) { throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found"); } else if (beans.size() == 1) { return beans.iterator().next(); } else { BaseLdapPathSource found = null; for (BaseLdapPathSource bean : beans) { if(bean instanceof AbstractContextSource) { if(found != null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use. Please specify 'baseLdapPathSourceName'"); } found = bean; } } if(found == null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use (one of them should be an AbstractContextSource instance). " + "Please specify 'baseLdapPathSourceName'"); } return found; } } }
BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered { BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() { if (StringUtils.hasLength(baseLdapPathSourceName)) { return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class); } Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values(); if (beans.isEmpty()) { throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found"); } else if (beans.size() == 1) { return beans.iterator().next(); } else { BaseLdapPathSource found = null; for (BaseLdapPathSource bean : beans) { if(bean instanceof AbstractContextSource) { if(found != null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use. Please specify 'baseLdapPathSourceName'"); } found = bean; } } if(found == null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use (one of them should be an AbstractContextSource instance). " + "Please specify 'baseLdapPathSourceName'"); } return found; } }  }
BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered { BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() { if (StringUtils.hasLength(baseLdapPathSourceName)) { return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class); } Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values(); if (beans.isEmpty()) { throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found"); } else if (beans.size() == 1) { return beans.iterator().next(); } else { BaseLdapPathSource found = null; for (BaseLdapPathSource bean : beans) { if(bean instanceof AbstractContextSource) { if(found != null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use. Please specify 'baseLdapPathSourceName'"); } found = bean; } } if(found == null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use (one of them should be an AbstractContextSource instance). " + "Please specify 'baseLdapPathSourceName'"); } return found; } }  @Override Object postProcessBeforeInitialization(Object bean, String beanName); @Override Object postProcessAfterInitialization(Object bean, String beanName); @Override void setApplicationContext(ApplicationContext applicationContext); void setBasePath(DistinguishedName basePath); void setBasePath(String basePath); void setBaseLdapPathSourceName(String contextSourceName); void setOrder(int order); int getOrder(); }
BaseLdapPathBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware, Ordered { BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() { if (StringUtils.hasLength(baseLdapPathSourceName)) { return applicationContext.getBean(baseLdapPathSourceName, BaseLdapPathSource.class); } Collection<BaseLdapPathSource> beans = applicationContext.getBeansOfType(BaseLdapPathSource.class).values(); if (beans.isEmpty()) { throw new NoSuchBeanDefinitionException("No BaseLdapPathSource implementation definition found"); } else if (beans.size() == 1) { return beans.iterator().next(); } else { BaseLdapPathSource found = null; for (BaseLdapPathSource bean : beans) { if(bean instanceof AbstractContextSource) { if(found != null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use. Please specify 'baseLdapPathSourceName'"); } found = bean; } } if(found == null) { throw new NoSuchBeanDefinitionException( "More than BaseLdapPathSource implementation definition found in current ApplicationContext; " + "unable to determine the one to use (one of them should be an AbstractContextSource instance). " + "Please specify 'baseLdapPathSourceName'"); } return found; } }  @Override Object postProcessBeforeInitialization(Object bean, String beanName); @Override Object postProcessAfterInitialization(Object bean, String beanName); @Override void setApplicationContext(ApplicationContext applicationContext); void setBasePath(DistinguishedName basePath); void setBasePath(String basePath); void setBaseLdapPathSourceName(String contextSourceName); void setOrder(int order); int getOrder();  }