Search in sources :

Example 96 with DirectFieldAccessor

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

the class RedisInboundChannelAdapterParserTests method validateConfiguration.

@Test
public void validateConfiguration() {
    RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class);
    assertEquals("adapter", adapter.getComponentName());
    assertEquals("redis:inbound-channel-adapter", adapter.getComponentType());
    DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
    Object errorChannelBean = context.getBean("testErrorChannel");
    assertEquals(errorChannelBean, accessor.getPropertyValue("errorChannel"));
    Object converterBean = context.getBean("testConverter");
    assertEquals(converterBean, accessor.getPropertyValue("messageConverter"));
    assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
    Object container = accessor.getPropertyValue("container");
    DirectFieldAccessor containerAccessor = new DirectFieldAccessor(container);
    assertSame(this.executor, containerAccessor.getPropertyValue("taskExecutor"));
    Object bean = context.getBean("withoutSerializer.adapter");
    assertNotNull(bean);
    assertNull(TestUtils.getPropertyValue(bean, "serializer"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RedisInboundChannelAdapter(org.springframework.integration.redis.inbound.RedisInboundChannelAdapter) Test(org.junit.Test)

Example 97 with DirectFieldAccessor

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

the class WebFluxOutboundChannelAdapterParserTests method reactiveMinimalConfig.

@Test
public void reactiveMinimalConfig() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.reactiveMinimalConfig);
    WebClient webClient = TestUtils.getPropertyValue(this.reactiveMinimalConfig, "handler.webClient", WebClient.class);
    assertNotSame(this.webClient, webClient);
    Object handler = endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression");
    assertEquals("http://localhost/test1", uriExpression.getValue());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
Also used : Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) WebClient(org.springframework.web.reactive.function.client.WebClient) Test(org.junit.Test)

Example 98 with DirectFieldAccessor

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

the class WebFluxDslTests method testHttpReactiveProxyFlow.

@Test
public void testHttpReactiveProxyFlow() throws Exception {
    ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
        response.setStatusCode(HttpStatus.OK);
        response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
        return response.writeWith(Mono.just(response.bufferFactory().wrap("FOO".getBytes()))).then(Mono.defer(response::setComplete));
    });
    WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
    new DirectFieldAccessor(this.httpReactiveProxyFlow).setPropertyValue("webClient", webClient);
    this.mockMvc.perform(get("/service2").with(httpBasic("guest", "guest")).param("name", "foo")).andExpect(content().string("FOO"));
}
Also used : ClientHttpConnector(org.springframework.http.client.reactive.ClientHttpConnector) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) WebClient(org.springframework.web.reactive.function.client.WebClient) HttpHandlerConnector(org.springframework.test.web.reactive.server.HttpHandlerConnector) Test(org.junit.Test)

Example 99 with DirectFieldAccessor

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

the class DownstreamExceptionTests method testNoErrorChannel.

@Test
public void testNoErrorChannel() throws Exception {
    service.n = 0;
    Log logger = spy(TestUtils.getPropertyValue(noErrorChannel, "logger", Log.class));
    final CountDownLatch latch = new CountDownLatch(1);
    doAnswer(invocation -> {
        if (((String) invocation.getArgument(0)).contains("Unhandled")) {
            latch.countDown();
        }
        return null;
    }).when(logger).error(anyString(), any(Throwable.class));
    new DirectFieldAccessor(noErrorChannel).setPropertyValue("logger", logger);
    MqttPahoMessageHandler adapter = new MqttPahoMessageHandler("tcp://localhost:1883", "si-test-out");
    adapter.setDefaultTopic("mqtt-fooEx1");
    adapter.setBeanFactory(mock(BeanFactory.class));
    adapter.afterPropertiesSet();
    adapter.start();
    adapter.handleMessage(new GenericMessage<String>("foo"));
    service.barrier.await(10, TimeUnit.SECONDS);
    service.barrier.reset();
    adapter.handleMessage(new GenericMessage<String>("foo"));
    service.barrier.await(10, TimeUnit.SECONDS);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    verify(logger).error(contains("Unhandled exception for"), any(Throwable.class));
    service.barrier.reset();
    adapter.stop();
}
Also used : Log(org.apache.commons.logging.Log) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MqttPahoMessageHandler(org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler) BeanFactory(org.springframework.beans.factory.BeanFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 100 with DirectFieldAccessor

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

the class FileLockingNamespaceTests method extractSources.

@Before
public void extractSources() {
    nioLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(nioAdapter).getPropertyValue("source");
    customLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(customAdapter).getPropertyValue("source");
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Before(org.junit.Before)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)481 Test (org.junit.Test)389 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)60 Test (org.junit.jupiter.api.Test)48 List (java.util.List)45 Log (org.apache.commons.logging.Log)35 BeanFactory (org.springframework.beans.factory.BeanFactory)32 Expression (org.springframework.expression.Expression)29 Method (java.lang.reflect.Method)28 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)27 QueueChannel (org.springframework.integration.channel.QueueChannel)24 AbstractMailReceiver (org.springframework.integration.mail.AbstractMailReceiver)23 Map (java.util.Map)22 MessageChannel (org.springframework.messaging.MessageChannel)21 ArrayList (java.util.ArrayList)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)20 IOException (java.io.IOException)19 File (java.io.File)18 Properties (java.util.Properties)18