diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2012-04-17 09:29:05 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-19 10:45:53 (GMT) |
commit | d9d9451156ee8a4315de30571131d114af205fa1 (patch) | |
tree | 24d0dfb36be867651c39ff6898c944ed035e7f5b /test | |
parent | b54bc5406f95902ce2438ac64a19390ae0f2f409 (diff) | |
download | stroke-d9d9451156ee8a4315de30571131d114af205fa1.zip stroke-d9d9451156ee8a4315de30571131d114af205fa1.tar.bz2 |
Port MUC Payload Parsers from Swiften to Stroke
This patch ports the MUC Payload parsers from swiften to stroke.
Test-information:
ported junits work fine
Diffstat (limited to 'test')
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/MUCAdminPayloadParserTest.java | 54 | ||||
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParserTest.java | 102 |
2 files changed, 156 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/MUCAdminPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MUCAdminPayloadParserTest.java new file mode 100644 index 0000000..0a4a6b0 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/MUCAdminPayloadParserTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2011, Kevin Smith + * All rights reserved. + */ +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.isode.stroke.elements.MUCAdminPayload; +import com.isode.stroke.elements.MUCItem; +import com.isode.stroke.elements.MUCOccupant; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; + +public class MUCAdminPayloadParserTest { + private static MUCAdminPayload parse(String xmlString) { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertTrue(parser.parse(xmlString)); + + Payload payload = null; + do { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + eventLoop.processEvents(); + payload = parser.getPayload(); + } while (payload == null); + + return (MUCAdminPayload) payload; + } + + @Test + public void testParse() throws Exception{ + MUCAdminPayload payload = (parse("<query xmlns=\"http://jabber.org/protocol/muc#admin\">" + + "<item affiliation=\"owner\" role=\"visitor\">" + + "<actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>")); + MUCItem item = payload.getItems().get(0); + assertEquals(MUCOccupant.Affiliation.Owner, item.affiliation); + assertEquals(MUCOccupant.Role.Visitor, item.role); + assertEquals(new JID("kev@tester.lit"), item.actor); + assertEquals("malice", item.reason); + } +} diff --git a/test/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParserTest.java new file mode 100644 index 0000000..a334285 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/MUCUserPayloadParserTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2011, Kevin Smith + * All rights reserved. + */ +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.*; + +import org.junit.Test; +import com.isode.stroke.elements.MUCDestroyPayload; +import com.isode.stroke.elements.MUCItem; +import com.isode.stroke.elements.MUCOccupant; +import com.isode.stroke.elements.MUCUserPayload; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.jid.JID; + +public class MUCUserPayloadParserTest { + + private static MUCUserPayload parse(String xmlString) { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertTrue(parser.parse(xmlString)); + + Payload payload = null; + do { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + eventLoop.processEvents(); + payload = parser.getPayload(); + } while (payload == null); + + return (MUCUserPayload) payload; + } + + @Test + public void testParse() { + boolean found110 = false; + boolean found210 = false; + + MUCUserPayload payload = parse("<x xmlns=\"http://jabber.org/protocol/muc#user\"><status code='110'/>" + + "<item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/>" + + "<reason>malice</reason></item><status code='210'/></x>"); + + for (MUCUserPayload.StatusCode status : payload.getStatusCodes()) { + if (status.code == 110) found110 = true; + if (status.code == 210) found210 = true; + } + + MUCItem item = payload.getItems().get(0); + assertEquals(MUCOccupant.Affiliation.Owner, item.affiliation); + assertEquals(MUCOccupant.Role.Visitor, item.role); + assertEquals(new JID("kev@tester.lit"), item.actor); + assertEquals("malice", item.reason); + assertTrue(found110); + assertTrue(found210); + } + + @Test + public void testParseEmpty() { + MUCUserPayload payload = parse("<x xmlns=\"http://jabber.org/protocol/muc#user\">" + + "<destroy jid='alice@wonderland.lit'><reason>bert</reason></destroy></x>"); + assertTrue(payload != null); + assertTrue(payload.getItems().isEmpty()); + } + + @Test + public void testParseDestroy() { + MUCUserPayload payload = parse("<x xmlns=\"http://jabber.org/protocol/muc#user\">" + + "<destroy jid='alice@wonderland.lit'><reason>bert</reason></destroy></x>"); + assertTrue(payload!= null); + MUCDestroyPayload destroy = (MUCDestroyPayload)(payload.getPayload()); + assertTrue(destroy != null); + assertEquals("bert", destroy.getReason()); + assertEquals(new JID("alice@wonderland.lit"), destroy.getNewVenue()); + } + + @Test + public void testParseInvite() { + MUCUserPayload payload = parse("<x xmlns=\"http://jabber.org/protocol/muc#user\">" + + "<invite from='crone1@shakespeare.lit/desktop' to='alice@wonderland.lit/xxx'> " + + "<reason>Hey Hecate, this is the place for all good witches!</reason> " + + "</invite> <password>cauldronburn</password></x>"); + assertTrue(payload != null); + assertTrue(payload.getInvite() != null); + assertTrue(payload.getPassword() != null); + assertEquals("cauldronburn", payload.getPassword()); + MUCUserPayload.Invite invite = payload.getInvite(); + assertEquals("Hey Hecate, this is the place for all good witches!", invite.reason); + assertEquals(new JID("crone1@shakespeare.lit/desktop"), invite.from); + assertEquals(new JID("alice@wonderland.lit/xxx"), invite.to); + } + +} |