Source Code Cross Referenced for TestCommonDataSourceDatabase.java in  » Database-JDBC-Connection-Pool » HA-JDBC » net » sf » hajdbc » sql » 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 JDBC Connection Pool » HA JDBC » net.sf.hajdbc.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HA-JDBC: High-Availability JDBC
003:         * Copyright (c) 2004-2008 Paul Ferraro
004:         * 
005:         * This library is free software; you can redistribute it and/or modify it 
006:         * under the terms of the GNU Lesser General Public License as published by the 
007:         * Free Software Foundation; either version 2.1 of the License, or (at your 
008:         * option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful, but WITHOUT
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013:         * for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public License
016:         * along with this library; if not, write to the Free Software Foundation, 
017:         * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         * 
019:         * Contact: ferraro@users.sourceforge.net
020:         */
021:        package net.sf.hajdbc.sql;
022:
023:        import javax.management.DynamicMBean;
024:        import javax.naming.Context;
025:        import javax.naming.InitialContext;
026:        import javax.naming.NamingException;
027:        import javax.naming.Reference;
028:        import javax.naming.spi.ObjectFactory;
029:        import javax.sql.CommonDataSource;
030:
031:        import org.easymock.EasyMock;
032:        import org.testng.annotations.AfterMethod;
033:        import org.testng.annotations.DataProvider;
034:        import org.testng.annotations.Test;
035:
036:        /**
037:         * @author Paul Ferraro
038:         *
039:         */
040:        public abstract class TestCommonDataSourceDatabase<C extends CommonDataSourceDatabase<D>, D extends CommonDataSource>
041:                extends AbstractTestDatabase<C, D> implements 
042:                InactiveDataSourceDatabaseMBean {
043:            protected D dataSource;
044:
045:            protected TestCommonDataSourceDatabase(D dataSource) {
046:                this .dataSource = dataSource;
047:            }
048:
049:            protected Object[] objects() {
050:                return new Object[] { this .dataSource };
051:            }
052:
053:            protected void replay() {
054:                EasyMock.replay(this .objects());
055:            }
056:
057:            protected void verify() {
058:                EasyMock.verify(this .objects());
059:            }
060:
061:            @AfterMethod
062:            protected void reset() {
063:                EasyMock.reset(this .objects());
064:            }
065:
066:            /**
067:             * @see net.sf.hajdbc.sql.AbstractTestDatabase#createDatabase(java.lang.String)
068:             */
069:            @Override
070:            protected final C createDatabase(String id) {
071:                C database = this .createDatabase();
072:
073:                database.setId(id);
074:
075:                return database;
076:            }
077:
078:            protected abstract C createDatabase();
079:
080:            @DataProvider(name="datasource")
081:            Object[][] dataSourceProvider() {
082:                return new Object[][] { new Object[] { this .dataSource } };
083:            }
084:
085:            /**
086:             * @see net.sf.hajdbc.Database#createConnectionFactory()
087:             */
088:            @Test
089:            public final D createConnectionFactory() {
090:                C database = this .createDatabase("1");
091:                database.setName("test");
092:                database.setProperty(Context.INITIAL_CONTEXT_FACTORY,
093:                        MockInitialContextFactory.class.getName());
094:
095:                try {
096:                    Reference reference = new Reference(this .dataSource
097:                            .getClass().getName(), this .objectFactoryClass()
098:                            .getName(), null);
099:
100:                    Context context = new InitialContext(database
101:                            .getProperties());
102:
103:                    context.rebind("test", reference);
104:                } catch (NamingException e) {
105:                    assert false;
106:                }
107:
108:                D dataSource = database.createConnectionFactory();
109:
110:                assert dataSource.getClass().equals(this .mockDataSourceClass()) : dataSource
111:                        .getClass();
112:
113:                return dataSource;
114:            }
115:
116:            protected abstract Class<? extends ObjectFactory> objectFactoryClass();
117:
118:            protected abstract Class<? extends D> mockDataSourceClass();
119:
120:            /**
121:             * @see net.sf.hajdbc.Database#getActiveMBean()
122:             */
123:            @Test
124:            public final DynamicMBean getActiveMBean() {
125:                C database = this .createDatabase("1");
126:
127:                DynamicMBean mbean = database.getActiveMBean();
128:
129:                String className = mbean.getMBeanInfo().getClassName();
130:
131:                try {
132:                    assert ActiveDataSourceDatabaseMBean.class
133:                            .isAssignableFrom(Class.forName(className)) : className;
134:                } catch (ClassNotFoundException e) {
135:                    assert false : e;
136:                }
137:
138:                return mbean;
139:            }
140:
141:            /**
142:             * @see net.sf.hajdbc.Database#getInactiveMBean()
143:             */
144:            @Test
145:            public final DynamicMBean getInactiveMBean() {
146:                C database = this .createDatabase("1");
147:
148:                DynamicMBean mbean = database.getInactiveMBean();
149:
150:                String className = mbean.getMBeanInfo().getClassName();
151:
152:                try {
153:                    assert InactiveDataSourceDatabaseMBean.class
154:                            .isAssignableFrom(Class.forName(className)) : className;
155:                } catch (ClassNotFoundException e) {
156:                    assert false : e;
157:                }
158:
159:                return mbean;
160:            }
161:
162:            /**
163:             * @see net.sf.hajdbc.sql.ActiveDataSourceDatabaseMBean#getName()
164:             */
165:            @Test
166:            public final String getName() {
167:                C database = this .createDatabase("1");
168:
169:                String name = database.getName();
170:
171:                assert name == null : name;
172:
173:                database.setName("name");
174:
175:                name = database.getName();
176:
177:                assert name.equals("name") : name;
178:
179:                return name;
180:            }
181:
182:            @Test(dataProvider="string")
183:            public final void setName(String name) {
184:                C database = this .createDatabase("1");
185:
186:                database.setName(name);
187:
188:                String value = database.getName();
189:
190:                assert value.equals(name) : value;
191:
192:                database.clean();
193:
194:                database.setName(name);
195:
196:                value = database.getName();
197:
198:                assert value.equals(name) : value;
199:
200:                assert !database.isDirty();
201:
202:                database.setName(null);
203:
204:                assert database.isDirty();
205:
206:                value = database.getName();
207:
208:                assert value == null : value;
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.