Search in sources :

Example 6 with MamQueryArgs

use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.

the class FiltersTest method checkStartDateFilter.

@Test
public void checkStartDateFilter() throws Exception {
    Date date = new Date();
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder().limitResultsSince(date).build();
    DataForm dataForm = mamQueryArgs.getDataForm(MamVersion.MAM2);
    List<String> fields = new ArrayList<>();
    fields.add("start");
    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 7 with MamQueryArgs

use of org.jivesoftware.smackx.mam.MamManager.MamQueryArgs in project Smack by igniterealtime.

the class MamIntegrationTest method mamTest.

@SmackIntegrationTest
public void mamTest() throws TimeoutException, Exception {
    EntityBareJid userOne = conOne.getUser().asEntityBareJid();
    EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
    final String messageBody = "Test MAM message (" + testRunId + ')';
    Message message = conTwo.getStanzaFactory().buildMessageStanza().to(userTwo).setBody(messageBody).build();
    final String messageId = message.getStanzaId();
    final SimpleResultSyncPoint messageReceived = new SimpleResultSyncPoint();
    final StanzaListener stanzaListener = new StanzaListener() {

        @Override
        public void processStanza(Stanza stanza) {
            Message message = (Message) stanza;
            if (message.getBody().equals(messageBody)) {
                messageReceived.signal();
            }
        }
    };
    conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
    try {
        conOne.sendStanza(message);
        messageReceived.waitForResult(timeout);
    } finally {
        conTwo.removeAsyncStanzaListener(stanzaListener);
    }
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSizeTo(1).limitResultsToJid(userOne).queryLastPage().build();
    MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
    assertEquals(1, mamQuery.getMessages().size());
    Message mamMessage = mamQuery.getMessages().get(0);
    assertEquals(messageId, mamMessage.getStanzaId());
    assertEquals(messageBody, mamMessage.getBody());
    assertEquals(conOne.getUser(), mamMessage.getFrom());
    assertEquals(userTwo, mamMessage.getTo());
}
Also used : Message(org.jivesoftware.smack.packet.Message) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) MamQuery(org.jivesoftware.smackx.mam.MamManager.MamQuery) 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)

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