Source Code Cross Referenced for T_UUIDFactory.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » unitTests » services » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derbyTesting.unitTests.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.unitTests.services.T_UUIDFactory
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derbyTesting.unitTests.services;
023:
024:        import org.apache.derbyTesting.unitTests.harness.T_Generic;
025:        import org.apache.derbyTesting.unitTests.harness.T_Fail;
026:
027:        import org.apache.derby.catalog.UUID;
028:
029:        import org.apache.derby.iapi.services.monitor.Monitor;
030:        import org.apache.derby.iapi.error.StandardException;
031:
032:        import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
033:
034:        import org.apache.derby.iapi.services.uuid.UUIDFactory;
035:
036:        /**
037:         Test to ensure a implementation of the UUID module
038:         implements the protocol correctly. 
039:         */
040:
041:        public class T_UUIDFactory extends T_Generic {
042:
043:            protected UUIDFactory factory;
044:            boolean resultSoFar;
045:
046:            public T_UUIDFactory() {
047:                super ();
048:            }
049:
050:            protected String getModuleToTestProtocolName() {
051:
052:                return "A.Dummy.Name";
053:            }
054:
055:            /**
056:            	Run all the tests, each test that starts with 'S' is a single user
057:            	test, each test that starts with 'M' is a multi-user test.
058:
059:            	@exception T_Fail The test failed in some way.
060:             */
061:            protected void runTests() throws T_Fail {
062:
063:                factory = Monitor.getMonitor().getUUIDFactory();
064:                if (factory == null) {
065:                    throw T_Fail.testFailMsg(getModuleToTestProtocolName()
066:                            + " module not started.");
067:                }
068:
069:                if (!testUUID())
070:                    throw T_Fail.testFailMsg("testUUID indicated failure");
071:            }
072:
073:            /*
074:             ** Tests
075:             */
076:
077:            protected boolean testUUID() {
078:                resultSoFar = true;
079:
080:                UUID uuid1 = factory.createUUID();
081:                UUID uuid2 = factory.createUUID();
082:
083:                if (uuid1.equals(uuid2)) {
084:                    // Resolve: format this with a message factory
085:                    String message = "UUID factory created matching UUIDS '%0' and '%1'";
086:                    out.printlnWithHeader(message);
087:                    resultSoFar = false;
088:                }
089:
090:                if (!uuid1.equals(uuid1)) {
091:                    // Resolve: format this with a message factory
092:                    String message = "UUID '%0' does not equal itself";
093:                    resultSoFar = false;
094:                }
095:
096:                if (uuid1.hashCode() != uuid1.hashCode()) {
097:                    // Resolve: format this with a message factory
098:                    String message = "UUID '%0' does not hash to the same thing twice.";
099:                    out.printlnWithHeader(message);
100:                    resultSoFar = false;
101:                }
102:
103:                // Check that we can go from UUID to string and back.
104:
105:                String suuid1 = uuid1.toString();
106:                UUID uuid3 = factory.recreateUUID(suuid1);
107:                if (!uuid3.equals(uuid1)) {
108:                    // Resolve: format this with a message factory
109:                    String message = "Couldn't recreate UUID: "
110:                            + uuid3.toString() + " != " + uuid1.toString();
111:                    out.printlnWithHeader(message);
112:                    resultSoFar = false;
113:                }
114:
115:                // Check that we can transform from string to UUID and back
116:                // for a few "interesting" UUIDs.
117:
118:                // This one came from GUIDGEN.EXE.
119:                testUUIDConversions(out, "7878FCD0-DA09-11d0-BAFE-0060973F0942");
120:
121:                // Interesting bit patterns.
122:                testUUIDConversions(out, "80706050-4030-2010-8070-605040302010");
123:                testUUIDConversions(out, "f0e0d0c0-b0a0-9080-7060-504030201000");
124:                testUUIDConversions(out, "00000000-0000-0000-0000-000000000000");
125:                testUUIDConversions(out, "ffffffff-ffff-ffff-ffff-ffffffffffff");
126:
127:                // A couple self-generated ones for good measure.
128:                testUUIDConversions(out, factory.createUUID().toString());
129:                testUUIDConversions(out, factory.createUUID().toString());
130:
131:                return resultSoFar;
132:
133:            }
134:
135:            private void testUUIDConversions(HeaderPrintWriter out,
136:                    String uuidstring) {
137:                UUID uuid = factory.recreateUUID(uuidstring);
138:                if (!uuidstring.equalsIgnoreCase(uuid.toString())) {
139:                    // Resolve: format this with a message factory
140:                    String message = "Couldn't recreate UUID String: "
141:                            + uuidstring + " != " + uuid.toString();
142:                    out.printlnWithHeader(message);
143:                    resultSoFar = false;
144:                }
145:
146:                byte[] uuidByteArray = uuid.toByteArray();
147:                UUID uuid_b = factory.recreateUUID(uuidByteArray);
148:                if (!uuid_b.equals(uuid)) {
149:                    // Resolve: format this with a message factory
150:                    String badByteArrayString = "";
151:                    for (int ix = 0; ix < 16; ix++) {
152:                        badByteArrayString += Integer
153:                                .toHexString(0x00ff & uuidByteArray[ix])
154:                                + ".";
155:                    }
156:
157:                    String message = "Conversion error: " + uuidstring + " != "
158:                            + badByteArrayString;
159:                    out.printlnWithHeader(message);
160:                    resultSoFar = false;
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.