Search in sources :

Example 1 with Destroyable

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

the class SpringInitDestroyVerficationTest method testDestroyMethodCalls.

@Test
public void testDestroyMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Destroyable> beans = applicationContext.getBeansOfType(Destroyable.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 Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName().equals("destroy"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testDestroyMethodCalls: 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) Destroyable(org.olat.core.configuration.Destroyable) 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 Destroyable

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

the class SpringInitDestroyVerficationTest method testDestroyMethodCalls.

@Test
public void testDestroyMethodCalls() {
    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    Map<String, Destroyable> beans = applicationContext.getBeansOfType(Destroyable.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 Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName());
            if (beanDef.getDestroyMethodName() != null) {
                assertTrue("Spring Bean (" + beanName + ") of type Destroyable does not have the required destroy-method attribute or the method name is not destroy!", beanDef.getDestroyMethodName().equals("destroy"));
            }
        } catch (NoSuchBeanDefinitionException e) {
            log.error("testDestroyMethodCalls: Error while trying to analyze bean with name: " + beanName + " :" + e);
        } catch (Exception e) {
            log.error("testDestroyMethodCalls: 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) Destroyable(org.olat.core.configuration.Destroyable) 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 Destroyable (org.olat.core.configuration.Destroyable)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