Search in sources :

Example 1 with Initializable

use of org.olat.core.configuration.Initializable in project OpenOLAT by OpenOLAT.

the class SpringInitDestroyVerficationTest method testInitMethodCalls.

@Test
public void testInitMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Initializable> beans = applicationContext.getBeansOfType(Initializable.class);
    for (Iterator<String> iterator = beans.keySet().iterator(); iterator.hasNext(); ) {
        String beanName = iterator.next();
        try {
            GenericBeanDefinition beanDef = (GenericBeanDefinition) beanFactory.getBeanDefinition(beanName);
            assertNotNull("Spring Bean (" + beanName + ") of type Initializable does not have the required init-method attribute or the method name is not init!", beanDef.getInitMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Initializable does not have the required init-method attribute or the method name is not init!", beanDef.getInitMethodName().equals("init"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testInitMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testInitMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        }
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Initializable(org.olat.core.configuration.Initializable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 2 with Initializable

use of org.olat.core.configuration.Initializable in project openolat by klemens.

the class SpringInitDestroyVerficationTest method testInitMethodCalls.

@Test
public void testInitMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Initializable> beans = applicationContext.getBeansOfType(Initializable.class);
    for (Iterator<String> iterator = beans.keySet().iterator(); iterator.hasNext(); ) {
        String beanName = iterator.next();
        try {
            GenericBeanDefinition beanDef = (GenericBeanDefinition) beanFactory.getBeanDefinition(beanName);
            assertNotNull("Spring Bean (" + beanName + ") of type Initializable does not have the required init-method attribute or the method name is not init!", beanDef.getInitMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Initializable does not have the required init-method attribute or the method name is not init!", beanDef.getInitMethodName().equals("init"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testInitMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testInitMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        }
    }
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) Initializable(org.olat.core.configuration.Initializable) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Initializable (org.olat.core.configuration.Initializable)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)2 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)2