use of org.jivesoftware.smackx.forward.packet.Forwarded 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.forward.packet.Forwarded 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);
}
use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.
the class MamManager method queryArchive.
private MamQueryResult queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
MamFinIQ mamFinIQ = null;
StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));
StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);
StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration);
try {
connection.sendStanza(mamQueryIq);
mamFinIQ = mamFinIQCollector.nextResultOrThrow();
} finally {
mamFinIQCollector.cancel();
resultCollector.cancel();
}
List<Forwarded> forwardedMessages = new ArrayList<>(resultCollector.getCollectedCount());
for (Message resultMessage = resultCollector.pollResult(); resultMessage != null; resultMessage = resultCollector.pollResult()) {
MamElements.MamResultExtension mamResultExtension = MamElements.MamResultExtension.from(resultMessage);
forwardedMessages.add(mamResultExtension.getForwarded());
}
return new MamQueryResult(forwardedMessages, mamFinIQ, mamQueryIq.getNode(), DataForm.from(mamQueryIq));
}
use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.
the class CarbonTest method carbonSentTest.
@Test
public void carbonSentTest() throws Exception {
XmlPullParser parser;
String control;
CarbonExtension cc;
Forwarded fwd;
control = XMLBuilder.create("sent").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
cc = new CarbonManagerProvider().parse(parser);
fwd = cc.getForwarded();
// meta
assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
// no delay in packet
assertEquals(null, fwd.getDelayInformation());
// check message
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("sent", parser.getName());
}
use of org.jivesoftware.smackx.forward.packet.Forwarded in project Smack by igniterealtime.
the class ForwardedTest method forwardedTest.
@Test
public void forwardedTest() throws Exception {
XmlPullParser parser;
String control;
Forwarded fwd;
control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
fwd = new ForwardedProvider().parse(parser);
// no delay in packet
assertEquals(null, fwd.getDelayInformation());
// check message
assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("forwarded", parser.getName());
}
Aggregations