01: /**
02: * Copyright (C) 2004-2007 Jive Software. All rights reserved.
03: *
04: * This software is published under the terms of the GNU Public License (GPL),
05: * a copy of which is included in this distribution.
06: */package org.jivesoftware.util;
07:
08: import junit.framework.TestCase;
09: import org.xmpp.packet.JID;
10:
11: /**
12: * Test cases for the JID class.
13: *
14: * @author Gaston Dombiak
15: */
16: public class JIDTest extends TestCase {
17:
18: public void testDomain() {
19: new JID("mycomapny.com");
20: new JID("wfink-adm");
21:
22: boolean failed = false;
23: try {
24: new JID("wfink adm");
25: } catch (Exception e) {
26: failed = true;
27: }
28: assertTrue("A domain with spaces was accepted", failed);
29:
30: failed = false;
31: try {
32: new JID("wfink_adm");
33: } catch (Exception e) {
34: failed = true;
35: }
36: assertTrue("A domain with _ was accepted", failed);
37: }
38:
39: public void testUsernames() {
40: new JID("john@mycomapny.com");
41: new JID("john_paul@mycomapny.com");
42: new JID("john-paul@mycomapny.com");
43: boolean failed = false;
44: try {
45: new JID("john paul@mycomapny.com");
46: } catch (Exception e) {
47: failed = true;
48: }
49: assertTrue("A username with spaces was accepted", failed);
50: }
51:
52: public void testCompare() {
53: JID jid1 = new JID("john@mycomapny.com");
54: JID jid2 = new JID("john@mycomapny.com");
55: assertEquals("Failed to compare 2 similar JIDs", 0, jid1
56: .compareTo(jid2));
57: assertEquals("Failed to recognize equal JIDs", jid1, jid2);
58:
59: jid1 = new JID("john@mycomapny.com");
60: jid2 = new JID("mycomapny.com");
61: assertTrue("Failed to recognized bigger JID", jid1
62: .compareTo(jid2) > 0);
63: assertFalse("Failed to recognize different JIDs", jid1
64: .equals(jid2));
65:
66: jid1 = new JID("john@mycomapny.com");
67: jid2 = new JID("mycomapny.com/resource");
68: assertTrue("Failed to recognized bigger JID", jid1
69: .compareTo(jid2) > 0);
70: assertFalse("Failed to recognize different JIDs", jid1
71: .equals(jid2));
72:
73: jid1 = new JID("john@mycomapny.com");
74: jid2 = new JID("john@mycomapny.com/resource");
75: assertTrue("Failed to recognized bigger JID", jid1
76: .compareTo(jid2) < 0);
77: assertFalse("Failed to recognize different JIDs", jid1
78: .equals(jid2));
79:
80: }
81: }
|