]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
156d36894a051b9a577cac2ac7f2d8462152475f
[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 org.collectionspace.services.id.*;
27
28 import org.collectionspace.services.common.repository.BadRequestException; 
29
30 import junit.framework.TestCase;
31 import static org.junit.Assert.*;
32
33 /**
34  * IDGeneratorSerializerTest
35  *
36  * Unit tests of the ID Service's IDGeneratorSerializer class.
37  *
38  * $LastChangedRevision: 302 $
39  * $LastChangedDate$
40  */
41 public class IDGeneratorSerializerTest extends TestCase {
42
43   String serializedGenerator;
44   SettableIDGenerator generator;
45   
46   final static String DEFAULT_CSID = "TEST-1";
47
48   final static String DEFAULT_SERIALIZED_ID_GENERATOR =
49     "<org.collectionspace.services.id.SettableIDGenerator>\n" +
50     "  <parts/>\n" +
51     "</org.collectionspace.services.id.SettableIDGenerator>";
52
53     // @TODO We may want to canonicalize (or otherwise normalize) the
54     // expected and actual XML in these tests, to avoid failures resulting
55     // from differences in whitespace, etc.
56     public void testSerializeIDGenerator() throws BadRequestException {
57       SettableIDGenerator tempGenerator = new SettableIDGenerator();
58         assertEquals(DEFAULT_SERIALIZED_ID_GENERATOR,
59             IDGeneratorSerializer.serialize(tempGenerator));
60     }
61
62     public void testSerializeNullIDGenerator() {
63       try {
64         String serializedPattern = IDGeneratorSerializer.serialize(null);
65             fail("Should have thrown BadRequestException here");
66         } catch (BadRequestException expected) {
67             // This Exception should be thrown, and thus the test should pass.
68         }
69     }
70
71     public void testDeserializeIDGenerator() {
72       // This test will fail with different hash codes unless
73       // we add an IDGenerator.equals() method that explicitly defines
74       // object equality as, for instance, having identical values
75       // in each of its instance variables.
76       // IDGenerator generator =
77       //     IDGeneratorSerializer.deserialize(DEFAULT_SERIALIZED_ID_PATTERN);
78       // assertEquals(generator, new IDGenerator(DEFAULT_CSID));
79     }
80
81     public void testDeserializeNullSerializedIDGenerator() {
82       try {
83         SettableIDGenerator tempGenerator =
84             IDGeneratorSerializer.deserialize(null);
85             fail("Should have thrown BadRequestException here");
86         } catch (BadRequestException expected) {
87             // This Exception should be thrown, and thus the test should pass.
88         }
89     }
90
91     public void testDeserializeInvalidSerializedIDGenerator() {
92       try {
93         IDGenerator tempGenerator =
94             IDGeneratorSerializer.deserialize("<invalid_serialized_generator/>");
95             fail("Should have thrown BadRequestException here");
96         } catch (BadRequestException expected) {
97             // This Exception should be thrown, and thus the test should pass.
98         }
99     }
100     
101 }