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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.id.test;
26 import org.collectionspace.services.id.*;
28 import junit.framework.TestCase;
29 import static org.junit.Assert.*;
32 * IDGeneratorSerializerTest
34 * Unit tests of the ID Service's IDGeneratorSerializer class.
36 * $LastChangedRevision: 302 $
39 public class IDGeneratorSerializerTest extends TestCase {
41 String serializedGenerator;
42 BaseIDGenerator generator;
44 final static String DEFAULT_CSID = "TEST-1";
46 final static String DEFAULT_SERIALIZED_ID_GENERATOR =
47 "<org.collectionspace.services.id.BaseIDGenerator>\n" +
48 " <csid>" + DEFAULT_CSID + "</csid>\n" +
50 " <description></description>\n" +
52 "</org.collectionspace.services.id.BaseIDGenerator>";
54 // @TODO We may want to canonicalize (or otherwise normalize) the expected and
55 // actual XML in these tests, to avoid failures resulting from differences in
57 public void testSerializeIDGenerator() {
58 BaseIDGenerator generator = new BaseIDGenerator(DEFAULT_CSID);
59 assertEquals(DEFAULT_SERIALIZED_ID_GENERATOR, IDGeneratorSerializer.serialize(generator));
62 public void testSerializeNullIDGenerator() {
64 String serializedPattern = IDGeneratorSerializer.serialize(null);
65 fail("Should have thrown IllegalArgumentException here");
66 } catch (IllegalArgumentException expected) {
67 // This Exception should be thrown, and thus the test should pass.
71 public void testDeserializeIDGenerator() {
72 // This test will fail with different hash codes unless we add an IDGenerator.equals()
73 // method that explicitly defines object equality as, for instance, having identical values
74 // in each of its instance variables.
75 // IDGenerator generator = IDGeneratorSerializer.deserialize(DEFAULT_SERIALIZED_ID_PATTERN);
76 // assertEquals(generator, new IDGenerator(DEFAULT_CSID));
79 public void testDeserializeNullSerializedIDGenerator() {
81 BaseIDGenerator generator = IDGeneratorSerializer.deserialize(null);
82 fail("Should have thrown IllegalArgumentException here");
83 } catch (IllegalArgumentException expected) {
84 // This Exception should be thrown, and thus the test should pass.
88 public void testDeserializeInvalidSerializedIDGenerator() {
90 IDGenerator generator = IDGeneratorSerializer.deserialize("<invalid_serialized_generator/>");
91 fail("Should have thrown IllegalArgumentException here");
92 } catch (IllegalArgumentException expected) {
93 // This Exception should be thrown, and thus the test should pass.