KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > test > StartStopServerTest


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.modules.j2ee.sun.test;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.netbeans.junit.NbTestSuite;
24 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
25 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
26 import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
27
28 /**
29  *
30  * @author Michal Mocnak
31  */

32 public class StartStopServerTest extends NbTestCase {
33     
34     private final int SLEEP = 10000;
35     
36     public StartStopServerTest(String JavaDoc testName) {
37         super(testName);
38     }
39     
40     public void startServer() {
41         try {
42             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
43             
44             if(inst.isRunning())
45                 return;
46             
47             ProgressUI pui = new ProgressUI("Start Sjsas", true);
48             inst.start(pui);
49             
50             Util.sleep(SLEEP);
51             
52             if(!inst.isRunning())
53                 throw new Exception JavaDoc("Sjsas server start failed");
54             
55             if (inst.isDebuggable(null))
56                 fail("Server started in debug... it should not have done that");
57             
58             Util.sleep(SLEEP);
59         } catch(Exception JavaDoc e) {
60             fail(e.getMessage());
61         }
62     }
63     
64     public void stopServer() {
65         try {
66             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
67             
68             if(!inst.isRunning())
69                 return;
70             
71             ProgressUI pui = new ProgressUI("Stop Sjsas", true);
72             inst.stop(pui);
73             
74             Util.sleep(SLEEP);
75             
76             if(inst.isRunning())
77                 throw new Exception JavaDoc("Sjsas server stop failed");
78             
79             Util.sleep(SLEEP);
80         } catch(Exception JavaDoc e) {
81             fail(e.getMessage());
82         }
83     }
84     
85     public void restartServer() {
86         try {
87             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
88             
89             if(!inst.isRunning())
90                 return;
91             
92             ProgressUI pui = new ProgressUI("Restart Sjsas", true);
93             inst.restart(pui);
94             
95             Util.sleep(SLEEP);
96             
97             if(!inst.isRunning())
98                 throw new Exception JavaDoc("Sjsas server restart failed");
99             
100             Util.sleep(SLEEP);
101         } catch(Exception JavaDoc e) {
102             fail(e.getMessage());
103         }
104     }
105     
106     public void startDebugServer() {
107         try {
108             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
109             
110             if(inst.isRunning())
111                 return;
112             
113             ProgressUI pui = new ProgressUI("Start Debug Sjsas", true);
114             inst.startDebug(pui);
115             
116             Util.sleep(SLEEP);
117             
118             if(!inst.isRunning())
119                 throw new Exception JavaDoc("Sjsas server start debug failed");
120             
121             if (!inst.isDebuggable(null))
122                 fail("server isn't debuggable...");
123             
124             Util.sleep(SLEEP);
125         } catch(Exception JavaDoc e) {
126             fail(e.getMessage());
127         }
128     }
129     
130     public static NbTestSuite suite() {
131         NbTestSuite suite = new NbTestSuite("StartStopServerTest");
132         suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance"));
133         // detect 88916 regression
134
suite.addTest(new StartStopServerTest("startDebugServer"));
135         suite.addTest(new StartStopServerTest("restartServer"));
136         suite.addTest(new StartStopServerTest("stopServer"));
137         suite.addTest(new StartStopServerTest("startServer"));
138         suite.addTest(new StartStopServerTest("restartServer"));
139         suite.addTest(new StartStopServerTest("stopServer"));
140         // detect 88608 regression
141
suite.addTest(new StartStopServerTest("startServer"));
142         suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance"));
143         return suite;
144     }
145 }
Popular Tags