KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > web > core > syntax > J2EECompletionTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.web.core.syntax;
21
22 import java.io.File JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import javax.swing.SwingUtilities JavaDoc;
25 import org.netbeans.test.web.FileObjectFilter;
26 import org.netbeans.test.web.RecurrentSuiteFactory;
27 import org.openide.filesystems.FileObject;
28 import junit.framework.Test;
29 import org.netbeans.api.db.explorer.ConnectionManager;
30 import org.netbeans.api.db.explorer.DatabaseConnection;
31
32 /**
33  *
34  * @author ms113234
35  */

36 public class J2EECompletionTest extends CompletionTest{
37     
38     /** Creates a new instance of CompletionTesJ2EE */
39     public J2EECompletionTest(String JavaDoc name, FileObject testFileObj) {
40         super(name, testFileObj);
41         debug = false;
42     }
43     
44     public static Test suite() {
45         // find folder with test projects and define file objects filter
46
File JavaDoc datadir = new J2EECompletionTest(null, null).getDataDir();
47         File JavaDoc projectsDir = new File JavaDoc(datadir, "J2EECompletionTestProjects");
48         FileObjectFilter filter = new FileObjectFilter() {
49             public boolean accept(FileObject fo) {
50                 String JavaDoc ext = fo.getExt();
51                 String JavaDoc name = fo.getName();
52                 return (name.startsWith("test") || name.startsWith("Test"))
53                 && (xmlExts.contains(ext) || jspExts.contains(ext) || ext.equals("java"));
54             }
55         };
56          
57         //DB Connecting - this must start with clear userdir, because it expect sample connection as the first one
58
int time=0;
59         while ((ConnectionManager.getDefault().getConnections().length==0)&&(time<=12)){
60          time++;
61          try{
62              Thread.currentThread().sleep(5000);
63          }catch(Exception JavaDoc e){
64              e.printStackTrace(System.err);
65          }
66         }
67         if (time>12) {
68             System.err.println("IMPOSSIBLE TO CONNECT THE DATABASE");
69         } else {
70             final DatabaseConnection dbconn = ConnectionManager.getDefault().getConnections()[0];
71             try {
72                 SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
73                     public void run() {
74                         ConnectionManager.getDefault().showConnectionDialog(dbconn);
75                     }
76                 });
77             } catch (InterruptedException JavaDoc e) {
78             } catch (InvocationTargetException JavaDoc e) {
79             }
80         }
81         
82         return RecurrentSuiteFactory.createSuite(J2EECompletionTest.class,
83                 projectsDir, filter);
84     }
85 }
86
Popular Tags