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

Last change on this file since 18504 was 18504, checked in by oranfry, 15 years ago

a correction to the get parent test on the OID class

  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/*
2 * OIDTest.java
3 * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.util;
20
21import junit.framework.*;
22
23public class OIDTest extends TestCase {
24
25 /** what type of test - used by the testing framework */
26 public static final String TEST_ALL_TEST_TYPE="UNIT";
27
28 private static final String empty = "";
29 private static final String oid1="HASH123";
30 private static final String oid2="HASH123.1";
31 private static final String oid3="HASH123.1.2";
32 private static final String oidfc = oid1+".fc";
33 private static final String oidlc = oid1+".lc";
34 private static final String oidpr = oid1+".pr";
35 private static final String oidns = oid1+".ns";
36 private static final String oidps = oid1+".ps";
37
38 public OIDTest(String name) {
39 super(name);
40 }
41
42 /** test suite that dynamically runs all the tests */
43 public static Test suite() {
44 return new TestSuite(OIDTest.class);
45 }
46
47 public void testGetTop() {
48 assertEquals(oid1, OID.getTop(oid1));
49 assertEquals(oid1, OID.getTop(oid2));
50 assertEquals(empty, OID.getTop(empty));
51 }
52
53 public void testIsTop() {
54 assertTrue(!OID.isTop(empty));
55 assertTrue(OID.isTop(oid1));
56 assertTrue(!OID.isTop(oid2));
57 }
58
59 public void testGetParent() {
60 assertEquals(oid1, OID.getParent(oid1));
61 assertEquals(oid1, OID.getParent(oid2));
62 assertEquals(empty, OID.getParent(empty));
63 }
64
65 public void testTranslateParent() {
66 String short_id = "\".1";
67 assertEquals(oid2, OID.translateParent(short_id, oid1));
68 // should return the original oid if its not a shortened form
69 assertEquals(oid2, OID.translateParent(oid2, oid1));
70 }
71
72 public void testShrinkParent() {
73 String short_oid2 = "\".1";
74 String short_oid3 = "\".2";
75
76 assertEquals(oid1, OID.shrinkParent(oid1));
77 assertEquals(short_oid2, OID.shrinkParent(oid2));
78 assertEquals(short_oid3, OID.shrinkParent(oid3));
79 }
80
81 public void testNeedsTranslating() {
82 assertTrue(!OID.needsTranslating(oid1));
83 assertTrue(!OID.needsTranslating(oid2));
84 assertTrue(OID.needsTranslating(oidfc));
85 assertTrue(OID.needsTranslating(oidlc));
86 assertTrue(OID.needsTranslating(oidpr));
87 assertTrue(OID.needsTranslating(oidns));
88 assertTrue(OID.needsTranslating(oidps));
89
90 }
91
92 public void testStripSuffix() {
93 assertEquals(oid1, OID.stripSuffix(oidfc));
94 assertEquals(oid1, OID.stripSuffix(oidlc));
95 assertEquals(oid1, OID.stripSuffix(oidpr));
96 assertEquals(oid1, OID.stripSuffix(oidns));
97 assertEquals(oid1, OID.stripSuffix(oidps));
98 }
99
100 public void testIsChildOf() {
101 assertTrue(OID.isChildOf(oid1, oid2));
102 assertTrue(OID.isChildOf(oid1, oid3));
103 assertTrue(OID.isChildOf(oid2, oid3));
104 assertTrue(!OID.isChildOf(oid3, oid1));
105 assertTrue(!OID.isChildOf(oid1, oid1));
106 }
107
108}
Note: See TracBrowser for help on using the repository browser.