KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DukeStatefulTest.java
21  *
22  * Created on June 8, 2006, 11:00 AM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.j2ee.sun.test;
29
30 import java.io.BufferedReader JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FileOutputStream JavaDoc;
33 import java.io.InputStreamReader JavaDoc;
34 import java.io.OutputStream JavaDoc;
35 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
36 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
37 import org.netbeans.api.project.Project;
38 import org.netbeans.junit.NbTestCase;
39 import org.netbeans.junit.NbTestSuite;
40 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
41 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
42 import org.netbeans.spi.project.ActionProvider;
43
44 /**
45  *
46  * @author Amanpreet Kaur
47  */

48 public class DukeStatefulTest extends NbTestCase{
49     
50     /** Creates a new instance of DukeStatefulTest */
51     private final int SLEEP = 10000;
52     
53     public DukeStatefulTest(String JavaDoc testName) {
54         super(testName);
55     }
56     /** calls the deploy api for the duke-stateful project*/
57     public void deployApplication() {
58         try {
59             Util.deployModule(ModuleType.EAR,Util.STATEFUL_PROJECT_PATH, Util.STATEFUL_PROJECT_NAME );
60         } catch(Exception JavaDoc e) {
61             fail(e.getMessage());
62         }
63     }
64     
65     /**disables the application by using asadmin command and then checks for it availability in running modules in appserver domain*/
66     public void disableApplication(){
67         try{
68             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
69             String JavaDoc[] command = new String JavaDoc[]{"disable", Util.STATEFUL_PROJECT_NAME};
70             Process JavaDoc p=Util.runAsadmin(command);
71             Util.sleep(Util.SLEEP);
72             BufferedReader JavaDoc error = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getErrorStream()));
73             String JavaDoc errorMess = error.readLine();
74             BufferedReader JavaDoc input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getInputStream()));
75             String JavaDoc output=input.readLine();
76             if(errorMess!=null)
77                 throw new Exception JavaDoc(errorMess+"\n"+output);
78             System.out.println(output);
79             if (Util.getModuleID(ModuleType.EAR, Util.STATEFUL_PROJECT_NAME, si,true)!=null)
80                 throw new Exception JavaDoc("Disable of application failed.");
81         }catch(Exception JavaDoc e){
82             fail(e.getMessage());
83         }
84     }
85     /**enables the application by using asadmin command and then checks for it availability in running modules in appserver domain*/
86     public void enableApplication(){
87         try{
88             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
89             String JavaDoc[] command = new String JavaDoc[]{"enable", Util.STATEFUL_PROJECT_NAME};
90             Process JavaDoc p=Util.runAsadmin(command);
91             Util.sleep(Util.SLEEP);
92             BufferedReader JavaDoc error = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getErrorStream()));
93             String JavaDoc errorMess = error.readLine();
94             BufferedReader JavaDoc input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getInputStream()));
95             String JavaDoc output=input.readLine();
96             if(errorMess!=null)
97                 throw new Exception JavaDoc(errorMess+"\n"+output);
98             System.out.println(output);
99         }catch(Exception JavaDoc e){
100             fail(e.getMessage());
101         }
102     }
103     /** undeploys the application and checks for its unavailability in running modules of appserver */
104     public void undeployApplication() {
105         try {
106             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
107             TargetModuleID JavaDoc moduleID = Util.getModuleID(ModuleType.EAR, Util.CUSTOMER_APPLICATION_PROJECT_NAME, si,false);
108             if(moduleID == null)
109                 return;
110             Util.undeployModule(ModuleType.EAR, Util.STATEFUL_PROJECT_PATH, Util.STATEFUL_PROJECT_NAME, moduleID);
111         } catch(Exception JavaDoc e) {
112             fail(e.getMessage());
113         }
114     }
115     /**only runs the verifier, no failures reported- need more work*/
116     public void verifyApplication() {
117         try{
118             File JavaDoc f =new File JavaDoc(Util.STATEFUL_PROJECT_PATH + Util._SEP + "verifier_results");
119             Project project = (Project)Util.openProject(new File JavaDoc(Util.STATEFUL_PROJECT_PATH));
120             ActionProvider ap =(ActionProvider)project.getLookup().lookup(ActionProvider.class);
121             OutputStream JavaDoc logger=(OutputStream JavaDoc)new FileOutputStream JavaDoc(f);
122            ap.invokeAction("verify", project.getLookup());
123             Util.sleep(10*Util.SLEEP);
124             Util.closeProject(Util.STATEFUL_PROJECT_NAME);
125             Util.sleep(Util.SLEEP);
126             
127         } catch(Exception JavaDoc e){
128             fail(e.getMessage());
129         }
130         
131         
132     }
133     
134     /*runs the application client and checks for correct output*/
135     public void runClient(){
136         try{
137             String JavaDoc[] getClientStubs = new String JavaDoc[]{"get-client-stubs", "--user", "admin","--appname", Util.STATEFUL_PROJECT_NAME, "." };
138             Util.runAsadmin(getClientStubs);
139             Util.sleep(Util.SLEEP);
140             Process JavaDoc p = Runtime.getRuntime().exec(Util._PLATFORM_LOCATION+Util._SEP+"bin"+Util._SEP+"appclient -client "+Util.STATEFUL_PROJECT_NAME+"Client.jar");
141             BufferedReader JavaDoc error = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getErrorStream()));
142             String JavaDoc errorMess = error.readLine();
143             BufferedReader JavaDoc input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getInputStream()));
144             String JavaDoc output=input.readLine();
145             if(errorMess!=null)
146                 throw new Exception JavaDoc(errorMess+"\n"+output);
147             if (!output.equals("duke"))
148                 throw new Exception JavaDoc("The client of application giving wrong results");
149         }catch(Exception JavaDoc e){
150             fail(e.getMessage());
151         }
152     }
153     public static NbTestSuite suite() {
154         NbTestSuite suite = new NbTestSuite("DukeStatefulTest");
155         // TODO : Retouche migration
156
// suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance"));
157
// suite.addTest(new StartStopServerTest("startServer"));
158
// suite.addTest(new DukeStatefulTest("deployApplication"));
159
// suite.addTest(new DukeStatefulTest("runClient"));
160
// //suite.addTest(new DukeStatefulTest("verifyApplication"));
161
// suite.addTest(new DukeStatefulTest("disableApplication"));
162
// suite.addTest(new DukeStatefulTest("enableApplication"));
163
// suite.addTest(new StartStopServerTest("restartServer"));
164
// suite.addTest(new DukeStatefulTest("runClient"));
165
// suite.addTest(new DukeStatefulTest("undeployApplication"));
166
// suite.addTest(new StartStopServerTest("stopServer"));
167
// suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance"));
168
return suite;
169     }
170 }
171
172
Popular Tags