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());
}
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);
}
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());
}
}
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());
}
}
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());
}
}
Aggregations