KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > db > derby > DerbyDatabaseTest


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.db.derby;
21
22
23
24
25 import java.sql.Connection JavaDoc;
26 import java.sql.Driver JavaDoc;
27 import java.util.Properties JavaDoc;
28 import junit.extensions.TestSetup;
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import org.netbeans.jellytools.JellyTestCase;
32 import org.netbeans.modules.derby.StartAction;
33 import org.netbeans.junit.NbTestSuite;
34 import org.netbeans.modules.derby.DerbyOptions;
35 import org.netbeans.modules.derby.StopAction;
36 import org.netbeans.test.db.util.DbUtil;
37 import org.openide.util.actions.SystemAction;
38
39
40
41 /*
42  * MyTestCase.java
43  *
44  * Created on February 6, 2006, 1:39 PM
45  *
46  * To change this template, choose Tools | Template Manager
47  * and open the template in the editor.
48  */

49
50 /**
51  *
52  * @author lg198683
53  */

54 public class DerbyDatabaseTest extends DbJellyTestCase {
55     
56     public static final String JavaDoc DERBY_CLASS_NAME = "org.apache.derby.jdbc.ClientDriver";
57     public static final String JavaDoc PORT="1527";
58     public static String JavaDoc location="";
59     
60     public DerbyDatabaseTest(String JavaDoc s) {
61         
62         super(s);
63         debug("derby location:"+location);
64     }
65     
66     
67     
68     public void testStartAction() {
69        debug("Starting Java DB server");
70        StartAction start=(StartAction)SystemAction.get(StartAction.class);
71        start.performAction();
72        sleep(2000);
73       
74     }
75     
76     public void testStopAction() throws Exception JavaDoc {
77         debug("Stoping Java DB server");
78
79         StopAction stop=(StopAction)SystemAction.get(StopAction.class);
80         stop.performAction();
81                 
82     }
83     
84     
85     public void testConnect() throws Exception JavaDoc{
86         debug("Connection to Java DB server");
87         DbUtil util=new DbUtil(location);
88         String JavaDoc s="jdbc:derby://localhost:1527/db;create=true";
89         Connection JavaDoc con=util.createConnection(s);
90         con.close();
91         
92    }
93         
94     
95     
96     
97     
98     public static Test suite() {
99         
100         NbTestSuite suite = new NbTestSuite();
101         suite.addTest(new DerbyDatabaseTest("testStartAction"));
102         suite.addTest(new DerbyDatabaseTest("testConnect"));
103         suite.addTest(new DerbyDatabaseTest("testStopAction"));
104         TestSetup setup=new TestSetup(suite){
105             
106             protected void setUp() throws Exception JavaDoc{
107                 init();
108             }
109             
110             protected void tearDown() throws Exception JavaDoc {
111
112             }
113         };
114      
115         return setup;
116     }
117
118     private static void init() throws Exception JavaDoc {
119         location=DerbyOptions.getDefault().getLocation();
120         String JavaDoc systemHome=System.getProperty("xtest.tmpdir");
121         //DerbyOptions.getDefault().setLocation(location);
122
DerbyOptions.getDefault().setSystemHome(systemHome);
123         
124     }
125     
126     
127
128     
129     
130    
131     
132 }
133
Popular Tags