Source Code Cross Referenced for DatabaseTests.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » test » dataprovider » common » 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 » IDE Netbeans » visualweb.api.designer » org.netbeans.test.dataprovider.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:
004:        Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:
006:
007:        The contents of this file are subject to the terms of either the GNU
008:        General Public License Version 2 only ("GPL") or the Common
009:        Development and Distribution License("CDDL") (collectively, the
010:        "License"). You may not use this file except in compliance with the
011:        License. You can obtain a copy of the License at
012:        http://www.netbeans.org/cddl-gplv2.html
013:        or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
014:        specific language governing permissions and limitations under the
015:        License.  When distributing the software, include this License Header
016:        Notice in each file and include the License file at
017:        nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
018:        particular file as subject to the "Classpath" exception as provided
019:        by Sun in the GPL Version 2 section of the License file that
020:        accompanied this code. If applicable, add the following below the
021:        License Header, with the fields enclosed by brackets [] replaced by
022:        your own identifying information:
023:        "Portions Copyrighted [year] [name of copyright owner]"
024:
025:        Contributor(s):
026:
027:        The Original Software is NetBeans. The Initial Developer of the Original
028:        Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
029:        Microsystems, Inc. All Rights Reserved.
030:
031:        If you wish your version of this file to be governed by only the CDDL
032:        or only the GPL Version 2, indicate your decision by adding
033:        "[Contributor] elects to include this software in this distribution
034:        under the [CDDL or GPL Version 2] license." If you do not indicate a
035:        single choice of license, a recipient has the option to distribute
036:        your version of this file under either the CDDL, the GPL Version 2 or
037:        to extend the choice of license to its licensees as provided above.
038:        However, if you add GPL Version 2 code and therefore, elected the GPL
039:        Version 2 license, then the option applies only if the new code is
040:        made subject to such option by the copyright holder.
041:         */
042:        package org.netbeans.test.dataprovider.common;
043:
044:        import java.awt.event.*;
045:        import java.util.*;
046:        import java.awt.event.*;
047:        import java.awt.*;
048:        import javax.swing.*;
049:        import javax.swing.tree.*;
050:        import org.netbeans.jemmy.*;
051:        import org.netbeans.jemmy.operators.*;
052:        import org.netbeans.jellytools.actions.*;
053:        import org.netbeans.modules.visualweb.gravy.*;
054:        import org.netbeans.modules.visualweb.gravy.plugins.*;
055:        import org.netbeans.modules.visualweb.gravy.designer.*;
056:        import org.netbeans.modules.visualweb.gravy.dataconnectivity.*;
057:        import org.netbeans.modules.visualweb.gravy.model.deployment.*;
058:
059:        public class DatabaseTests implements  Constants {
060:            public String checkDBConnection() {
061:                String errMsg = null, dbURL = TestPropertiesHandler
062:                        .getDatabaseProperty("DB_URL");
063:
064:                Utils.putFocusOnWindowServices();
065:                Util.wait(1000);
066:                new QueueTool().waitEmpty();
067:
068:                TreePath dbTreePath = Utils.findServicesTreeNode(
069:                        SERVICES_TREE_NODE_DATABASES, true);
070:                Util.wait(1000);
071:                new QueueTool().waitEmpty();
072:
073:                JTreeOperator treeOp = new ServerNavigatorOperator().getTree();
074:                treeOp.expandPath(dbTreePath);
075:                Util.wait(1000);
076:                new QueueTool().waitEmpty();
077:
078:                dbTreePath = Utils.findDBConnectionTreeNode();
079:                if (dbTreePath == null) {
080:                    addNewDBDriver();
081:                    addNewDBConnection();
082:                    dbTreePath = Utils.findDBConnectionTreeNode();
083:                    if (dbTreePath == null)
084:                        return "The tree subnode [" + dbURL
085:                                + "] isn't found under the tree node ["
086:                                + SERVICES_TREE_NODE_DATABASES + "]";
087:                }
088:                treeOp = new ServerNavigatorOperator().getTree();
089:                //JPopupMenuOperator popupMenuOp = new JPopupMenuOperator(treeOp.callPopupOnPath(dbTreePath));
090:                JPopupMenuOperator popupMenuOp = Utils.callPopupOnPath(treeOp,
091:                        dbTreePath);
092:                JMenuItem menuItem = TestUtils.findPopupMenuItemByLabel(
093:                        popupMenuOp, DB_POPUP_MENU_ITEM_LABEL_CONNECT, false,
094:                        false);
095:                if (menuItem.isEnabled()) { // no DB connection
096:                    new JMenuItemOperator(menuItem).pushNoBlock();
097:                    Util.wait(500);
098:                    new QueueTool().waitEmpty();
099:                    connectToDB();
100:                } else { // required DB is already connected
101:                    popupMenuOp.pressKey(KeyEvent.VK_ESCAPE);
102:                }
103:                Util.wait(500);
104:                new QueueTool().waitEmpty();
105:                if (errMsg == null) {
106:                    Utils
107:                            .logMsg("+++ DB connection to [" + dbURL
108:                                    + "] is done");
109:                }
110:                return errMsg;
111:            }
112:
113:            private void connectToDB() {
114:                JDialogOperator dialogOp = new JDialogOperator(
115:                        DB_DIALOG_CONNECT_TITLE);
116:
117:                // for DB Derby: now the dialog "Connect" doesn't contain any
118:                // text fields and user name and password are not required
119:                if (Utils.isUsedDBDerby()) {
120:                    dialogOp.waitClosed();
121:                    Util.wait(500);
122:                    new QueueTool().waitEmpty();
123:                    return;
124:                }
125:
126:                new JTextFieldOperator(dialogOp, 0)
127:                        .setText(TestPropertiesHandler
128:                                .getDatabaseProperty("DB_Password"));
129:                new JTextFieldOperator(dialogOp, 1)
130:                        .setText(TestPropertiesHandler
131:                                .getDatabaseProperty("DB_User"));
132:                Util.wait(500);
133:                new JButtonOperator(dialogOp, BUTTON_LABEL_OK).pushNoBlock();
134:                Util.wait(500);
135:                new QueueTool().waitEmpty();
136:            }
137:
138:            private void addNewDBDriver() {
139:                String jdbcDriverName = getJDBCDriverName();
140:                TreePath driverPath = Utils.findServicesTreeNode(
141:                        SERVICES_TREE_NODE_DATABASES + "|"
142:                                + DB_TREE_NODE_DRIVERS + "|" + jdbcDriverName,
143:                        false);
144:                if (driverPath == null) {
145:                    if (Utils.isUsedDBDerby()) {
146:                        defineDBDerbySettings();
147:                        return;
148:                    }
149:
150:                    Utils.callPopupMenuOnServicesTreeNode(
151:                            SERVICES_TREE_NODE_DATABASES + "|"
152:                                    + DB_TREE_NODE_DRIVERS,
153:                            DB_POPUP_MENU_ITEM_LABEL_NEW_DRIVER);
154:
155:                    JDialogOperator dialogOp = new JDialogOperator(
156:                            DB_DIALOG_NEW_DRIVER_TITLE);
157:
158:                    new JTextFieldOperator(dialogOp, 1).setText(jdbcDriverName);
159:                    Util.wait(500);
160:
161:                    new JButtonOperator(dialogOp, BUTTON_LABEL_ADD)
162:                            .pushNoBlock();
163:                    Util.wait(500);
164:
165:                    JFileChooserOperator fileChooserOp = new JFileChooserOperator();
166:                    String jdbcDriverPath = TestPropertiesHandler
167:                            .getDatabaseProperty("JDBC_Driver_AbsPath")
168:                            + "/"
169:                            + TestPropertiesHandler
170:                                    .getDatabaseProperty("JDBC_Driver_File");
171:                    new JTextFieldOperator(fileChooserOp, 0)
172:                            .setText(jdbcDriverPath);
173:                    Util.wait(500);
174:                    new JButtonOperator(fileChooserOp, BUTTON_LABEL_OPEN)
175:                            .pushNoBlock();
176:                    Util.wait(1000);
177:
178:                    new JButtonOperator(dialogOp, BUTTON_LABEL_OK)
179:                            .pushNoBlock();
180:                    Util.wait(500);
181:                    new QueueTool().waitEmpty();
182:
183:                    Utils.logMsg("+++ New JDBC driver [" + jdbcDriverName
184:                            + "] has been added");
185:                } else {
186:                    Utils.logMsg("+++ JDBC driver [" + jdbcDriverName
187:                            + "] exists alredy");
188:                }
189:            }
190:
191:            private void defineDBDerbySettings() {
192:                Util.getMainMenu().pushMenuNoBlock(
193:                        MAIN_MENU_ITEM_TOOLS_JAVA_DB_DATABASE_SETTINGS);
194:                Util.wait(1000);
195:                new QueueTool().waitEmpty();
196:
197:                JDialogOperator dialogOp = new JDialogOperator(
198:                        DB_DIALOG_JAV_DB_SETTINGS_TITLE);
199:
200:                String dbInstallation = TestPropertiesHandler
201:                        .getDatabaseProperty("DB_Installation");
202:                new JTextFieldOperator(dialogOp, 1).setText(dbInstallation);
203:                Util.wait(500);
204:
205:                String dbLocation = TestPropertiesHandler
206:                        .getDatabaseProperty("DB_Location");
207:                new JTextFieldOperator(dialogOp, 0).setText(dbLocation);
208:                Util.wait(500);
209:
210:                new JButtonOperator(dialogOp, BUTTON_LABEL_OK).pushNoBlock();
211:                Util.wait(500);
212:
213:                Utils.logMsg("+++ Java DB Settings are defined properly.");
214:            }
215:
216:            private String getJDBCDriverName() {
217:                String dbType = TestPropertiesHandler
218:                        .getDatabaseProperty("Database"), jdbcDriverName = null;
219:                if (dbType.toLowerCase().contains("oracle")) {
220:                    jdbcDriverName = DB_TREE_NODE_ORACLE_JDBC_DRIVER_NAME;
221:                } else if (dbType.toLowerCase().contains("derby")) {
222:                    jdbcDriverName = DB_TREE_NODE_DERBY_JDBC_DRIVER_NAME;
223:                } else {
224:                    jdbcDriverName = "Unknown JDBC Driver";
225:                }
226:                return jdbcDriverName;
227:            }
228:
229:            private void addNewDBConnection() {
230:                TreePath dbTreePath = Utils.findDBConnectionTreeNode();
231:                if (dbTreePath != null)
232:                    return;
233:
234:                String jdbcDriverName = getJDBCDriverName();
235:                Utils.callPopupMenuOnServicesTreeNode(
236:                        SERVICES_TREE_NODE_DATABASES,
237:                        DB_POPUP_MENU_ITEM_LABEL_NEW_CONNECTION);
238:                JDialogOperator dialogOp = new JDialogOperator(
239:                        DB_DIALOG_NEW_CONNECTION_TITLE);
240:
241:                JComboBoxOperator driverComboBoxOp = new JComboBoxOperator(
242:                        dialogOp);
243:                driverComboBoxOp.selectItem(jdbcDriverName);
244:                /* - workaround if the previous line has no effect      
245:                int itemIndex = -1, itemCount = driverComboBoxOp.getItemCount();        
246:                for (int i = 0; i < itemCount; ++i) {
247:                    String itemText = driverComboBoxOp.getItemAt(i).toString();
248:                    if (itemText.contains(jdbcDriverName)) {
249:                        itemIndex = i;
250:                        //Utils.logMsg("itemIndex = " + itemIndex);
251:                        break;
252:                    }
253:                }
254:                driverComboBoxOp.setSelectedIndex(itemIndex);
255:                 */
256:
257:                Util.wait(500);
258:
259:                String dbURL = TestPropertiesHandler
260:                        .getDatabaseProperty("DB_URL"), dbUser = TestPropertiesHandler
261:                        .getDatabaseProperty("DB_User"), dbPassword = TestPropertiesHandler
262:                        .getDatabaseProperty("DB_Password");
263:
264:                new JTextFieldOperator(dialogOp, 1).setText(dbURL);
265:                Util.wait(500);
266:
267:                new JTextFieldOperator(dialogOp, 2).setText(dbUser);
268:                Util.wait(500);
269:
270:                new JTextFieldOperator(dialogOp, 3).setText(dbPassword);
271:                Util.wait(500);
272:
273:                new JButtonOperator(dialogOp, BUTTON_LABEL_OK).pushNoBlock();
274:                Util.wait(500);
275:                new QueueTool().waitEmpty();
276:
277:                // wait until DB is connected and dialog is closed
278:                waitDialogClosed(dialogOp);
279:            }
280:
281:            private void waitDialogClosed(JDialogOperator dialogOp) {
282:                ((JDialog) dialogOp.getSource())
283:                        .addWindowListener(new WindowAdapter() {
284:                            @Override
285:                            public void windowClosed(WindowEvent e) {
286:                                synchronized (DatabaseTests.this ) {
287:                                    DatabaseTests.this .notifyAll();
288:                                }
289:                            }
290:                        });
291:                synchronized (this ) {
292:                    try {
293:                        wait(60000);
294:                    } catch (InterruptedException e) {
295:                        e.printStackTrace(Utils.logStream);
296:                    }
297:                }
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.