MatchingArchivedMessageResults { public List<Stanza> toStanzas() { List<Stanza> stanzas = new ArrayList<>(); archivedMessages.list().stream().map(archivedMessage -> new MatchingArchivedMessageResult(initiatingEntity, archiveId, query, archivedMessage)).map(MatchingArchivedMessageResult::toStanza).forEach(stanzas::add); stanzas.add(buildResultIq()); return stanzas; } MatchingArchivedMessageResults(Entity initiatingEntity, Entity archiveId, Query query,
            ArchivedMessages archivedMessages); List<Stanza> toStanzas();  }
@Test public void testUncomplete() throws IOException, SAXException { SimpleArchivedMessage archivedMessage1 = new SimpleArchivedMessage("28482-98726-73623", ZonedDateTime.of(LocalDateTime.of(2010, 7, 10, 23, 8, 25), ZoneId.of("Z")), messageStanza); SimpleArchivedMessage archivedMessage2 = new SimpleArchivedMessage("09af3-cc343-b409f", ZonedDateTime.of(LocalDateTime.of(2010, 7, 10, 23, 8, 25), ZoneId.of("Z")), messageStanza); List<ArchivedMessage> archivedMessagesList = new ArrayList<>(); archivedMessagesList.add(archivedMessage1); archivedMessagesList.add(archivedMessage2); SimpleArchivedMessages archivedMessages = new SimpleArchivedMessages(archivedMessagesList, 0L, 3L); MatchingArchivedMessageResults tested = new MatchingArchivedMessageResults(INITIATING_ENTITY, ARCHIVE_ID, query, archivedMessages); List<Stanza> responseStanzas = tested.toStanzas(); assertEquals(3, responseStanzas.size()); StanzaAssert.assertEquals(StanzaBuilder .createClone(XMLParserUtil.parseRequiredDocument("<message to='juliet@capulet.lit/chamber'>" + " <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>" + " <forwarded xmlns='urn:xmpp:forward:0'>" + " <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" + " <message xmlns='jabber:client' from='witch@shakespeare.lit' to='macbeth@shakespeare.lit'>" + " <body>Hail to thee</body>" + " <stanza-id xmlns='urn:xmpp:sid:0' by='juliet@capulet.lit' id='28482-98726-73623'/>" + "</message></forwarded></result></message>"), true, null) .build(), responseStanzas.get(0)); StanzaAssert.assertEquals(StanzaBuilder .createClone(XMLParserUtil.parseRequiredDocument("<message to='juliet@capulet.lit/chamber'>" + " <result xmlns='urn:xmpp:mam:2' queryid='f27' id='09af3-cc343-b409f'>" + " <forwarded xmlns='urn:xmpp:forward:0'>" + " <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" + " <message xmlns='jabber:client' from='witch@shakespeare.lit' to='macbeth@shakespeare.lit'>" + " <body>Hail to thee</body>" + " <stanza-id xmlns='urn:xmpp:sid:0' by='juliet@capulet.lit' id='09af3-cc343-b409f'/>" + "</message></forwarded></result></message>"), true, null) .build(), responseStanzas.get(1)); StanzaAssert.assertEquals( StanzaBuilder.createClone(XMLParserUtil .parseRequiredDocument("<iq type='result' id='juliet1'><fin xmlns='urn:xmpp:mam:2'>" + " <set xmlns='http: + " <count>3</count><first index='0'>28482-98726-73623</first>" + " <last>09af3-cc343-b409f</last></set></fin></iq>"), true, null).build(), responseStanzas.get(2)); }
@Test public void testComplete() throws IOException, SAXException { ArchivedMessage message = new SimpleArchivedMessage("28482-98726-73623", ZonedDateTime.of(LocalDateTime.of(2010, 7, 10, 23, 8, 25), ZoneId.of("Z")), messageStanza); ArchivedMessages archivedMessages = new SimpleArchivedMessages(Collections.singletonList(message), 0L, 1L); MatchingArchivedMessageResults tested = new MatchingArchivedMessageResults(INITIATING_ENTITY, ARCHIVE_ID, query, archivedMessages); List<Stanza> responseStanzas = tested.toStanzas(); assertEquals(2, responseStanzas.size()); StanzaAssert.assertEquals(StanzaBuilder .createClone(XMLParserUtil.parseRequiredDocument("<message to='juliet@capulet.lit/chamber'>" + " <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>" + " <forwarded xmlns='urn:xmpp:forward:0'>" + " <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>" + " <message xmlns='jabber:client' from='witch@shakespeare.lit' to='macbeth@shakespeare.lit'>" + " <body>Hail to thee</body>" + " <stanza-id xmlns='urn:xmpp:sid:0' by='juliet@capulet.lit' id='28482-98726-73623'/>" + "</message></forwarded></result></message>"), true, null) .build(), responseStanzas.get(0)); StanzaAssert.assertEquals( StanzaBuilder.createClone(XMLParserUtil.parseRequiredDocument( "<iq type='result' id='juliet1'><fin xmlns='urn:xmpp:mam:2' complete='true'>" + " <set xmlns='http: + " <count>1</count><first index='0'>28482-98726-73623</first>" + " <last>28482-98726-73623</last></set></fin></iq>"), true, null).build(), responseStanzas.get(1)); }
@Test public void testEmptyPage() throws IOException, SAXException { SimpleArchivedMessages archivedMessages = new SimpleArchivedMessages(Collections.emptyList(), 0L, 50L); MatchingArchivedMessageResults tested = new MatchingArchivedMessageResults(INITIATING_ENTITY, ARCHIVE_ID, query, archivedMessages); List<Stanza> responseStanzas = tested.toStanzas(); assertEquals(1, responseStanzas.size()); StanzaAssert.assertEquals( StanzaBuilder.createClone(XMLParserUtil .parseRequiredDocument("<iq type='result' id='juliet1'><fin xmlns='urn:xmpp:mam:2'>" + " <set xmlns='http: + " <count>50</count></set></fin></iq>"), true, null).build(), responseStanzas.get(0)); }