use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class MUCLightConfigurationsChangeExtensionTest method checkConfigsChangeExtension.
@Test
public void checkConfigsChangeExtension() throws Exception {
Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithConfigsChangeExample);
ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension.from(configurationsMessage);
Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
Assert.assertNull(configurationsChangeExtension.getSubject());
Assert.assertEquals("blue", configurationsChangeExtension.getCustomConfigs().get("color"));
Assert.assertEquals(messageWithConfigsChangeExample, configurationsMessage.toXML().toString());
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class QueryArchiveTest method checkMamQueryResults.
@Test
public void checkMamQueryResults() throws Exception {
Message message = new Message();
message.setStanzaId("iasd207");
message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
DelayInformation delay = new DelayInformation(date);
Message forwardedMessage = new Message();
forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
forwardedMessage.setType(Type.chat);
forwardedMessage.setBody("Thrice the brinded cat hath mew.");
Forwarded forwarded = new Forwarded(delay, forwardedMessage);
message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
Assert.assertEquals(message.toXML().toString(), mamQueryResultExample);
MamResultExtension mamResultExtension = MamResultExtension.from(message);
Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
Assert.assertEquals(resultMessage.getType(), Type.chat);
Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class MUCLightAffiliationsChangeExtensionTest method checkAffiliationsChangeExtensionWithPrevVersion.
@Test
public void checkAffiliationsChangeExtensionWithPrevVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanzaWithPrevVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliationsChangeExtension.getPrevVersion(), "njiokm");
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class MUCLightAffiliationsChangeExtensionTest method checkAffiliationsChangeExtensionWithVersion.
@Test
public void checkAffiliationsChangeExtensionWithVersion() throws Exception {
Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanzaWithVersion);
AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension.from(changeAffiliationsMessage);
HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
Assert.assertEquals(affiliations.size(), 2);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.
the class MultiUserChatTest method testDiscussionHistory.
public void testDiscussionHistory() {
try {
// User1 sends some messages to the room
muc.sendMessage("Message 1");
muc.sendMessage("Message 2");
// Wait 5 seconds before sending the last message
Thread.sleep(5000);
muc.sendMessage("Message 3");
// User2 joins the room requesting to receive the messages of the last 2 seconds.
MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
DiscussionHistory history = new DiscussionHistory();
history.setSeconds(2);
muc2.join("testbot2", null, history, SmackConfiguration.getPacketReplyTimeout());
Message msg;
// Get first historic message
msg = muc2.nextMessage(1000);
assertNotNull("First message is null", msg);
DelayInformation delay = DelayInformationManager.getDelayInformation(msg);
assertNotNull("Message contains no delay information", delay);
SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
UTC_FORMAT.setTimeZone(TimeZone.getDefault());
System.out.println(UTC_FORMAT.format(delay.getStamp()));
assertEquals("Body of first message is incorrect", "Message 3", msg.getBody());
// Try to get second historic message
msg = muc2.nextMessage(1000);
assertNull("Second message is not null", msg);
// User3 joins the room requesting to receive the last 2 messages.
MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
history = new DiscussionHistory();
history.setMaxStanzas(2);
muc3.join("testbot3", null, history, SmackConfiguration.getPacketReplyTimeout());
// Get first historic message
msg = muc3.nextMessage(1000);
assertNotNull("First message is null", msg);
assertEquals("Body of first message is incorrect", "Message 2", msg.getBody());
// Get second historic message
msg = muc3.nextMessage(1000);
assertNotNull("Second message is null", msg);
assertEquals("Body of second message is incorrect", "Message 3", msg.getBody());
// Try to get third historic message
msg = muc3.nextMessage(1000);
assertNull("Third message is not null", msg);
// User2 leaves the room
muc2.leave();
// User3 leaves the room
muc3.leave();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations