Search in sources :

Example 36 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class VCardTest method testBinaryAvatar.

public void testBinaryAvatar() throws Throwable {
    VCard card = new VCard();
    card.setAvatar(getAvatarBinary());
    card.save(getConnection(0));
    VCard loaded = new VCard();
    try {
        loaded.load(getConnection(0));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    byte[] initialAvatar = card.getAvatar();
    byte[] loadedAvatar = loaded.getAvatar();
    assertEquals("Should load own Avatar successfully", initialAvatar, loadedAvatar);
    loaded = new VCard();
    try {
        loaded.load(getConnection(1), getBareJID(0));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertEquals("Should load avatar successfully", card.getAvatar(), loaded.getAvatar());
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard)

Example 37 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class VCardTest method testBigFunctional.

public void testBigFunctional() throws XMPPException {
    VCard origVCard = new VCard();
    origVCard.setFirstName("kir");
    origVCard.setLastName("max");
    origVCard.setEmailHome("foo@fee.bar");
    origVCard.setEmailWork("foo@fee.www.bar");
    origVCard.setJabberId("jabber@id.org");
    origVCard.setOrganization("Jetbrains, s.r.o");
    origVCard.setNickName("KIR");
    origVCard.setField("TITLE", "Mr");
    origVCard.setAddressFieldHome("STREET", "Some street & House");
    origVCard.setAddressFieldWork("STREET", "Some street work");
    origVCard.setPhoneWork("FAX", "3443233");
    origVCard.setPhoneHome("VOICE", "3443233");
    origVCard.save(getConnection(0));
    VCard loaded = new VCard();
    try {
        loaded.load(getConnection(0));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertEquals("Should load own VCard successfully", origVCard, loaded);
    loaded = new VCard();
    try {
        loaded.load(getConnection(1), getBareJID(0));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertEquals("Should load another user's VCard successfully", origVCard, loaded);
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard)

Example 38 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class AdHocCommandDiscoTest method testAdHocCommands.

public void testAdHocCommands() {
    try {
        AdHocCommandManager manager1 = AdHocCommandManager.getAddHocCommandsManager(getConnection(0));
        manager1.registerCommand("test", "test node", LocalCommand.class);
        manager1.registerCommand("test2", "test node", new LocalCommandFactory() {

            public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
                return new LocalCommand() {

                    public boolean isLastStage() {
                        return true;
                    }

                    public boolean hasPermission(String jid) {
                        return true;
                    }

                    public void execute() throws XMPPException {
                        Form result = new Form(Form.TYPE_RESULT);
                        FormField resultField = new FormField("test2");
                        resultField.setLabel("test node");
                        resultField.addValue("it worked");
                        result.addField(resultField);
                        setForm(result);
                    }

                    public void next(Form response) throws XMPPException {
                    //
                    }

                    public void complete(Form response) throws XMPPException {
                    //
                    }

                    public void prev() throws XMPPException {
                    //
                    }

                    public void cancel() throws XMPPException {
                    //
                    }
                };
            }
        });
        AdHocCommandManager manager2 = AdHocCommandManager.getAddHocCommandsManager(getConnection(1));
        DiscoverItems items = manager2.discoverCommands(getFullJID(0));
        assertTrue("Disco for command test failed", items.getItems().next().getNode().equals("test"));
        RemoteCommand command = manager2.getRemoteCommand(getFullJID(0), "test2");
        command.execute();
        assertEquals("Disco for command test failed", command.getForm().getField("test2").getValues().next(), "it worked");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField) XMPPException(org.jivesoftware.smack.XMPPException)

Example 39 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class MultiUserChatCreationTest method testCreateInstantRoom.

/**
     * Tests creating a new "Instant Room".
     */
public void testCreateInstantRoom() {
    MultiUserChat muc = new MultiUserChat(getConnection(0), room);
    try {
        // Create the room
        muc.create("testbot");
        // Send an empty room configuration form which indicates that we want
        // an instant room
        muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
        // Destroy the new room
        muc.destroy("The room has almost no activity...", null);
    } catch (XMPPException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) XMPPException(org.jivesoftware.smack.XMPPException)

Example 40 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class MultiUserChatTest method testPrivateChat.

public void testPrivateChat() {
    try {
        // User2 joins the new room
        MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
        muc2.join("testbot2");
        getConnection(0).getChatManager().addChatListener(new ChatManagerListener() {

            public void chatCreated(Chat chat2, boolean createdLocally) {
                assertEquals("Sender of chat is incorrect", room + "/testbot2", chat2.getParticipant());
                try {
                    chat2.sendMessage("ACK");
                } catch (XMPPException e) {
                    fail(e.getMessage());
                }
            }
        });
        // Start a private chat with another participant            
        Chat chat = muc2.createPrivateChat(room + "/testbot", null);
        StanzaCollector collector = chat.createCollector();
        chat.sendMessage("Hello there");
        Message response = (Message) collector.nextResult(2000);
        assertNotNull("No response", response);
        assertEquals("Sender of response is incorrect", room + "/testbot", response.getFrom());
        assertEquals("Body of response is incorrect", "ACK", response.getBody());
        // User2 leaves the room
        muc2.leave();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) Chat(org.jivesoftware.smack.Chat) XMPPException(org.jivesoftware.smack.XMPPException) StanzaCollector(org.jivesoftware.smack.StanzaCollector) ChatManagerListener(org.jivesoftware.smack.ChatManagerListener) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

XMPPException (org.jivesoftware.smack.XMPPException)61 ArrayList (java.util.ArrayList)15 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)13 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)13 IOException (java.io.IOException)11 SmackException (org.jivesoftware.smack.SmackException)11 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)9 XMPPConnection (org.jivesoftware.smack.XMPPConnection)9 Message (org.jivesoftware.smack.packet.Message)8 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)6 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)5 FixedResolver (org.jivesoftware.smackx.jingle.nat.FixedResolver)5 FixedTransportManager (org.jivesoftware.smackx.jingle.nat.FixedTransportManager)5 TransportCandidate (org.jivesoftware.smackx.jingle.nat.TransportCandidate)5 Chat (org.jivesoftware.smack.Chat)4 TCPConnection (org.jivesoftware.smack.TCPConnection)4 Form (org.jivesoftware.smackx.Form)4 JingleSessionListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)4 JmfMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager)4 ICETransportManager (org.jivesoftware.smackx.jingle.nat.ICETransportManager)4