@Test public void handlerMappingOrder() { HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class)); HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class)); when(((Ordered) hm1).getOrder()).thenReturn(1); when(((Ordered) hm2).getOrder()).thenReturn(2); when((hm1).getHandler(any())).thenReturn(Mono.just((Supplier<String>) () -> "1")); when((hm2).getHandler(any())).thenReturn(Mono.just((Supplier<String>) () -> "2")); StaticApplicationContext context = new StaticApplicationContext(); context.registerBean("b2", HandlerMapping.class, () -> hm2); context.registerBean("b1", HandlerMapping.class, () -> hm1); context.registerBean(HandlerAdapter.class, SupplierHandlerAdapter::new); context.registerBean(HandlerResultHandler.class, StringHandlerResultHandler::new); context.refresh(); DispatcherHandler dispatcherHandler = new DispatcherHandler(context); MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); dispatcherHandler.handle(exchange).block(Duration.ofSeconds(0)); assertEquals("1", exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5))); }
@Test public void invokedAsynchronouslyOnProxyTarget() { StaticApplicationContext context = new StaticApplicationContext(); context.registerBeanDefinition("postProcessor", new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class)); TestBean tb = new TestBean(); ProxyFactory pf = new ProxyFactory(ITestBean.class, (MethodInterceptor) invocation -> invocation.getMethod().invoke(tb, invocation.getArguments())); context.registerBean("target", ITestBean.class, () -> (ITestBean) pf.getProxy()); context.refresh(); ITestBean testBean = context.getBean("target", ITestBean.class); testBean.test(); Thread mainThread = Thread.currentThread(); testBean.await(3000); Thread asyncThread = testBean.getThread(); assertNotSame(mainThread, asyncThread); context.close(); }
@Before public void setup() throws Exception { this.publisherObjectName = ObjectNameManager.getInstance("test:type=publisher"); this.context.registerBean("mbeanServer", MBeanServerFactoryBean.class, MBeanServerFactoryBean::new); this.context.registerSingleton("exporter", IntegrationMBeanExporter.class, new MutablePropertyValues() .add("server", new RuntimeBeanReference("mbeanServer"))); this.context.registerSingleton("anotherExporter", MBeanExporter.class); RootBeanDefinition publisherDefinition = new RootBeanDefinition(NotificationPublishingMessageHandler.class); publisherDefinition.getConstructorArgumentValues().addGenericArgumentValue(this.publisherObjectName); publisherDefinition.getPropertyValues().add("defaultNotificationType", "test.type"); context.registerBeanDefinition("testPublisher", publisherDefinition); context.refresh(); MBeanExporter exporter = context.getBean(IntegrationMBeanExporter.class); exporter.getServer().addNotificationListener(publisherObjectName, this.listener, null, null); }