UserMessageStanzaBroker extends DelegatingStanzaBroker { @Override public void writeToSession(Stanza stanza) { super.writeToSession(archive(stanza)); } UserMessageStanzaBroker(StanzaBroker delegate, ServerRuntimeContext serverRuntimeContext,
            SessionContext sessionContext, boolean isOutbound, boolean archivingForced); @Override void write(Entity receiver, Stanza stanza, DeliveryFailureStrategy deliveryFailureStrategy); @Override void writeToSession(Stanza stanza);  }
@Test public void onlyNormalAndChatMessageAreArchived() { UserMessageStanzaBroker tested = buildTested(true, false); Stream.of(MessageStanzaType.values()).filter(messageStanzaType -> messageStanzaType != MessageStanzaType.NORMAL) .filter(messageStanzaType -> messageStanzaType != MessageStanzaType.CHAT).forEach(messageStanzaType -> { MessageStanza stanza = buildMessageStanza(messageStanzaType, null, ALICE_IN_RABBIT_HOLE, "hello world"); tested.writeToSession(stanza); julietArchive.assertEmpty(); romeoArchive.assertEmpty(); macbethArchive.assertEmpty(); }); Stream.of(MessageStanzaType.CHAT, MessageStanzaType.NORMAL).forEach(messageStanzaType -> { julietArchive.clear(); MessageStanza messageStanza = buildMessageStanza(messageStanzaType, null, ALICE_IN_RABBIT_HOLE, "hello world"); tested.writeToSession(messageStanza); julietArchive.assertUniqueArchivedMessageStanza(messageStanza); }); }
@Test public void outboundMessageHavingFrom() { UserMessageStanzaBroker tested = buildTested(true, false); MessageStanza messageStanza = buildMessageStanza(MessageStanzaType.NORMAL, ROMEO_IN_ORCHARD, ALICE_IN_RABBIT_HOLE, "hello world"); tested.writeToSession(messageStanza); romeoArchive.assertUniqueArchivedMessageStanza(messageStanza); }
@Test public void outboundMessageWithoutFrom() { UserMessageStanzaBroker tested = buildTested(true, false); MessageStanza messageStanza = buildMessageStanza(MessageStanzaType.NORMAL, null, ALICE_IN_RABBIT_HOLE, "hello world"); tested.writeToSession(messageStanza); julietArchive.assertUniqueArchivedMessageStanza(messageStanza); }
@Test public void unexistingArchive() { UserMessageStanzaBroker tested = buildTested(true, false); MessageStanza messageStanza = buildMessageStanza(MessageStanzaType.NORMAL, ALICE_IN_RABBIT_HOLE, ALICE_IN_RABBIT_HOLE, "hello world"); tested.writeToSession(messageStanza); julietArchive.assertEmpty(); romeoArchive.assertEmpty(); macbethArchive.assertEmpty(); }
@Test public void messageWithoutBody() { UserMessageStanzaBroker tested = buildTested(true, false); MessageStanza messageStanza = buildMessageStanza(MessageStanzaType.NORMAL, JULIET_IN_CHAMBER, ROMEO_IN_ORCHARD, null); tested.writeToSession(messageStanza); julietArchive.assertEmpty(); romeoArchive.assertEmpty(); }
@Test public void messageWithoutBodyWithArchivingForced(){ UserMessageStanzaBroker tested = buildTested(true, true); MessageStanza messageStanza = buildMessageStanza(MessageStanzaType.NORMAL, JULIET_IN_CHAMBER, ROMEO_IN_ORCHARD, null); tested.writeToSession(messageStanza); julietArchive.assertUniqueArchivedMessageStanza(messageStanza); romeoArchive.assertEmpty(); }