@Test(expected = NoSuchBeanDefinitionException.class) public void testGetAbstractContextSourceFromApplicationContextTwoContextSources() throws Exception { when(applicationContextMock .getBeanNamesForType(BaseLdapPathSource.class)).thenReturn(new String[2]); tested.getBaseLdapPathSourceFromApplicationContext(); }
@Test(expected = NoSuchBeanDefinitionException.class) public void testGetAbstractContextSourceFromApplicationContextNoContextSource() throws Exception { when(applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)) .thenReturn(new String[0]); tested.getBaseLdapPathSourceFromApplicationContext(); }
@Test public void testGetAbstractContextSourceFromApplicationContext() throws Exception { when(applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)) .thenReturn(new String[]{"contextSource"}); final LdapContextSource expectedContextSource = new LdapContextSource(); HashMap<String, BaseLdapPathSource> expectedBeans = new HashMap<String, BaseLdapPathSource>() {{ put("dummy", expectedContextSource); }}; when(applicationContextMock.getBeansOfType(BaseLdapPathSource.class)).thenReturn(expectedBeans); BaseLdapPathSource result = tested.getBaseLdapPathSourceFromApplicationContext(); assertThat(result).isSameAs(expectedContextSource); }
@Test public void testGetAbstractContextSourceFromApplicationContextTwoContextSourcesAndSpecifiedName() throws Exception { LdapContextSource expectedContextSource = new LdapContextSource(); tested.setBaseLdapPathSourceName("myContextSource"); when(applicationContextMock.getBean("myContextSource")).thenReturn(expectedContextSource); tested.getBaseLdapPathSourceFromApplicationContext(); } }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if(bean instanceof BaseLdapNameAware) { BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean; if (basePath != null) { baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName())); } } else if (bean instanceof BaseLdapPathAware) { BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean; if (basePath != null) { baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName()); } } return bean; }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if(bean instanceof BaseLdapNameAware) { BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean; if (basePath != null) { baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName())); } } else if (bean instanceof BaseLdapPathAware) { BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean; if (basePath != null) { baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName()); } } return bean; }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if(bean instanceof BaseLdapNameAware) { BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean; if (basePath != null) { baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName())); } } else if (bean instanceof BaseLdapPathAware) { BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean; if (basePath != null) { baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName()); } } return bean; }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if(bean instanceof BaseLdapNameAware) { BaseLdapNameAware baseLdapNameAware = (BaseLdapNameAware) bean; if (basePath != null) { baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapNameAware.setBaseLdapPath(LdapUtils.newLdapName(ldapPathSource.getBaseLdapName())); } } else if (bean instanceof BaseLdapPathAware) { BaseLdapPathAware baseLdapPathAware = (BaseLdapPathAware) bean; if (basePath != null) { baseLdapPathAware.setBaseLdapPath(new DistinguishedName(basePath)); } else { BaseLdapPathSource ldapPathSource = getBaseLdapPathSourceFromApplicationContext(); baseLdapPathAware.setBaseLdapPath(ldapPathSource.getBaseLdapPath().immutableDistinguishedName()); } } return bean; }