source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/OIDTest.java@ 3284

Last change on this file since 3284 was 3284, checked in by kjdon, 22 years ago

more functionality added along with Test classes

  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1package org.greenstone.gsdl3.util;
2
3import junit.framework.*;
4
5public class OIDTest extends TestCase {
6
7 /** what type of test - used by the testing framework */
8 public static final String TEST_ALL_TEST_TYPE="UNIT";
9
10 private static final String empty = "";
11 private static final String oid1="HASH123";
12 private static final String oid2="HASH123.1";
13 private static final String oid3="HASH123.1.2";
14 private static final String oidfc = oid1+".fc";
15 private static final String oidlc = oid1+".lc";
16 private static final String oidpr = oid1+".pr";
17 private static final String oidns = oid1+".ns";
18 private static final String oidps = oid1+".ps";
19
20 public OIDTest(String name) {
21 super(name);
22 }
23
24 /** test suite that dynamically runs all the tests */
25 public static Test suite() {
26 return new TestSuite(OIDTest.class);
27 }
28
29 public void testGetTop() {
30
31 assertEquals(oid1, OID.getTop(oid1));
32 assertEquals(oid1, OID.getTop(oid2));
33 assertEquals(empty, OID.getTop(empty));
34 }
35
36 public void testIsTop() {
37 assertTrue(!OID.isTop(empty));
38 assertTrue(OID.isTop(oid1));
39 assertTrue(!OID.isTop(oid2));
40 }
41
42 public void testGetParent() {
43
44 assertEquals(empty, OID.getParent(oid1));
45 assertEquals(oid1, OID.getParent(oid2));
46 assertEquals(empty, OID.getParent(empty));
47
48 }
49
50 public void testTranslateParent() {
51 String short_id = "\".1";
52 assertEquals(oid2, OID.translateParent(short_id, oid1));
53 // should return the original oid if its not a shortened form
54 assertEquals(oid2, OID.translateParent(oid2, oid1));
55
56 }
57
58 public void testShrinkParent() {
59 String short_oid2 = "\".1";
60 String short_oid3 = "\".2";
61
62 assertEquals(oid1, OID.shrinkParent(oid1));
63 assertEquals(short_oid2, OID.shrinkParent(oid2));
64 assertEquals(short_oid3, OID.shrinkParent(oid3));
65 }
66
67 public void testNeedsTranslating() {
68 assertTrue(!OID.needsTranslating(oid1));
69 assertTrue(!OID.needsTranslating(oid2));
70 assertTrue(OID.needsTranslating(oidfc));
71 assertTrue(OID.needsTranslating(oidlc));
72 assertTrue(OID.needsTranslating(oidpr));
73 assertTrue(OID.needsTranslating(oidns));
74 assertTrue(OID.needsTranslating(oidps));
75
76 }
77
78 public void testStripSuffix() {
79 assertEquals(oid1, OID.stripSuffix(oidfc));
80 assertEquals(oid1, OID.stripSuffix(oidlc));
81 assertEquals(oid1, OID.stripSuffix(oidpr));
82 assertEquals(oid1, OID.stripSuffix(oidns));
83 assertEquals(oid1, OID.stripSuffix(oidps));
84 }
85
86 public void testIsChildOf() {
87 assertTrue(OID.isChildOf(oid1, oid2));
88 assertTrue(OID.isChildOf(oid1, oid3));
89 assertTrue(OID.isChildOf(oid2, oid3));
90 assertTrue(!OID.isChildOf(oid3, oid1));
91 assertTrue(!OID.isChildOf(oid1, oid1));
92 }
93
94}
Note: See TracBrowser for help on using the repository browser.