use of org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension in project Smack by igniterealtime.
the class MamResultProviderTest method checkMamResultProvider.
@Test
public void checkMamResultProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(exampleMamResultXml);
MamResultExtension mamResultExtension = new MamResultProvider().parse(parser);
Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
Forwarded forwarded = mamResultExtension.getForwarded();
Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
Message message = (Message) forwarded.getForwardedStanza();
Assert.assertEquals(message.getFrom(), "romeo@montague.lit/orchard");
Assert.assertEquals(message.getTo(), "juliet@capulet.lit/balcony");
Assert.assertEquals(message.getBody(), "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
}
use of org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension in project Smack by igniterealtime.
the class MamResultProviderTest method checkResultsParse.
@Test
public void checkResultsParse() throws Exception {
Message message = (Message) PacketParserUtils.parseStanza(exampleResultMessage);
MamResultExtension mamResultExtension = MamResultExtension.from(message);
Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
Forwarded forwarded = mamResultExtension.getForwarded();
Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
Message forwardedMessage = (Message) forwarded.getForwardedStanza();
Assert.assertEquals(forwardedMessage.getFrom(), "witch@shakespeare.lit");
Assert.assertEquals(forwardedMessage.getTo(), "macbeth@shakespeare.lit");
Assert.assertEquals(forwardedMessage.getBody(), "Hail to thee");
}
use of org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension in project Smack by igniterealtime.
the class MamResultFilter method acceptSpecific.
@Override
protected boolean acceptSpecific(Message message) {
MamResultExtension mamResultExtension = MamResultExtension.from(message);
if (mamResultExtension == null) {
return false;
}
String resultQueryId = mamResultExtension.getQueryId();
return ((queryId == null && resultQueryId == null) || (queryId != null && queryId.equals(resultQueryId)));
}
use of org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension 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.smackx.mam.element.MamElements.MamResultExtension in project Smack by igniterealtime.
the class MamResultProvider method parse.
@Override
public MamResultExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
Forwarded forwarded = null;
String queryId = parser.getAttributeValue("", "queryid");
String id = parser.getAttributeValue("", "id");
outerloop: while (true) {
final int eventType = parser.next();
final String name = parser.getName();
switch(eventType) {
case XmlPullParser.START_TAG:
switch(name) {
case Forwarded.ELEMENT:
forwarded = ForwardedProvider.INSTANCE.parse(parser);
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return new MamResultExtension(queryId, id, forwarded);
}
Aggregations