use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.
the class RetrieveFormFieldsTest method checkAddAdditionalFieldsStanza.
@Test
public void checkAddAdditionalFieldsStanza() throws Exception {
FormField field1 = FormField.builder("urn:example:xmpp:free-text-search").setValue("Hi").build();
FormField field2 = FormField.jidSingleBuilder("urn:example:xmpp:stanza-content").setValue(JidTestUtil.BARE_JID_1).build();
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().withAdditionalFormField(field1).withAdditionalFormField(field2).build();
DataForm dataForm = mamQueryArgs.getDataForm(MamVersion.MAM2);
String dataFormResult = dataForm.toXML().toString();
assertXmlSimilar(additionalFieldsStanza, dataFormResult);
}
use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.
the class ResultsLimitTest method checkResultsLimit.
@Test
public void checkResultsLimit() throws Exception {
DataForm dataForm = getNewMamForm();
MamQueryIQ mamQueryIQ = new MamQueryIQ(MamVersion.MAM2, queryId, dataForm);
mamQueryIQ.setType(IQ.Type.set);
mamQueryIQ.setStanzaId("sarasa");
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(10).build();
mamQueryArgs.maybeAddRsmSet(mamQueryIQ);
assertEquals(resultsLimitStanza, mamQueryIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}
use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.
the class FiltersTest method checkEndDateFilter.
@Test
public void checkEndDateFilter() throws Exception {
Date date = new Date();
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsBefore(date).build();
DataForm dataForm = mamQueryArgs.getDataForm(MamVersion.MAM2);
List<String> fields = new ArrayList<>();
fields.add("end");
List<String> values = new ArrayList<>();
values.add(XmppDateTime.formatXEP0082Date(date));
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
}
use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.
the class MamIntegrationTest method mamPageTest.
@SmackIntegrationTest
public void mamPageTest() throws TimeoutException, Exception {
final int messagesPerPage = 10;
final int numPages = 3;
final int totalMessages = messagesPerPage * numPages;
final List<Message> outgoingMessages = new ArrayList<>(totalMessages);
final EntityBareJid userOne = conOne.getUser().asEntityBareJid();
final EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
final SimpleResultSyncPoint allMessagesReceived = new SimpleResultSyncPoint();
final String lastMessageArchiveUid = mamManagerConTwo.getMessageUidOfLatestMessage();
for (int i = 0; i < totalMessages; i++) {
String messageBody = "MAM Page Test " + testRunId + ' ' + (i + 1);
Message message = StanzaBuilder.buildMessage().to(userTwo).setBody(messageBody).build();
outgoingMessages.add(message);
}
final String lastBody = outgoingMessages.get(outgoingMessages.size() - 1).getBody();
final StanzaListener stanzaListener = new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
Message message = (Message) stanza;
if (message.getBody().equals(lastBody)) {
allMessagesReceived.signal();
}
}
};
conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
try {
for (Message message : outgoingMessages) {
conOne.sendStanza(message);
}
allMessagesReceived.waitForResult(timeout);
} finally {
conTwo.removeAsyncStanzaListener(stanzaListener);
}
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(messagesPerPage).limitResultsToJid(userOne).afterUid(lastMessageArchiveUid).build();
MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
assertFalse(mamQuery.isComplete());
assertEquals(messagesPerPage, mamQuery.getMessageCount());
List<List<Message>> pages = new ArrayList<>(numPages);
pages.add(mamQuery.getMessages());
for (int additionalPageRequestNum = 0; additionalPageRequestNum < numPages - 1; additionalPageRequestNum++) {
List<Message> page = mamQuery.pageNext(messagesPerPage);
boolean isLastQuery = additionalPageRequestNum == numPages - 2;
if (isLastQuery) {
assertTrue(mamQuery.isComplete());
} else {
assertFalse(mamQuery.isComplete());
}
assertEquals(messagesPerPage, page.size());
pages.add(page);
}
List<Message> queriedMessages = new ArrayList<>(totalMessages);
for (List<Message> messages : pages) {
queriedMessages.addAll(messages);
}
assertEquals(outgoingMessages.size(), queriedMessages.size());
for (int i = 0; i < outgoingMessages.size(); i++) {
Message outgoingMessage = outgoingMessages.get(i);
Message queriedMessage = queriedMessages.get(i);
assertEquals(outgoingMessage.getBody(), queriedMessage.getBody());
}
}
use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.
the class FiltersTest method checkWithJidFilter.
@Test
public void checkWithJidFilter() throws Exception {
Jid jid = JidTestUtil.BARE_JID_1;
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsToJid(jid).build();
DataForm dataForm = mamQueryArgs.getDataForm(MamVersion.MAM2);
List<String> fields = new ArrayList<>();
fields.add("with");
List<CharSequence> values = new ArrayList<>();
values.add(jid);
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
}
Aggregations