Source Code Cross Referenced for DatabaseTest.java in  » Database-DBMS » perst » org » garret » perst » 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 » perst » org.garret.perst 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $URL: DatabaseTest.java $ 
003:         * $Rev: 3582 $ 
004:         * $Date: 2007-11-25 14:29:06 +0300 (Ð’Ñ?, 25 ноÑ? 2007) $
005:         *
006:         * Copyright 2005 Netup, Inc. All rights reserved.
007:         * URL:    http://www.netup.biz
008:         * e-mail: info@netup.biz
009:         */
010:
011:        package org.garret.perst;
012:
013:        import junit.framework.*;
014:
015:        import java.util.Iterator;
016:
017:        /**
018:         * These tests verifies an functionality of the <code>Database</code> class.
019:         */
020:        public class DatabaseTest extends TestCase {
021:
022:            Storage storage;
023:            Database database;
024:
025:            public DatabaseTest(String testName) {
026:                super (testName);
027:            }
028:
029:            public static junit.framework.Test suite() {
030:                junit.framework.TestSuite suite = new junit.framework.TestSuite(
031:                        DatabaseTest.class);
032:
033:                return suite;
034:            }
035:
036:            protected void setUp() throws java.lang.Exception {
037:                storage = StorageFactory.getInstance().createStorage();
038:                storage.open(new NullFile(), Storage.INFINITE_PAGE_POOL);
039:                database = new Database(storage);
040:            }
041:
042:            protected void tearDown() throws java.lang.Exception {
043:                if (storage.isOpened())
044:                    storage.close();
045:            }
046:
047:            /**
048:             * <B>Goal:</B> To verify the functionality of the <CODE>createTable(...)</CODE> method.
049:             * <P>
050:             * <B>Conditions:</B>
051:             * <ul>
052:             * <li><code>createTable(Stored.class)</code> is invoked twice.</li>
053:             * <li><code>Stored</code> class implements the <code>Persistent</code>
054:             * interface.</li>
055:             * </ul>
056:             * <P>
057:             * <B>Expected result:</B>
058:             * <ul>
059:             * <li>no exceptions are thrown.</li>
060:             * <li>The first invocation of <code>createTable(...)</code> returned <i>true</i> and the
061:                   second invocation returned <i>false</i>.</li>
062:             * </ul>
063:             */
064:            public void testCreateTable00() {
065:                // test target
066:                assertTrue(database.createTable(Stored.class));
067:                assertFalse(database.createTable(Stored.class));
068:            }
069:
070:            /**
071:             * <B>Goal:</B> To verify the functionality of the
072:             * <CODE>addRecord(...)</CODE> method.
073:             * <P>
074:             * <B>Conditions:</B>
075:             * <ul>
076:             * <li>the Perst is able to store the <code>persistent</code> object.</li>
077:             * <li>the <code>addRecord(null)</code>method is invoked.</li>
078:             * </ul>
079:             * <P>
080:             * <B>Expected result:</B>
081:             * <ul>
082:             * <li><code>NullPointerException</code> was thrown.</li>
083:             * </ul>
084:             */
085:            public void testAddRecord00() {
086:                assertTrue(database.createTable(Stored.class));
087:                try {
088:                    //test target
089:                    database.addRecord(null);
090:                    fail("NullPointerExceptions expected");
091:                } catch (NullPointerException e) {
092:                    // expected exception
093:                }
094:            }
095:
096:            /**
097:             * <B>Goal:</B> To verify the functionality of the
098:             * <CODE>addRecord(...)</CODE> method.
099:             * <P>
100:             * <B>Conditions:</B>
101:             * <ul>
102:             * <li>the Perst is able to store the <code>persistent</code> object.</li>
103:             * <li>the <code>addRecord(persistent)</code>method is invoked.</li>
104:             * <li><code>persistent</code> implements the <code>Persistent</code>
105:             * interface.</li>
106:             * </ul>
107:             * <P>
108:             * <B>Expected result:</B>
109:             * <ul>
110:             * <li>no exceptions are thrown.</li>
111:             * </ul>
112:             */
113:            public void testAddRecord01() {
114:                assertTrue(database.createTable(Stored.class));
115:                // test target
116:                database.addRecord(new Stored("asdf"));
117:            }
118:
119:            /**
120:             * <b>Goal:</b> To verify the functionality of the <CODE>addRecode(...)</CODE>
121:             * and <CODE>getRecords(...)</CODE> methods.
122:             * <P>
123:             * <B>Conditions:</B>
124:             * <ul>
125:             * <li>the Perst is able to store the <code>persistent</code> object.</li>
126:             * <li><code>Stored</code> class implements the <code>Persistent</code>
127:             * interface.</li>
128:             * <li><code>createTable(Stored.class)</code> is invoked.</li>
129:             * <li><code>addRecord(new Stored(...))</code> is invoked.</li>
130:             * <li><code>getRecords(Stored.class)</code> is invoked.</li>
131:             * </ul>
132:             * <B>Expected result:</B>
133:             * <ul>
134:             * <li>no exceptions are thrown.</li>
135:             * <li><code>getRecords(...)</code> returned added record.</li>
136:             * </ul>
137:             */
138:            public void testAddRecordGetRecords() {
139:                assertTrue(database.createTable(Stored.class));
140:                Stored st = new Stored("qwe");
141:                database.addRecord(st);
142:                // test target
143:                Iterator<IPersistent> i = database.getRecords(Stored.class);
144:                assertEquals(st, i.next());
145:                assertFalse(i.hasNext());
146:            }
147:
148:            /**
149:             * <b>Goal:</b> To verify the functionality of the <CODE>addRecod(...)</CODE>,
150:             * <CODE>deleteRecod(...)</CODE> and <CODE>getRecords(...)</CODE> methods.
151:             * <P>
152:             * <B>Conditions:</B>
153:             * <ul>
154:             * <li><code>createTable(Stored.class)</code> is invoked.</li>
155:             * <li><code>stored</code> object implements the <code>Persistent</code>
156:             * interface.</li>
157:             * <li><code>addRecord(stored)</code> is invoked.</li>
158:             * <li><code>deleteRecord(stored)</code> is invoked.</li>
159:             * <li><code>getRecords(Stored.class)</code> is invoked.</li>
160:             * </ul>
161:             * <P>
162:             * <B>Expected result:</B>
163:             * <ul>
164:             * <li>no exceptions are thrown.</li>
165:             * <li><code>getRecords(...)</code> returned empty set.</li>
166:             * </ul>
167:             */
168:            public void testAddRecordDeleteRecordGetRecords() {
169:                assertTrue(database.createTable(Stored.class));
170:                Stored st = new Stored("qwe");
171:                database.addRecord(st);
172:                database.deleteRecord(st);
173:                Iterator<IPersistent> i = database.getRecords(Stored.class);
174:                assertFalse(i.hasNext());
175:            }
176:
177:            /**
178:             * Internal class
179:             */
180:            private static class Stored extends Persistent {
181:                public String name;
182:
183:                Stored(String name) {
184:                    this .name = name;
185:                }
186:
187:                public Stored() {
188:                }
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.