Package rocks.xmpp.core.session

Examples of rocks.xmpp.core.session.XmppSession


    @Test
    public void testAttentionManager() {

        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        final boolean[] attentionReceived = {false};
        xmppSession2.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                if (e.isIncoming() && e.getMessage().getExtension(Attention.class) != null && e.getMessage().getType() == AbstractMessage.Type.HEADLINE) {
                    attentionReceived[0] = true;
                    Assert.assertEquals(e.getMessage().getType(), AbstractMessage.Type.HEADLINE);
View Full Code Here


    @Test
    public void testReachabilityManager() {

        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        final boolean[] attentionReceived = {false};
        xmppSession2.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                if (e.isIncoming() && e.getMessage().getExtension(Attention.class) != null && e.getMessage().getType() == AbstractMessage.Type.HEADLINE) {
                    attentionReceived[0] = true;
                    Assert.assertEquals(e.getMessage().getType(), AbstractMessage.Type.HEADLINE);
View Full Code Here

    @Test
    public void testManager() {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager1 = xmppSession1.getExtensionManager(MessageDeliveryReceiptsManager.class);
        // Test if the manager is disabled by default.
        Assert.assertFalse(messageDeliveryReceiptsManager1.isEnabled());

        messageDeliveryReceiptsManager1.setEnabled(true);
        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager2 = xmppSession2.getExtensionManager(MessageDeliveryReceiptsManager.class);
        messageDeliveryReceiptsManager2.setEnabled(true);

        final boolean[] messageReceived = {false};
        final String[] receivedId = {null};
        messageDeliveryReceiptsManager1.setEnabled(true);
View Full Code Here

    @Test
    public void testManagerIfContactDoesNotSupportReceipts() {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager1 = xmppSession1.getExtensionManager(MessageDeliveryReceiptsManager.class);
        messageDeliveryReceiptsManager1.setEnabled(true);
        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager2 = xmppSession2.getExtensionManager(MessageDeliveryReceiptsManager.class);
        messageDeliveryReceiptsManager2.setEnabled(false);

        final boolean[] messageReceived = {false};
        messageDeliveryReceiptsManager1.setEnabled(true);
        messageDeliveryReceiptsManager1.addMessageDeliveredListener(new MessageDeliveredListener() {
View Full Code Here

    @Test
    public void testManagerIfNoMessageId() {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager1 = xmppSession1.getExtensionManager(MessageDeliveryReceiptsManager.class);
        messageDeliveryReceiptsManager1.setEnabled(true);
        xmppSession1.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                Assert.assertNull(e.getMessage().getExtension(Request.class));
            }
        });

        Message message = new Message(JULIET);
        xmppSession1.send(message);
    }
View Full Code Here

     */
    @Test
    public void testManagerIfErrorType() {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        MessageDeliveryReceiptsManager messageDeliveryReceiptsManager1 = xmppSession1.getExtensionManager(MessageDeliveryReceiptsManager.class);
        messageDeliveryReceiptsManager1.setEnabled(true);
        xmppSession1.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                Assert.assertNull(e.getMessage().getExtension(Request.class));
            }
        });

        Message message = new Message(JULIET);
        message.setType(Message.Type.ERROR);
        message.setId("123");
        xmppSession1.send(message);
    }
View Full Code Here

    @Test
    public void testDisabledManager() {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);

        xmppSession1.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                Assert.assertNull(e.getMessage().getExtension(Request.class));
            }
        });

        Message message = new Message(JULIET);
        message.setId("123");
        xmppSession1.send(message);
    }
View Full Code Here

    @Test
    public void testCall() throws XmppException, RpcException {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        RpcManager rpcManager = xmppSession1.getExtensionManager(RpcManager.class);
        rpcManager.executorService = new SameThreadExecutorService();
        rpcManager.setEnabled(true);
        rpcManager.setRpcHandler(new RpcHandler() {
            @Override
            public Value process(Jid requester, String methodName, List<Value> parameters) throws RpcException {
                if (methodName.equals("square")) {
                    return new Value(parameters.get(0).getAsInteger() * parameters.get(0).getAsInteger());
                }
                return null;
            }
        });

        Value result = xmppSession2.getExtensionManager(RpcManager.class).call(ROMEO, "square", new Value(2));
        Assert.assertEquals(result.getAsInteger().intValue(), 4);
    }
View Full Code Here

    @Test
    public void testRpcException() throws XmppException {
        MockServer mockServer = new MockServer();

        XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);

        RpcManager rpcManager = xmppSession1.getExtensionManager(RpcManager.class);
        rpcManager.setEnabled(true);

        rpcManager.executorService = new SameThreadExecutorService();

        rpcManager.setRpcHandler(new RpcHandler() {
            @Override
            public Value process(Jid requester, String methodName, List<Value> parameters) throws RpcException {
                if (methodName.equals("fault")) {
                    throw new RpcException(2, "faulty");
                }
                return null;
            }
        });

        try {
            xmppSession2.getExtensionManager(RpcManager.class).call(ROMEO, "fault", new Value(2));
        } catch (RpcException e) {
            Assert.assertEquals(e.getFaultCode(), 2);
            Assert.assertEquals(e.getFaultString(), "faulty");
            return;
        }
View Full Code Here

    }

    @Test
    public void testIbbSessionRejection() {
        MockServer mockServer = new MockServer();
        final XmppSession xmppSession1 = new TestXmppSession(ROMEO, mockServer);
        final XmppSession xmppSession2 = new TestXmppSession(JULIET, mockServer);
        InBandByteStreamManager inBandBytestreamManager2 = xmppSession2.getExtensionManager(InBandByteStreamManager.class);
        inBandBytestreamManager2.addByteStreamListener(new ByteStreamListener() {
            @Override
            public void byteStreamRequested(final ByteStreamEvent e) {
                e.reject();
            }
View Full Code Here

TOP

Related Classes of rocks.xmpp.core.session.XmppSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.