diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-12 21:25:03 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-16 19:15:24 (GMT) |
commit | 1910b4f007f2cf2f19be8793fd7ad29a729d7997 (patch) | |
tree | 75fafb7f7969b88137139cd0313d5afb52fef221 /test/com | |
parent | e868c966e23716d8a0261b222cccbeb04616e235 (diff) | |
download | stroke-1910b4f007f2cf2f19be8793fd7ad29a729d7997.zip stroke-1910b4f007f2cf2f19be8793fd7ad29a729d7997.tar.bz2 |
Add InBandRegistrationPayload Element.
Adds InBandRegistrationPayload Element, its Parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Test added for InBandRegistrationPayload Serializer, which passes.
Change-Id: Ic6cc1329f222b5a57f05ec2299e36b56f5767091
Diffstat (limited to 'test/com')
2 files changed, 134 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/InBandRegistrationPayloadParserTest.java b/test/com/isode/stroke/parser/payloadparsers/InBandRegistrationPayloadParserTest.java new file mode 100644 index 0000000..9e93b37 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/InBandRegistrationPayloadParserTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.elements.InBandRegistrationPayload; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.InBandRegistrationPayloadParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; + +public class InBandRegistrationPayloadParserTest { + + public InBandRegistrationPayloadParserTest() { + + } + + @Test + public void testParse() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<query xmlns=\"jabber:iq:register\">" + + "<registered/>" + + "</query>")); + + InBandRegistrationPayload payload = (InBandRegistrationPayload)parser.getPayload(); + assertNotNull(payload); + assertTrue(payload.isRegistered()); + } + + @Test + public void testParse_Form() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<query xmlns=\"jabber:iq:register\">" + + "<instructions>Use the enclosed form to register.</instructions>" + + "<x type=\"form\" xmlns=\"jabber:x:data\">" + + "<title>Contest Registration</title>" + + "<field type=\"hidden\" var=\"FORM_TYPE\">" + + "<value>jabber:iq:register</value>" + + "</field>" + + "</x>" + + "</query>")); + + InBandRegistrationPayload payload = (InBandRegistrationPayload)parser.getPayload(); + assertNotNull(payload); + assertEquals("Use the enclosed form to register.", payload.getInstructions()); + + Form form = payload.getForm(); + assertNotNull(form); + assertEquals("Contest Registration", form.getTitle()); + assertEquals(Form.Type.FORM_TYPE, form.getType()); + assertEquals("jabber:iq:register", form.getFormType()); + + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/InBandRegistrationPayloadSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/InBandRegistrationPayloadSerializerTest.java new file mode 100644 index 0000000..6880f5d --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/InBandRegistrationPayloadSerializerTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010-2013 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.serializer.payloadserializers; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.payloadserializers.InBandRegistrationPayloadSerializer; +import com.isode.stroke.elements.InBandRegistrationPayload; +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.FormField; + +public class InBandRegistrationPayloadSerializerTest { + + /** + * Default Constructor. + */ + public InBandRegistrationPayloadSerializerTest() { + + } + + @Test + public void testSerialize() { + InBandRegistrationPayloadSerializer testling = new InBandRegistrationPayloadSerializer(); + InBandRegistrationPayload registration = new InBandRegistrationPayload(); + registration.setRegistered(true); + + String expectedResult = + "<query xmlns=\"jabber:iq:register\">" + + "<registered/>" + + "</query>"; + + assertEquals(expectedResult, testling.serialize(registration)); + } + + @Test + public void testSerialize_Form() { + InBandRegistrationPayloadSerializer testling = new InBandRegistrationPayloadSerializer(); + InBandRegistrationPayload registration = new InBandRegistrationPayload(); + registration.setInstructions("Use the enclosed form to register."); + + Form form = new Form(); + form.setTitle("Contest Registration"); + + FormField field = new FormField(FormField.Type.HIDDEN_TYPE, "jabber:iq:register"); + field.setName("FORM_TYPE"); + form.addField(field); + registration.setForm(form); + + String expectedResult = + "<query xmlns=\"jabber:iq:register\">" + + "<instructions>Use the enclosed form to register.</instructions>" + + "<x type=\"form\" xmlns=\"jabber:x:data\">" + + "<title>Contest Registration</title>" + + "<field type=\"hidden\" var=\"FORM_TYPE\">" + + "<value>jabber:iq:register</value>" + + "</field>" + + "</x>" + + "</query>"; + + assertEquals(expectedResult, testling.serialize(registration)); + } +}
\ No newline at end of file |