summaryrefslogtreecommitdiffstats
path: root/test/com
diff options
context:
space:
mode:
authorGurmeen Bindra <gurmeen.bindra@isode.com>2012-04-16 09:22:16 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-04-19 10:45:32 (GMT)
commit00b0f316b9125031f30151cacdf2dcf217b8fa01 (patch)
tree0784522133c67892cdd4d7e4f951700534975496 /test/com
parent1cf764950ad4675b9192a1d76e422415e377216b (diff)
downloadstroke-00b0f316b9125031f30151cacdf2dcf217b8fa01.zip
stroke-00b0f316b9125031f30151cacdf2dcf217b8fa01.tar.bz2
Port Error parser Tests to stroke from Swiften
Junit tests ported from Swiften to stroke. Test-information: ran the tests from Eclipse IDE
Diffstat (limited to 'test/com')
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/ErrorParserTest.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/ErrorParserTest.java b/test/com/isode/stroke/parser/payloadparsers/ErrorParserTest.java
new file mode 100644
index 0000000..caffbe9
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/ErrorParserTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012 Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * All rights reserved.
+ */
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.elements.ErrorPayload;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.eventloop.DummyEventLoop;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+/**
+ * Junit tests for the Error Parser
+ *
+ */
+public class ErrorParserTest {
+
+ /**
+ * Parse the xml string representing containing the error payload
+ * @param xmlString XML string not null
+ * @return Error Payload, not null
+ */
+ private static ErrorPayload 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) {
+ }
+ eventLoop.processEvents();
+ payload = parser.getPayload();
+ } while (payload == null);
+
+ return (ErrorPayload) payload;
+ }
+
+ @Test
+ public void testParse() {
+ ErrorPayload payload = parse(
+ "<error type=\"modify\">"+
+ "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"+
+ "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>"+
+ "</error>");
+ assertEquals(ErrorPayload.Condition.BadRequest, payload.getCondition());
+ assertEquals(ErrorPayload.Type.Modify, payload.getType());
+ assertEquals("boo", payload.getText());
+ assertTrue(payload.getPayload() == null);
+ }
+
+ @Test
+ public void testParseWithPayload() {
+ ErrorPayload payload = parse(
+ "<error type=\"modify\">"+
+ "<bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>"+
+ "<delay xmlns='urn:xmpp:delay' from='juliet@capulet.com/balcony' stamp='2002-09-10T23:41:07Z'/>"+
+ "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">boo</text>"+
+ "</error>");
+ assertEquals(ErrorPayload.Condition.BadRequest, payload.getCondition());
+ assertEquals(ErrorPayload.Type.Modify, payload.getType());
+ assertEquals("boo", payload.getText());
+ //TODO After porting Delay, this line should be uncommented
+ //assertTrue(payload.getPayload() instanceof Delay);
+ }
+
+}