From 00b0f316b9125031f30151cacdf2dcf217b8fa01 Mon Sep 17 00:00:00 2001 From: Gurmeen Bindra Date: Mon, 16 Apr 2012 10:22:16 +0100 Subject: Port Error parser Tests to stroke from Swiften Junit tests ported from Swiften to stroke. Test-information: ran the tests from Eclipse IDE diff --git a/src/com/isode/stroke/parser/payloadparsers/ErrorParser.java b/src/com/isode/stroke/parser/payloadparsers/ErrorParser.java index 7ff0b49..32fe8a5 100644 --- a/src/com/isode/stroke/parser/payloadparsers/ErrorParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/ErrorParser.java @@ -10,7 +10,6 @@ package com.isode.stroke.parser.payloadparsers; import com.isode.stroke.elements.ErrorPayload; -import com.isode.stroke.elements.Payload; import com.isode.stroke.parser.AttributeMap; import com.isode.stroke.parser.GenericPayloadParser; import com.isode.stroke.parser.PayloadParser; 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( + ""+ + ""+ + "boo"+ + ""); + 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( + ""+ + ""+ + ""+ + "boo"+ + ""); + 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); + } + +} -- cgit v0.10.2-6-g49f6