Search in sources :

Example 1 with MamQueryArgs

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);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Example 2 with MamQueryArgs

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());
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Example 3 with MamQueryArgs

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());
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ArrayList(java.util.ArrayList) Date(java.util.Date) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Example 4 with MamQueryArgs

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());
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) Stanza(org.jivesoftware.smack.packet.Stanza) ArrayList(java.util.ArrayList) StanzaListener(org.jivesoftware.smack.StanzaListener) MamQuery(org.jivesoftware.smackx.mam.MamManager.MamQuery) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) ArrayList(java.util.ArrayList) List(java.util.List) EntityBareJid(org.jxmpp.jid.EntityBareJid) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 5 with MamQueryArgs

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());
}
Also used : Jid(org.jxmpp.jid.Jid) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ArrayList(java.util.ArrayList) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Aggregations

MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)7 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)2 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)2 StanzaListener (org.jivesoftware.smack.StanzaListener)2 Message (org.jivesoftware.smack.packet.Message)2 Stanza (org.jivesoftware.smack.packet.Stanza)2 MamQuery (org.jivesoftware.smackx.mam.MamManager.MamQuery)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 List (java.util.List)1 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)1 FormField (org.jivesoftware.smackx.xdata.FormField)1 Jid (org.jxmpp.jid.Jid)1