diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-02-15 17:24:49 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-02-29 10:39:49 (GMT) |
commit | 3bfe54c141dd3fa20e391312a0a84c75731e2b2a (patch) | |
tree | 4de10e954ff540fa6e1b70c8735ac5da14b19743 /test/com/isode/stroke/parser/BOSHBodyExtractorTest.java | |
parent | 2ebf488dfee7156fbbe0b3d3eccebe13d86a8634 (diff) | |
download | stroke-3bfe54c141dd3fa20e391312a0a84c75731e2b2a.zip stroke-3bfe54c141dd3fa20e391312a0a84c75731e2b2a.tar.bz2 |
Add Network Bosh Classes
Add the missing Bosh classes to the network packages (BoshConnection
and BoshConnectionPool), plus tests for the classes and any other
classes required by the new classes.
Test-information:
Units tests all pass ok.
Change-Id: I5c2e05bae9e678ac10d2601c7fdbdccd68d66b71
Diffstat (limited to 'test/com/isode/stroke/parser/BOSHBodyExtractorTest.java')
-rw-r--r-- | test/com/isode/stroke/parser/BOSHBodyExtractorTest.java | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/BOSHBodyExtractorTest.java b/test/com/isode/stroke/parser/BOSHBodyExtractorTest.java new file mode 100644 index 0000000..e8f0db5 --- /dev/null +++ b/test/com/isode/stroke/parser/BOSHBodyExtractorTest.java @@ -0,0 +1,101 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.parser; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.isode.stroke.base.ByteArray; + +/** + * Tests for {@link BOSHBodyExtractor} + */ +public class BOSHBodyExtractorTest { + + private final PlatformXMLParserFactory parserFactory = new PlatformXMLParserFactory(); + + @Test + public void testGetBody() { + ByteArray data = new ByteArray("<body a1='a\"1' a2=\"a'2\" boo='bar' >" + +"foo <message> <body> bar" + +"</body > "); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNotNull(testling.getBody()); + assertEquals("a\"1",testling.getBody().getAttributes().getAttribute("a1")); + assertEquals("foo <message> <body> bar",testling.getBody().getContent()); + } + + @Test + public void testGetBody_EmptyContent() { + ByteArray data = new ByteArray("<body foo='bar'/>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + + assertNotNull(testling.getBody()); + assertEquals("bar",testling.getBody().getAttributes().getAttribute("foo")); + assertTrue(testling.getBody().getContent().isEmpty()); + } + + @Test + public void testGetBody_EmptyContent2() { + ByteArray data = new ByteArray("<body foo='bar'></body>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + + assertNotNull(testling.getBody()); + assertEquals("bar",testling.getBody().getAttributes().getAttribute("foo")); + assertTrue(testling.getBody().getContent().isEmpty()); + } + + @Test + public void testGetBody_EmptyElementEmptyContent() { + ByteArray data = new ByteArray("<body/>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNotNull(testling.getBody()); + } + + @Test + public void testGetBody_InvalidStartTag() { + ByteArray data = new ByteArray("<bodi></body>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNull(testling.getBody()); + } + + @Test + public void testGetBody_InvalidStartTag2() { + ByteArray data = new ByteArray("<bodyy></body>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNull(testling.getBody()); + } + + @Test + public void testGetBody_IncompleteStartTag() { + ByteArray data = new ByteArray("<body"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNull(testling.getBody()); + } + + @Test + public void testGetBody_InvalidEndTag() { + ByteArray data = new ByteArray("<body></bodi>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNull(testling.getBody()); + } + + @Test + public void testGetBody_InvalidEndTag2() { + ByteArray data = new ByteArray("<body><b/body>"); + BOSHBodyExtractor testling = new BOSHBodyExtractor(parserFactory, data); + assertNull(testling.getBody()); + } + +} |