KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CustomerCmpSampleTest.java
21  *
22  * Created on June 5, 2006, 12:14 PM
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.InputStreamReader JavaDoc;
33 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
34 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.junit.NbTestCase;
37 import org.netbeans.junit.NbTestSuite;
38 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
39 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
40 import org.netbeans.spi.project.ActionProvider;
41
42 /**
43  *
44  * @author Amanpreet Kaur
45  */

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