diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-29 20:15:15 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-07-06 14:43:56 (GMT) |
commit | c2ed130b2356a4a1b10a0a7854517bcdfcb13ff6 (patch) | |
tree | 4a88970320150acc479808b02e0cb190145c24af /test/com/isode | |
parent | c23c591f888f6cb1054bd110f7b6ffff9a1173a0 (diff) | |
download | stroke-c2ed130b2356a4a1b10a0a7854517bcdfcb13ff6.zip stroke-c2ed130b2356a4a1b10a0a7854517bcdfcb13ff6.tar.bz2 |
Completes JID functionalities.
Completes JID by providing all features Swiften provides including Escaped and Unescaped Node.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Test added for JID, which passes.
Change-Id: Ia61dad0ed93a153186b9f78e2669f675f51e3734
Diffstat (limited to 'test/com/isode')
-rw-r--r-- | test/com/isode/stroke/jid/JIDTest.java | 449 |
1 files changed, 449 insertions, 0 deletions
diff --git a/test/com/isode/stroke/jid/JIDTest.java b/test/com/isode/stroke/jid/JIDTest.java new file mode 100644 index 0000000..9a7b16a --- /dev/null +++ b/test/com/isode/stroke/jid/JIDTest.java @@ -0,0 +1,449 @@ +/* + * Copyright (c) 2010 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.jid; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import com.isode.stroke.jid.JID; + +public class JIDTest { + + public JIDTest() { + + } + + @Test + public void testConstructorWithString() { + JID testling = new JID("foo@bar/baz"); + + assertEquals("foo", testling.getNode()); + assertEquals("bar", testling.getDomain()); + assertEquals("baz", testling.getResource()); + assertFalse(testling.isBare()); + } + + + @Test + public void testConstructorWithString_NoResource() { + JID testling = new JID("foo@bar"); + + assertEquals("foo", testling.getNode()); + assertEquals("bar", testling.getDomain()); + assertEquals("", testling.getResource()); + assertTrue(testling.isBare()); + } + + + @Test + public void testConstructorWithString_EmptyResource() { + JID testling = new JID("bar/"); + + assertTrue(testling.isValid()); + assertFalse(testling.isBare()); + } + + + @Test + public void testConstructorWithString_NoNode() { + JID testling = new JID("bar/baz"); + + assertEquals("", testling.getNode()); + assertEquals("bar", testling.getDomain()); + assertEquals("baz", testling.getResource()); + assertFalse(testling.isBare()); + } + + + @Test + public void testConstructorWithString_OnlyDomain() { + JID testling = new JID("bar"); + + assertEquals("", testling.getNode()); + assertEquals("bar", testling.getDomain()); + assertEquals("", testling.getResource()); + assertTrue(testling.isBare()); + } + + + @Test + public void testConstructorWithString_InvalidDomain() { + assertFalse(new JID("foo@bar,baz").isValid()); + } + + + @Test + public void testConstructorWithString_UpperCaseNode() { + JID testling = new JID("FoΩ@bar"); + + assertEquals("foω", testling.getNode()); + assertEquals("bar", testling.getDomain()); + } + + + @Test + public void testConstructorWithString_UpperCaseDomain() { + JID testling = new JID("FoΩ"); + + assertEquals("foω", testling.getDomain()); + } + + + @Test + public void testConstructorWithString_UpperCaseResource() { + JID testling = new JID("bar/FoΩ"); + + assertEquals(testling.getResource(), "FoΩ"); + } + + + @Test + public void testConstructorWithString_EmptyNode() { + JID testling = new JID("@bar"); + + assertFalse(testling.isValid()); + } + + + @Test + public void testConstructorWithString_IllegalResource() { + JID testling = new JID("foo@bar.com/رمقه ترنس "); + + assertFalse(testling.isValid()); + } + + + @Test + public void testConstructorWithString_SpacesInNode() { + assertFalse(new JID(" alice@wonderland.lit").isValid()); + assertFalse(new JID("alice @wonderland.lit").isValid()); + } + + + @Test + public void testConstructorWithStrings() { + JID testling = new JID("foo", "bar", "baz"); + + assertEquals("foo", testling.getNode()); + assertEquals("bar", testling.getDomain()); + assertEquals("baz", testling.getResource()); + } + + + @Test + public void testConstructorWithStrings_EmptyDomain() { + JID testling = new JID("foo", "", "baz"); + + assertFalse(testling.isValid()); + } + + + @Test + public void testIsBare() { + assertTrue(new JID("foo@bar").isBare()); + } + + + @Test + public void testIsBare_NotBare() { + assertFalse(new JID("foo@bar/baz").isBare()); + } + + + @Test + public void testToBare() { + JID testling = new JID("foo@bar/baz"); + + assertEquals("foo", testling.toBare().getNode()); + assertEquals("bar", testling.toBare().getDomain()); + assertTrue(testling.toBare().isBare()); + } + + + @Test + public void testToBare_EmptyNode() { + JID testling = new JID("bar/baz"); + + assertEquals("", testling.toBare().getNode()); + assertEquals("bar", testling.toBare().getDomain()); + assertTrue(testling.toBare().isBare()); + } + + + @Test + public void testToBare_EmptyResource() { + JID testling = new JID("bar/"); + + assertEquals("", testling.toBare().getNode()); + assertEquals("bar", testling.toBare().getDomain()); + assertTrue(testling.toBare().isBare()); + } + + + @Test + public void testToString() { + JID testling = new JID("foo@bar/baz"); + + assertEquals("foo@bar/baz", testling.toString()); + } + + + @Test + public void testToString_EmptyNode() { + JID testling = new JID("bar/baz"); + + assertEquals("bar/baz", testling.toString()); + } + + + @Test + public void testToString_NoResource() { + JID testling = new JID("foo@bar"); + + assertEquals("foo@bar", testling.toString()); + } + + + @Test + public void testToString_EmptyResource() { + JID testling = new JID("foo@bar/"); + + assertEquals("foo@bar/", testling.toString()); + } + + + @Test + public void testCompare_SmallerNode() { + JID testling1 = new JID("a@c"); + JID testling2 = new JID("b@b"); + + assertEquals(-1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_LargerNode() { + JID testling1 = new JID("c@a"); + JID testling2 = new JID("b@b"); + + assertEquals(1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_SmallerDomain() { + JID testling1 = new JID("x@a/c"); + JID testling2 = new JID("x@b/b"); + + assertEquals(-1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_LargerDomain() { + JID testling1 = new JID("x@b/b"); + JID testling2 = new JID("x@a/c"); + + assertEquals(1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_SmallerResource() { + JID testling1 = new JID("x@y/a"); + JID testling2 = new JID("x@y/b"); + + assertEquals(-1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_LargerResource() { + JID testling1 = new JID("x@y/b"); + JID testling2 = new JID("x@y/a"); + + assertEquals(1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_Equal() { + JID testling1 = new JID("x@y/z"); + JID testling2 = new JID("x@y/z"); + + assertEquals(0, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_EqualWithoutResource() { + JID testling1 = new JID("x@y/a"); + JID testling2 = new JID("x@y/b"); + + assertEquals(0, testling1.compare(testling2, JID.CompareType.WithoutResource)); + } + + + @Test + public void testCompare_NoResourceAndEmptyResource() { + JID testling1 = new JID("x@y/"); + JID testling2 = new JID("x@y"); + + assertEquals(1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testCompare_EmptyResourceAndNoResource() { + JID testling1 = new JID("x@y"); + JID testling2 = new JID("x@y/"); + + assertEquals(-1, testling1.compare(testling2, JID.CompareType.WithResource)); + } + + + @Test + public void testEquals() { + JID testling1 = new JID("x@y/c"); + JID testling2 = new JID("x@y/c"); + + assertTrue(testling1.compare(testling2, JID.CompareType.WithResource) == 0); + } + + + @Test + public void testEquals_NotEqual() { + JID testling1 = new JID("x@y/c"); + JID testling2 = new JID("x@y/d"); + + assertFalse(testling1.compare(testling2, JID.CompareType.WithResource) == 0); + } + + + @Test + public void testEquals_WithoutResource() { + JID testling1 = new JID("x@y/c"); + JID testling2 = new JID("x@y/d"); + + assertTrue(testling1.compare(testling2, JID.CompareType.WithoutResource) == 0); + } + + + @Test + public void testSmallerThan() { + JID testling1 = new JID("x@y/c"); + JID testling2 = new JID("x@y/d"); + + assertTrue(testling1.compare(testling2, JID.CompareType.WithResource) < 0); + } + + + @Test + public void testSmallerThan_Equal() { + JID testling1 = new JID("x@y/d"); + JID testling2 = new JID("x@y/d"); + + assertFalse(testling1.compare(testling2, JID.CompareType.WithResource) < 0); + } + + + @Test + public void testSmallerThan_Larger() { + JID testling1 = new JID("x@y/d"); + JID testling2 = new JID("x@y/c"); + + assertFalse(testling1.compare(testling2, JID.CompareType.WithResource) < 0); + } + + + @Test + public void testHasResource() { + JID testling = new JID("x@y/d"); + + assertFalse(testling.isBare()); + } + + + @Test + public void testHasResource_NoResource() { + JID testling = new JID("x@y"); + + assertTrue(testling.isBare()); + } + + + @Test + public void testGetEscapedNode() { + String escaped = JID.getEscapedNode("alice@wonderland.lit"); + assertEquals("alice\\40wonderland.lit", escaped); + + escaped = JID.getEscapedNode("\\& \" ' / <\\\\> @ :\\3a\\40"); + assertEquals("\\\\26\\20\\22\\20\\27\\20\\2f\\20\\3c\\\\\\3e\\20\\40\\20\\3a\\5c3a\\5c40", escaped); + } + + + @Test + public void testGetEscapedNode_XEP106Examples() { + assertEquals("\\2plus\\2is\\4", JID.getEscapedNode("\\2plus\\2is\\4")); + assertEquals("foo\\bar", JID.getEscapedNode("foo\\bar")); + assertEquals("foob\\41r", JID.getEscapedNode("foob\\41r")); + assertEquals(JID.getEscapedNode("space cadet"), "space\\20cadet"); + assertEquals(JID.getEscapedNode("call me \"ishmael\""), "call\\20me\\20\\22ishmael\\22"); + assertEquals(JID.getEscapedNode("at&t guy"), "at\\26t\\20guy"); + assertEquals(JID.getEscapedNode("d'artagnan"), "d\\27artagnan"); + assertEquals(JID.getEscapedNode("/.fanboy"), "\\2f.fanboy"); + assertEquals(JID.getEscapedNode("::foo::"), "\\3a\\3afoo\\3a\\3a"); + assertEquals(JID.getEscapedNode("<foo>"), "\\3cfoo\\3e"); + assertEquals(JID.getEscapedNode("user@host"), "user\\40host"); + assertEquals(JID.getEscapedNode("c:\\net"), "c\\3a\\net"); + assertEquals(JID.getEscapedNode("c:\\\\net"), "c\\3a\\\\net"); + assertEquals(JID.getEscapedNode("c:\\cool stuff"), "c\\3a\\cool\\20stuff"); + assertEquals(JID.getEscapedNode("c:\\5commas"), "c\\3a\\5c5commas"); + } + + + @Test + public void testGetEscapedNode_BackslashAtEnd() { + assertEquals("foo\\", JID.getEscapedNode("foo\\")); + } + + + @Test + public void testGetUnescapedNode() { + String input = "\\& \" ' / <\\\\> @ : \\5c\\40"; + JID testling = new JID((JID.getEscapedNode(input) + "@y")); + assertTrue(testling.isValid()); + assertEquals(input, testling.getUnescapedNode()); + } + + @Test + public void testGetUnescapedNode_XEP106Examples() { + assertEquals("\\2plus\\2is\\4", new JID("\\2plus\\2is\\4@example.com").getUnescapedNode()); + assertEquals("foo\\bar", new JID("foo\\bar@example.com").getUnescapedNode()); + assertEquals("foob\\41r", new JID("foob\\41r@example.com").getUnescapedNode()); + assertEquals("space cadet", new JID("space\\20cadet@example.com").getUnescapedNode()); + assertEquals("call me \"ishmael\"", new JID("call\\20me\\20\\22ishmael\\22@example.com").getUnescapedNode()); + assertEquals("at&t guy", new JID("at\\26t\\20guy@example.com").getUnescapedNode()); + assertEquals("d'artagnan", new JID("d\\27artagnan@example.com").getUnescapedNode()); + assertEquals("/.fanboy", new JID("\\2f.fanboy@example.com").getUnescapedNode()); + assertEquals("::foo::", new JID("\\3a\\3afoo\\3a\\3a@example.com").getUnescapedNode()); + assertEquals("<foo>", new JID("\\3cfoo\\3e@example.com").getUnescapedNode()); + assertEquals("user@host", new JID("user\\40host@example.com").getUnescapedNode()); + assertEquals("c:\\net", new JID("c\\3a\\net@example.com").getUnescapedNode()); + assertEquals("c:\\\\net", new JID("c\\3a\\\\net@example.com").getUnescapedNode()); + assertEquals("c:\\cool stuff", new JID("c\\3a\\cool\\20stuff@example.com").getUnescapedNode()); + assertEquals("c:\\5commas", new JID("c\\3a\\5c5commas@example.com").getUnescapedNode()); + } +}
\ No newline at end of file |