01: /**********************************************************************
02: Copyright (c) 2006 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: **********************************************************************/package org.jpox.store.poid;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: * Unit tests for the "uuid-hex" identity generation.
24: *
25: * @version $Revision: 1.2 $
26: */
27: public class UUIDHexPoidGeneratorTest extends TestCase {
28: /**
29: * Test for the length of the generated "uuid-hex" string.
30: * Should be 32 characters as per the JDO2 spec.
31: */
32: public void testStringLength() {
33: UUIDHexPoidGenerator gen = new UUIDHexPoidGenerator("Test",
34: null);
35: for (int i = 0; i < 10; i++) {
36: Object id = gen.next();
37: assertEquals(32, id.toString().length());
38: }
39: }
40:
41: /**
42: * Test for equality of any identifiers generated. Should be unique.
43: */
44: public void testEquality() {
45: // Create 1000 identifiers
46: String[] ids = new String[1000];
47: UUIDHexPoidGenerator gen = new UUIDHexPoidGenerator("Test",
48: null);
49: for (int i = 0; i < ids.length; i++) {
50: ids[i] = (String) gen.next();
51: }
52:
53: // Check for equality of any of them
54: for (int i = 0; i < ids.length; i++) {
55: for (int j = 0; j < ids.length; j++) {
56: if (i != j) {
57: assertFalse(
58: "Two uuid-hex identifiers are equal yet should be unique! : "
59: + ids[i] + " and " + ids[j], ids[i]
60: .equals(ids[j]));
61: }
62: }
63: }
64: }
65: }
|