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

Last change on this file since 16869 was 16869, checked in by kjdon, 16 years ago

added license message

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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
49 assertEquals(oid1, OID.getTop(oid1));
50 assertEquals(oid1, OID.getTop(oid2));
51 assertEquals(empty, OID.getTop(empty));
52 }
53
54 public void testIsTop() {
55 assertTrue(!OID.isTop(empty));
56 assertTrue(OID.isTop(oid1));
57 assertTrue(!OID.isTop(oid2));
58 }
59
60 public void testGetParent() {
61
62 assertEquals(empty, OID.getParent(oid1));
63 assertEquals(oid1, OID.getParent(oid2));
64 assertEquals(empty, OID.getParent(empty));
65
66 }
67
68 public void testTranslateParent() {
69 String short_id = "\".1";
70 assertEquals(oid2, OID.translateParent(short_id, oid1));
71 // should return the original oid if its not a shortened form
72 assertEquals(oid2, OID.translateParent(oid2, oid1));
73
74 }
75
76 public void testShrinkParent() {
77 String short_oid2 = "\".1";
78 String short_oid3 = "\".2";
79
80 assertEquals(oid1, OID.shrinkParent(oid1));
81 assertEquals(short_oid2, OID.shrinkParent(oid2));
82 assertEquals(short_oid3, OID.shrinkParent(oid3));
83 }
84
85 public void testNeedsTranslating() {
86 assertTrue(!OID.needsTranslating(oid1));
87 assertTrue(!OID.needsTranslating(oid2));
88 assertTrue(OID.needsTranslating(oidfc));
89 assertTrue(OID.needsTranslating(oidlc));
90 assertTrue(OID.needsTranslating(oidpr));
91 assertTrue(OID.needsTranslating(oidns));
92 assertTrue(OID.needsTranslating(oidps));
93
94 }
95
96 public void testStripSuffix() {
97 assertEquals(oid1, OID.stripSuffix(oidfc));
98 assertEquals(oid1, OID.stripSuffix(oidlc));
99 assertEquals(oid1, OID.stripSuffix(oidpr));
100 assertEquals(oid1, OID.stripSuffix(oidns));
101 assertEquals(oid1, OID.stripSuffix(oidps));
102 }
103
104 public void testIsChildOf() {
105 assertTrue(OID.isChildOf(oid1, oid2));
106 assertTrue(OID.isChildOf(oid1, oid3));
107 assertTrue(OID.isChildOf(oid2, oid3));
108 assertTrue(!OID.isChildOf(oid3, oid1));
109 assertTrue(!OID.isChildOf(oid1, oid1));
110 }
111
112}
Note: See TracBrowser for help on using the repository browser.