]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
5cdbe788be48f42a591bbec3d175a6ea11eced80
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 package org.collectionspace.services.id.test;
25
26 import junit.framework.TestCase;
27 import org.collectionspace.services.id.StoredValueIDGeneratorPart;
28 import org.collectionspace.services.id.StringIDGeneratorPart;
29
30 /**     
31  * StringIDGeneratorPartTest
32  *
33  * Test class for StringIDGeneratorPart.
34  *
35  * $LastChangedRevision$
36  * $LastChangedDate$
37  */
38 public class StringIDGeneratorPartTest extends TestCase {
39
40         StoredValueIDGeneratorPart part;
41
42         public void testNullInitialValue() {
43                 try {
44                         part = new StringIDGeneratorPart(null);
45                         fail("Should have thrown IllegalArgumentException here");
46                 } catch (IllegalArgumentException expected) {
47                         // This Exception should be thrown, and thus the test should pass.
48                 }
49         }
50
51         public void testEmptyInitialValue() {
52                 try {
53                         part = new StringIDGeneratorPart("");
54                         fail("Should have thrown IllegalArgumentException here");
55                 } catch (IllegalArgumentException expected) {
56                         // This Exception should be thrown, and thus the test should pass.
57                 }
58         }
59
60         public void testGetInitialID() {
61                 part = new StringIDGeneratorPart("-");
62                 assertEquals("-", part.getInitialID());
63         }
64
65         public void testGetCurrentID() {
66                 part = new StringIDGeneratorPart("- -");
67                 assertEquals("- -", part.getCurrentID());
68         }
69         
70         public void testNewID() {
71                 part = new StringIDGeneratorPart("E");          
72                 assertEquals("E", part.newID());        
73                 part = new StringIDGeneratorPart("XYZ");                
74                 assertEquals("XYZ", part.newID());              
75         }
76
77         public void testIsValidID() {
78                 part = new StringIDGeneratorPart("-");
79                 assertTrue(part.isValidID("-"));
80                 part = new StringIDGeneratorPart("TE");
81                 assertTrue(part.isValidID("TE"));
82                 
83         part = new StringIDGeneratorPart("-");
84         assertFalse(part.isValidID(null));       
85         part = new StringIDGeneratorPart("-");
86         assertFalse(part.isValidID(""));
87                 part = new StringIDGeneratorPart("-");
88                 assertFalse(part.isValidID("--"));
89                 part = new StringIDGeneratorPart("TE");
90                 assertFalse(part.isValidID("T"));
91                 part = new StringIDGeneratorPart("T");
92                 assertFalse(part.isValidID("TE"));      
93         }       
94
95 /*
96         public void testIsValidIDWithRegexChars() {
97                 // Test chars with special meaning in regexes.
98                 // @TODO Will throw a PatternSyntaxException; we need to catch this.
99                 part = new StringIDGeneratorPart("*");
100                 assertTrue(part.isValidID("*"));
101                 part = new StringIDGeneratorPart("T*E");
102                 assertTrue(part.isValidID("T*E"));
103     }
104 */
105
106         // @TODO: Add more tests of boundary conditions, exceptions ...
107  
108 }