Example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setLazyConnect

List of usage examples for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setLazyConnect

Introduction

In this page you can find the example usage for org.springframework.integration.amqp.outbound AmqpOutboundEndpoint setLazyConnect.

Prototype

public void setLazyConnect(boolean lazyConnect) 

Source Link

Document

Set to false to attempt to connect during endpoint start; default true , meaning the connection will be attempted to be established on the arrival of the first message.

Usage

From source file:org.springframework.integration.amqp.config.AmqpOutboundChannelAdapterParserTests.java

@Test
public void testInt3430FailForNotLazyConnect() {
    RabbitTemplate amqpTemplate = spy(new RabbitTemplate());
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    RuntimeException toBeThrown = new RuntimeException("Test Connection Exception");
    doThrow(toBeThrown).when(connectionFactory).createConnection();
    when(amqpTemplate.getConnectionFactory()).thenReturn(connectionFactory);
    AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(amqpTemplate);
    Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
    new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
    doAnswer(new DoesNothing()).when(logger).error("Failed to eagerly establish the connection.", toBeThrown);
    ApplicationContext context = mock(ApplicationContext.class);
    handler.setApplicationContext(context);
    handler.setBeanFactory(context);/*from  w w  w  .  ja  va 2  s.  c om*/
    handler.afterPropertiesSet();
    handler.start();
    handler.stop();
    verify(logger, never()).error(anyString(), any(RuntimeException.class));
    handler.setLazyConnect(false);
    handler.start();
    verify(logger).error("Failed to eagerly establish the connection.", toBeThrown);
    handler.stop();
}