Search in sources :

Example 51 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class JmsNamespaceHandlerTests method testJcaContainerConfiguration.

@Test
public void testJcaContainerConfiguration() throws Exception {
    Map<String, JmsMessageEndpointManager> containers = context.getBeansOfType(JmsMessageEndpointManager.class);
    assertTrue("listener3 not found", containers.containsKey("listener3"));
    JmsMessageEndpointManager listener3 = containers.get("listener3");
    assertEquals("Wrong resource adapter", context.getBean("testResourceAdapter"), listener3.getResourceAdapter());
    assertEquals("Wrong activation spec factory", context.getBean("testActivationSpecFactory"), new DirectFieldAccessor(listener3).getPropertyValue("activationSpecFactory"));
    Object endpointFactory = new DirectFieldAccessor(listener3).getPropertyValue("endpointFactory");
    Object messageListener = new DirectFieldAccessor(endpointFactory).getPropertyValue("messageListener");
    assertEquals("Wrong message listener", MessageListenerAdapter.class, messageListener.getClass());
    MessageListenerAdapter adapter = (MessageListenerAdapter) messageListener;
    DirectFieldAccessor adapterFieldAccessor = new DirectFieldAccessor(adapter);
    assertEquals("Message converter not set properly", context.getBean("testMessageConverter"), adapterFieldAccessor.getPropertyValue("messageConverter"));
    assertEquals("Wrong delegate", context.getBean("testBean1"), adapterFieldAccessor.getPropertyValue("delegate"));
    assertEquals("Wrong method name", "setName", adapterFieldAccessor.getPropertyValue("defaultListenerMethod"));
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) JmsMessageEndpointManager(org.springframework.jms.listener.endpoint.JmsMessageEndpointManager) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 52 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class ScheduledTasksBeanDefinitionParserTests method checkTarget.

@Test
public void checkTarget() {
    List<IntervalTask> tasks = (List<IntervalTask>) new DirectFieldAccessor(this.registrar).getPropertyValue("fixedRateTasks");
    Runnable runnable = tasks.get(0).getRunnable();
    assertEquals(ScheduledMethodRunnable.class, runnable.getClass());
    Object targetObject = ((ScheduledMethodRunnable) runnable).getTarget();
    Method targetMethod = ((ScheduledMethodRunnable) runnable).getMethod();
    assertEquals(this.testBean, targetObject);
    assertEquals("test", targetMethod.getName());
}
Also used : ScheduledMethodRunnable(org.springframework.scheduling.support.ScheduledMethodRunnable) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ScheduledMethodRunnable(org.springframework.scheduling.support.ScheduledMethodRunnable) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 53 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class ScheduledAnnotationBeanPostProcessorTests method composedAnnotationWithInitialDelayAndFixedRate.

@Test
public void composedAnnotationWithInitialDelayAndFixedRate() {
    BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
    BeanDefinition targetDefinition = new RootBeanDefinition(ComposedAnnotationFixedRateTestBean.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);
    context.registerBeanDefinition("target", targetDefinition);
    context.refresh();
    Object postProcessor = context.getBean("postProcessor");
    Object target = context.getBean("target");
    ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked") List<IntervalTask> fixedRateTasks = (List<IntervalTask>) new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("checkForUpdates", targetMethod.getName());
    assertEquals(5000L, task.getInterval());
    assertEquals(1000L, task.getInitialDelay());
}
Also used : ScheduledMethodRunnable(org.springframework.scheduling.support.ScheduledMethodRunnable) IntervalTask(org.springframework.scheduling.config.IntervalTask) ScheduledTaskRegistrar(org.springframework.scheduling.config.ScheduledTaskRegistrar) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) List(java.util.List) Method(java.lang.reflect.Method) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 54 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class ScheduledAnnotationBeanPostProcessorTests method nonVoidReturnType.

@Test
public void nonVoidReturnType() {
    BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
    BeanDefinition targetDefinition = new RootBeanDefinition(NonVoidReturnTypeTestBean.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);
    context.registerBeanDefinition("target", targetDefinition);
    context.refresh();
    Object postProcessor = context.getBean("postProcessor");
    Object target = context.getBean("target");
    ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked") List<CronTask> cronTasks = (List<CronTask>) new DirectFieldAccessor(registrar).getPropertyValue("cronTasks");
    assertEquals(1, cronTasks.size());
    CronTask task = cronTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("cron", targetMethod.getName());
    assertEquals("0 0 9-17 * * MON-FRI", task.getExpression());
}
Also used : ScheduledMethodRunnable(org.springframework.scheduling.support.ScheduledMethodRunnable) ScheduledTaskRegistrar(org.springframework.scheduling.config.ScheduledTaskRegistrar) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CronTask(org.springframework.scheduling.config.CronTask) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) List(java.util.List) Method(java.lang.reflect.Method) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 55 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class ScheduledAnnotationBeanPostProcessorTests method fixedRateTaskWithInitialDelay.

@Test
public void fixedRateTaskWithInitialDelay() {
    BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
    BeanDefinition targetDefinition = new RootBeanDefinition(FixedRateWithInitialDelayTestBean.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);
    context.registerBeanDefinition("target", targetDefinition);
    context.refresh();
    Object postProcessor = context.getBean("postProcessor");
    Object target = context.getBean("target");
    ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
    @SuppressWarnings("unchecked") List<IntervalTask> fixedRateTasks = (List<IntervalTask>) new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
    assertEquals(1, fixedRateTasks.size());
    IntervalTask task = fixedRateTasks.get(0);
    ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
    Object targetObject = runnable.getTarget();
    Method targetMethod = runnable.getMethod();
    assertEquals(target, targetObject);
    assertEquals("fixedRate", targetMethod.getName());
    assertEquals(1000L, task.getInitialDelay());
    assertEquals(3000L, task.getInterval());
}
Also used : ScheduledMethodRunnable(org.springframework.scheduling.support.ScheduledMethodRunnable) IntervalTask(org.springframework.scheduling.config.IntervalTask) ScheduledTaskRegistrar(org.springframework.scheduling.config.ScheduledTaskRegistrar) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) List(java.util.List) Method(java.lang.reflect.Method) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)95 Test (org.junit.Test)79 List (java.util.List)25 Method (java.lang.reflect.Method)16 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)15 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)15 ScheduledTaskRegistrar (org.springframework.scheduling.config.ScheduledTaskRegistrar)15 IntervalTask (org.springframework.scheduling.config.IntervalTask)8 CronTask (org.springframework.scheduling.config.CronTask)7 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)5 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)4 DataSourceTransactionManagerAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration)4 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)4 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)4 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 JdbcOperationsSessionRepository (org.springframework.session.jdbc.JdbcOperationsSessionRepository)4 ViewResolver (org.springframework.web.servlet.ViewResolver)4