Example usage for org.springframework.integration.xmpp.core XmppContextUtils XMPP_CONNECTION_BEAN_NAME

List of usage examples for org.springframework.integration.xmpp.core XmppContextUtils XMPP_CONNECTION_BEAN_NAME

Introduction

In this page you can find the example usage for org.springframework.integration.xmpp.core XmppContextUtils XMPP_CONNECTION_BEAN_NAME.

Prototype

String XMPP_CONNECTION_BEAN_NAME

To view the source code for org.springframework.integration.xmpp.core XmppContextUtils XMPP_CONNECTION_BEAN_NAME.

Click Source Link

Usage

From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java

@Test
public void testWithImplicitXmppConnection() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class));
    ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
    endpoint.setBeanFactory(bf);/*from ww w. j a v  a  2s  . c  om*/
    endpoint.setOutputChannel(new QueueChannel());
    endpoint.afterPropertiesSet();
    assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection"));
}

From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java

@Test
public void testWithErrorChannel() throws NotConnectedException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XMPPConnection connection = mock(XMPPConnection.class);
    bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);

    ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();

    DirectChannel outChannel = new DirectChannel();
    outChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });//from   w w  w  .  ja  v a 2s  .  co m
    PollableChannel errorChannel = new QueueChannel();
    endpoint.setBeanFactory(bf);
    endpoint.setOutputChannel(outChannel);
    endpoint.setErrorChannel(errorChannel);
    endpoint.afterPropertiesSet();
    StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener");
    Message smackMessage = new Message("kermit@frog.com");
    smackMessage.setBody("hello");
    smackMessage.setThread("1234");
    listener.processPacket(smackMessage);

    ErrorMessage msg = (ErrorMessage) errorChannel.receive();
    assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
}