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"));
}
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());
}
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());
}
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());
}
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());
}
Aggregations