diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-07-28 11:26:53 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-01-14 15:13:35 (GMT) |
commit | 701abcb162dfb3e7cc8c6a9ada81a16d1fc8d4ee (patch) | |
tree | 64f49648eefdca1e2245b6899a3b49e428063f13 /test | |
parent | c72128ba30a386704244322c15146a1b4a609a12 (diff) | |
download | stroke-701abcb162dfb3e7cc8c6a9ada81a16d1fc8d4ee.zip stroke-701abcb162dfb3e7cc8c6a9ada81a16d1fc8d4ee.tar.bz2 |
Minor changes to PubSubManagerImpl and StanzaAckRequester.
Small changes to PubSubManagerImpl and StanzaAckRequester making them equivalent with Swiften.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Added tests for StanzaAckResponder and StanzaAckRequester, which passes.
Change-Id: I99878fc6552ed18e353848a0cea6584c26b2ba0c
Diffstat (limited to 'test')
-rw-r--r-- | test/com/isode/stroke/streammanagement/StanzaAckRequesterTest.java | 175 | ||||
-rw-r--r-- | test/com/isode/stroke/streammanagement/StanzaAckResponderTest.java | 105 |
2 files changed, 280 insertions, 0 deletions
diff --git a/test/com/isode/stroke/streammanagement/StanzaAckRequesterTest.java b/test/com/isode/stroke/streammanagement/StanzaAckRequesterTest.java new file mode 100644 index 0000000..38b6943 --- /dev/null +++ b/test/com/isode/stroke/streammanagement/StanzaAckRequesterTest.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.streammanagement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Presence; +import com.isode.stroke.elements.Message; +import com.isode.stroke.elements.Stanza; +import com.isode.stroke.signals.Slot1; +import com.isode.stroke.signals.Slot; +import java.util.Vector; + +public class StanzaAckRequesterTest { + + private int acksRequested; + private Vector<Stanza> ackedStanzas = new Vector<Stanza>(); + + private Message createMessage(final String id) { + Message result = new Message(); + result.setID(id); + return result; + } + + private IQ createIQ(final String id) { + IQ result = new IQ(); + result.setID(id); + return result; + } + + private Presence createPresence(final String id) { + Presence result = new Presence(); + result.setID(id); + return result; + } + + private StanzaAckRequester createRequester() { + StanzaAckRequester requester = new StanzaAckRequester(); + requester.onRequestAck.connect(new Slot() { + @Override + public void call() { + handleRequestAck(); + } + }); + requester.onStanzaAcked.connect(new Slot1<Stanza>() { + @Override + public void call(Stanza s) { + handleStanzaAcked(s); + } + }); + return requester; + } + + private void handleRequestAck() { + acksRequested++; + } + + private void handleStanzaAcked(Stanza stanza) { + ackedStanzas.add(stanza); + } + + @Before + public void setUp() { + acksRequested = 0; + } + + @Test + public void testHandleStanzaSent_MessageRequestsAck() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createMessage("m1")); + + assertEquals(1, acksRequested); + } + + @Test + public void testHandleStanzaSent_IQDoesNotRequestAck() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createIQ("iq1")); + + assertEquals(0, acksRequested); + } + + @Test + public void testHandleStanzaSent_PresenceDoesNotRequestAck() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createPresence("p1")); + + assertEquals(0, acksRequested); + } + + @Test + public void testHandleAckReceived_AcksStanza() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createMessage("m1")); + + testling.handleAckReceived(1); + + assertEquals(1, (ackedStanzas.size())); + assertEquals(("m1"), ackedStanzas.get(0).getID()); + } + + @Test + public void testHandleAckReceived_AcksMultipleMessages() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createMessage("m1")); + testling.handleStanzaSent(createMessage("m2")); + + testling.handleAckReceived(2); + + assertEquals(2, (ackedStanzas.size())); + assertEquals(("m1"), ackedStanzas.get(0).getID()); + assertEquals(("m2"), ackedStanzas.get(1).getID()); + } + + @Test + public void testHandleAckReceived_AcksMultipleStanzas() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createIQ("iq1")); + testling.handleStanzaSent(createPresence("p1")); + testling.handleStanzaSent(createMessage("m1")); + + testling.handleAckReceived(3); + + assertEquals(3, (ackedStanzas.size())); + assertEquals(("iq1"), ackedStanzas.get(0).getID()); + assertEquals(("p1"), ackedStanzas.get(1).getID()); + assertEquals(("m1"), ackedStanzas.get(2).getID()); + } + + @Test + public void testHandleAckReceived_MultipleAcks() { + StanzaAckRequester testling = createRequester(); + testling.handleStanzaSent(createMessage("m1")); + testling.handleAckReceived(1); + + testling.handleStanzaSent(createMessage("m2")); + testling.handleStanzaSent(createMessage("m3")); + testling.handleAckReceived(3); + + assertEquals(3, (ackedStanzas.size())); + assertEquals(("m1"), ackedStanzas.get(0).getID()); + assertEquals(("m2"), ackedStanzas.get(1).getID()); + assertEquals(("m3"), ackedStanzas.get(2).getID()); + } + + // Handle stanza ack count wrapping, as per the XEP + @Test + public void testHandleAckReceived_WrapAround() { + StanzaAckRequester testling = createRequester(); + testling.lastHandledStanzasCount = Long.parseLong("4294967295"); + testling.handleStanzaSent(createMessage("m1")); + testling.handleStanzaSent(createMessage("m2")); + + testling.handleAckReceived(1); + + assertEquals(2, (ackedStanzas.size())); + assertEquals(("m1"), ackedStanzas.get(0).getID()); + assertEquals(("m2"), ackedStanzas.get(1).getID()); + } +} diff --git a/test/com/isode/stroke/streammanagement/StanzaAckResponderTest.java b/test/com/isode/stroke/streammanagement/StanzaAckResponderTest.java new file mode 100644 index 0000000..dc0074e --- /dev/null +++ b/test/com/isode/stroke/streammanagement/StanzaAckResponderTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.streammanagement; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Presence; +import com.isode.stroke.elements.Message; +import com.isode.stroke.elements.Stanza; +import com.isode.stroke.signals.Slot1; +import com.isode.stroke.signals.Slot; +import java.util.Vector; + +public class StanzaAckResponderTest { + + private Vector<Long> acks = new Vector<Long>(); + + private Message createMessage(final String id) { + Message result = new Message(); + result.setID(id); + return result; + } + + private StanzaAckResponder createResponder() { + StanzaAckResponder responder = new StanzaAckResponder(); + responder.onAck.connect(new Slot1<Long>() { + @Override + public void call(Long l) { + handleAck(l); + } + }); + return responder; + } + + private void handleAck(Long h) { + acks.add(h); + } + + @Test + public void testHandleAckRequestReceived_AcksStanza() { + StanzaAckResponder testling = createResponder(); + testling.handleStanzaReceived(); + + testling.handleAckRequestReceived(); + + assertEquals(1, (acks.size())); + assertEquals(Long.valueOf(1L), acks.get(0)); + } + + @Test + public void testHandleAckRequestReceived_AcksMultipleStanzas() { + StanzaAckResponder testling = createResponder(); + testling.handleStanzaReceived(); + testling.handleStanzaReceived(); + + testling.handleAckRequestReceived(); + + assertEquals(1, (acks.size())); + assertEquals(Long.valueOf(2L), acks.get(0)); + } + + @Test + public void testHandleAckRequestReceived_MultipleAcks() { + StanzaAckResponder testling = createResponder(); + testling.handleStanzaReceived(); + testling.handleAckRequestReceived(); + + testling.handleStanzaReceived(); + testling.handleAckRequestReceived(); + + assertEquals(2, (acks.size())); + assertEquals(Long.valueOf(1L), acks.get(0)); + assertEquals(Long.valueOf(2L), acks.get(1)); + } + + // Handle stanza ack count wrapping, as per the XEP + @Test + public void testHandleAckRequestReceived_WrapAround() { + StanzaAckResponder testling = createResponder(); + testling.handledStanzasCount = Long.parseLong("4294967295"); + testling.handleStanzaReceived(); + testling.handleStanzaReceived(); + + testling.handleAckRequestReceived(); + + assertEquals(1, (acks.size())); + assertEquals(Long.valueOf(1L), acks.get(0)); + } + +}
\ No newline at end of file |