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