KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MDBTest.java
21  *
22  * Created on May 15, 2006, 10:29 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
31 import java.io.BufferedReader JavaDoc;
32 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
33 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
34
35 import org.netbeans.junit.NbTestCase;
36 import org.netbeans.junit.NbTestSuite;
37 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
38 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
39 import org.netbeans.api.project.Project;
40 import java.io.File JavaDoc;
41 import java.io.InputStreamReader JavaDoc;
42 import org.netbeans.modules.j2ee.deployment.common.api.ValidationException;
43 import org.netbeans.spi.project.ActionProvider;
44
45
46 /**
47  *
48  * @author Amanpreet Kaur
49  */

50 public class MDBTest extends NbTestCase {
51     
52     private final int SLEEP = 10000;
53     
54     public MDBTest(String JavaDoc testName) {
55         super(testName);
56     }
57     
58     public void deployMDB() {
59         try {
60             Util.deployModule(ModuleType.EJB, Util.MDB_PROJECT_PATH, Util.MDB_PROJECT_NAME);
61         } catch(Exception JavaDoc e) {
62             fail(e.getMessage());
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 disableMDB(){
67         try{
68             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
69             String JavaDoc[] command = new String JavaDoc[]{"disable", Util.MDB_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.EJB, Util.MDB_PROJECT_NAME, si,true)!=null)
80                 throw new Exception JavaDoc("Disable of bean failed.");
81         }catch(Exception JavaDoc e){
82             fail(e.getMessage());
83         }
84         
85     }
86     /**enables the application by using asadmin command and then checks for it availability in running modules in appserver domain*/
87     public void enableMDB(){
88         try{
89             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
90             String JavaDoc[] command = new String JavaDoc[]{"enable", Util.MDB_PROJECT_NAME};
91             Process JavaDoc p=Util.runAsadmin(command);
92             Util.sleep(Util.SLEEP);
93             BufferedReader JavaDoc error = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getErrorStream()));
94             String JavaDoc errorMess = error.readLine();
95             BufferedReader JavaDoc input = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p.getInputStream()));
96             String JavaDoc output=input.readLine();
97             if(errorMess!=null)
98                 throw new Exception JavaDoc(errorMess+"\n"+output);
99             System.out.println(output);
100             if(Util.getModuleID(ModuleType.EJB, Util.MDB_PROJECT_NAME, si,true)==null)
101                 throw new Exception JavaDoc("Enable of bean failed.");
102         }catch(Exception JavaDoc e){
103             fail(e.getMessage());
104         }
105     }
106     /** undeploys the application and checks for its unavailability in running modules of appserver */
107     public void undeployMDB() {
108         try {
109             ServerInstance si = ServerRegistry.getInstance().getServerInstance(Util._URL);
110             TargetModuleID JavaDoc moduleID = Util.getModuleID(ModuleType.EJB, Util.MDB_PROJECT_NAME, si,false);
111             
112             if(moduleID == null)
113                 return;
114             
115             Util.undeployModule(ModuleType.EJB, Util.MDB_PROJECT_PATH, Util.MDB_PROJECT_NAME, moduleID);
116         } catch(Exception JavaDoc e) {
117             fail(e.getMessage());
118         }
119     }
120     /** updates the java code and then checks if jar was updated during deployment*/
121     public void updateMDB(){
122         
123         try{
124             File JavaDoc javaFile = new File JavaDoc(Util.MDB_PROJECT_PATH+Util._SEP+"src"+Util._SEP+"java"+Util._SEP+"beans"+Util._SEP+"SimpleMessageBean.java");
125             File JavaDoc jarFile = new File JavaDoc(Util.MDB_PROJECT_PATH+Util._SEP+"dist"+Util._SEP+Util.MDB_PROJECT_NAME+".jar");
126             Long JavaDoc initialDate=jarFile.lastModified();
127             javaFile.setLastModified(new java.util.Date JavaDoc().getTime());
128             deployMDB();
129             if(jarFile.lastModified()!= initialDate)
130                 System.out.println("jar updated");
131             else
132                 throw new Exception JavaDoc("jar was not updated despite java code being modified");
133         }catch(Exception JavaDoc e){
134             fail(e.getMessage());
135         }
136         
137     }
138     /**only runs the verifier, no failures reported- need more work*/
139     public void verifyMDB() {
140         try{
141             File JavaDoc f =new File JavaDoc(Util.MDB_PROJECT_PATH + Util._SEP + "verifier_results");
142             Project project = (Project)Util.openProject(new File JavaDoc(Util.MDB_PROJECT_PATH));
143             ActionProvider ap=(ActionProvider)project.getLookup().lookup(ActionProvider.class);
144             ap.invokeAction("verify", project.getLookup());
145             Util.sleep(10*Util.SLEEP);
146             Util.closeProject(Util.MDB_PROJECT_NAME);
147             Util.sleep(Util.SLEEP);
148         } catch(Exception JavaDoc e){
149             fail(e.getMessage());
150         }
151         
152         
153     }
154     public static NbTestSuite suite() {
155         NbTestSuite suite = new NbTestSuite("MDBTest");
156         // TODO : Retouche migration
157
// suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance"));
158
// suite.addTest(new StartStopServerTest("startServer"));
159
// suite.addTest(new MDBTest("deployMDB"));
160
// //suite.addTest(new MDBTest("verifyMDB"));
161
// suite.addTest(new MDBTest("updateMDB"));
162
// suite.addTest(new MDBTest("disableMDB"));
163
// suite.addTest(new MDBTest("enableMDB"));
164
// suite.addTest(new MDBTest("undeployMDB"));
165
// suite.addTest(new StartStopServerTest("stopServer"));
166
// suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance"));
167
return suite;
168     }
169     
170 }
Popular Tags