KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > test > serverplugins > generic > GenericRunTest


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.test.serverplugins.generic;
21
22 import org.netbeans.junit.NbTestCase;
23 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
24 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
25 import org.netbeans.modules.j2ee.deployment.impl.ui.ProgressUI;
26 import org.netbeans.modules.test.serverplugins.api.ConstantsProvider;
27 import org.netbeans.modules.test.serverplugins.api.ServerProvider;
28 import org.openide.util.NbBundle;
29
30 /**
31  * Generic run tests
32  *
33  * @author Michal Mocnak
34  */

35 public class GenericRunTest extends NbTestCase {
36     
37     private ConstantsProvider cProvider;
38     private ServerProvider sProvider;
39     
40     /**
41      * Creates a new instance of GenericInstanceTest
42      *
43      * @param name name of the test method which has to be performed
44      * @param cProvider instance of ConstantsProvider
45      * @param sProvider instance of ServerProvider
46      */

47     public GenericRunTest(String JavaDoc name, ConstantsProvider cProvider, ServerProvider sProvider) {
48         super(name);
49         
50         this.cProvider = cProvider;
51         this.sProvider = sProvider;
52     }
53     
54     /**
55      * Start server test
56      */

57     public void startServerTest() {
58         try {
59             // Get instance from ServerRegistry
60
ServerInstance si = ServerRegistry.getInstance().getServerInstance(cProvider.getServerURI());
61             
62             // Check if the server is running
63
if (si.isRunning())
64                 return;
65             
66             // Check if the server can be started
67
if (!si.canStartServer())
68                 return;
69             
70             // Start server
71
ProgressUI pui = new ProgressUI(NbBundle.getMessage(GenericInstanceTest.class,
72                     "MSG_Starting", cProvider.getServerURI()), false);
73             si.setServerState(ServerInstance.STATE_WAITING);
74             
75             try {
76                 pui.start();
77                 si.start(pui);
78             } finally {
79                 pui.finish();
80             }
81             
82             // Check if the server is running
83
if (!si.isRunning())
84                 throw new Exception JavaDoc(NbBundle.getMessage(GenericInstanceTest.class, "MSG_Start_Failed", cProvider.getServerURI()));
85         } catch(Exception JavaDoc e) {
86             fail(e.getMessage());
87         }
88     }
89     
90     /**
91      * Start server in debug mode test
92      */

93     public void startDebugServerTest() {
94         try {
95             // Get instance from ServerRegistry
96
ServerInstance si = ServerRegistry.getInstance().getServerInstance(cProvider.getServerURI());
97             
98             // Check if the server is running
99
if (si.isRunning())
100                 return;
101             
102             // Check if the server can be started
103
if (!si.canStartServer() || !si.isDebugSupported())
104                 return;
105             
106             // Start server
107
ProgressUI pui = new ProgressUI(NbBundle.getMessage(GenericInstanceTest.class,
108                     "MSG_Starting_Debug", cProvider.getServerURI()), false);
109             si.setServerState(ServerInstance.STATE_WAITING);
110             
111             try {
112                 pui.start();
113                 si.startDebug(pui);
114             } finally {
115                 pui.finish();
116             }
117             
118             // Check if the server is running
119
if (!si.isRunning())
120                 throw new Exception JavaDoc(NbBundle.getMessage(GenericInstanceTest.class, "MSG_Start_Debug_Failed", cProvider.getServerURI()));
121         } catch(Exception JavaDoc e) {
122             fail(e.getMessage());
123         }
124     }
125     
126     /**
127      * Stop server test
128      */

129     public void stopServerTest() {
130         try {
131             // Get instance from ServerRegistry
132
ServerInstance si = ServerRegistry.getInstance().getServerInstance(cProvider.getServerURI());
133             
134             // Check if the server is running
135
if (!si.isRunning())
136                 return;
137             
138             // Start server
139
ProgressUI pui = new ProgressUI(NbBundle.getMessage(GenericInstanceTest.class,
140                     "MSG_Stopping", cProvider.getServerURI()), false);
141             si.setServerState(ServerInstance.STATE_WAITING);
142             
143             try {
144                 pui.start();
145                 si.stop(pui);
146             } finally {
147                 pui.finish();
148             }
149             
150             // Check if the server is running
151
if (si.isRunning())
152                 throw new Exception JavaDoc(NbBundle.getMessage(GenericInstanceTest.class,
153                         "MSG_Stop_Failed", cProvider.getServerURI()));
154         } catch(Exception JavaDoc e) {
155             fail(e.getMessage());
156         }
157     }
158 }
Popular Tags