KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > WSValidation


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.test.j2ee;
21
22 import java.io.*;
23 import junit.textui.TestRunner;
24 import org.netbeans.jellytools.Bundle;
25 import org.netbeans.jellytools.EditorOperator;
26 import org.netbeans.jellytools.EditorWindowOperator;
27 import org.netbeans.jellytools.JellyTestCase;
28 import org.netbeans.jellytools.MainWindowOperator;
29 import org.netbeans.jellytools.NbDialogOperator;
30 import org.netbeans.jellytools.NewFileWizardOperator;
31 import org.netbeans.jellytools.ProjectsTabOperator;
32 import org.netbeans.jellytools.RuntimeTabOperator;
33 import org.netbeans.jellytools.actions.ActionNoBlock;
34 import org.netbeans.jellytools.actions.DeleteAction;
35 import org.netbeans.jellytools.actions.NewFileAction;
36 import org.netbeans.jellytools.actions.OpenAction;
37 import org.netbeans.jellytools.nodes.Node;
38 import org.netbeans.jemmy.operators.JButtonOperator;
39 import org.netbeans.jemmy.operators.JComboBoxOperator;
40 import org.netbeans.jemmy.operators.JDialogOperator;
41 import org.netbeans.jemmy.operators.JRadioButtonOperator;
42 import org.netbeans.jemmy.operators.JTableOperator;
43 import org.netbeans.jemmy.operators.JTextFieldOperator;
44 import org.netbeans.jemmy.operators.JTreeOperator;
45 import org.netbeans.jemmy.TimeoutExpiredException;
46 import org.netbeans.junit.NbTestSuite;
47 import org.netbeans.junit.ide.ProjectSupport;
48 import org.netbeans.test.j2ee.addmethod.AddOperationTest;
49 import org.netbeans.test.j2ee.addmethod.CallEJBTest;
50 import org.netbeans.test.j2ee.lib.ProgressSupport;
51 import org.netbeans.test.j2ee.lib.Utils;
52
53 /**
54  * WSValidation suite for J2EE.
55  *
56  *
57  * @author libor.martinek@sun.com
58  */

59 public class WSValidation extends JellyTestCase {
60     
61     public static final String JavaDoc EAR_SAMPLE_PROJECT_NAME = "SampleApp";
62     public static final String JavaDoc WEB_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-WebModule";
63     public static final String JavaDoc EJB_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-EJBModule";
64     public static final String JavaDoc WSC_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-WSClient";
65     
66     public static final String JavaDoc EAR_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME;
67     public static final String JavaDoc EJB_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + EAR_SAMPLE_PROJECT_NAME + "-ejb";
68     public static final String JavaDoc WEB_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + EAR_SAMPLE_PROJECT_NAME + "-war";
69     public static final String JavaDoc WSC_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + WSC_SAMPLE_PROJECT_NAME;
70     
71     /** Need to be defined because of JUnit */
72     public WSValidation(String JavaDoc name) {
73         super(name);
74     }
75     
76     public static NbTestSuite suite() {
77         NbTestSuite suite = new NbTestSuite();
78      
79         suite.addTest(new WSValidation("openProjects"));
80         suite.addTest(new EJBValidation("testStartServer"));
81
82         suite.addTest(new AddOperationTest("testAddOperation1"));
83         suite.addTest(new AddOperationTest("testAddOperation2"));
84         suite.addTest(new CallEJBTest("testCallEJBInWS"));
85         suite.addTest(new WSValidation("testDeploymentWS"));
86         //suite.addTest(new WSValidation("testRegisterWS"));
87
//suite.addTest(new WSValidation("testTestOperation"));
88

89         suite.addTest(new WSValidation("testCreateWSClient"));
90         suite.addTest(new WSValidation("testCallWS"));
91         suite.addTest(new WSValidation("testRunWSClient"));
92         suite.addTest(new WSValidation("testUndeployWSClient"));
93                
94         suite.addTest(new WSValidation("testUndeployWS"));
95         
96         suite.addTest(new WSValidation("testDeleteWSinWeb"));
97         
98         //suite.addTest(new GUIValidation("testNewWebServiceFromWSDL"));
99
suite.addTest(new EJBValidation("testStopServer"));
100         suite.addTest(new WSValidation("closeProjects"));
101         return suite;
102     }
103     
104     /** Use for execution inside IDE */
105     public static void main(java.lang.String JavaDoc[] args) {
106         // run whole suite
107
TestRunner.run(suite());
108     }
109         
110     public void openProjects() {
111         ProjectSupport.openProject(EAR_SAMPLE_PROJECT_PATH);
112         ProjectSupport.waitScanFinished();
113         ProjectSupport.openProject(EJB_SAMPLE_PROJECT_PATH);
114         ProjectSupport.waitScanFinished();
115         ProjectSupport.openProject(WEB_SAMPLE_PROJECT_PATH);
116         ProjectSupport.waitScanFinished();
117         ProjectSupport.openProject(WSC_SAMPLE_PROJECT_PATH);
118         ProjectSupport.waitScanFinished();
119         
120         //TEMPORARY HACK
121
try { new NbDialogOperator("Open Project").ok(); }
122         catch (TimeoutExpiredException e) {}
123         
124         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
125     }
126     
127     public void closeProjects() {
128         ProjectSupport.closeProject(EAR_SAMPLE_PROJECT_NAME);
129         ProjectSupport.closeProject(EJB_SAMPLE_PROJECT_NAME);
130         ProjectSupport.closeProject(WEB_SAMPLE_PROJECT_NAME);
131         ProjectSupport.closeProject(WSC_SAMPLE_PROJECT_NAME);
132     }
133     public void testDeploymentWS() throws IOException {
134         String JavaDoc CONTROL_TEXT = "name=\"SampleWebService\"";
135         String JavaDoc page = Utils.deploy(EAR_SAMPLE_PROJECT_NAME, "http://localhost:8080/SampleApp-WebModule/SampleWebService?WSDL");
136         log(page);
137         assertTrue("WSDL doesn't contain expected text '"+CONTROL_TEXT+"'. See log for content.", page.indexOf(CONTROL_TEXT)>=0);
138     }
139
140     public void testUndeployWS() {
141         Utils.undeploy(EAR_SAMPLE_PROJECT_NAME);
142     }
143     
144     public void testDeleteWSinWeb() throws IOException {
145         Node node = new Node(new ProjectsTabOperator().getProjectRootNode(WEB_SAMPLE_PROJECT_NAME),
146                                  "Web Services|SampleWebService");
147         new DeleteAction().performAPI(node);
148         NbDialogOperator dialog = new NbDialogOperator("Confirm Web Service Deletion");
149         dialog.yes();
150         
151         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
152         Utils utils = new Utils(this);
153         String JavaDoc ddNames[] = { "web.xml",
154                              "sun-web.xml" };
155         utils.assertFiles(new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF"), ddNames, getName()+"_");
156
157         File dir = new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "sample");
158         String JavaDoc deletedFiles[] = dir.list(new FilenameFilter () {
159             public boolean accept(File dir, String JavaDoc name) {
160                 return name.startsWith("SampleWebService");
161             }
162         });
163         File file = new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF" + File.separator + "webservices.xml");
164         if (file.exists())
165             fail("File "+file.getAbsolutePath()+" was not deleted.");
166         // NOT YET IMPLEMENTED IN IDE
167
/*
168         if (deletedFiles != null && deletedFiles.length > 0) {
169             fail("Web Service files was not deleted from directory "+dir.getAbsolutePath()+". I found "+Arrays.asList(deletedFiles));
170         }
171          */

172     }
173     
174     public void testRegisterWS() {
175         Node node = new Node(new ProjectsTabOperator().getProjectRootNode(WEB_SAMPLE_PROJECT_NAME),
176                                  "Web Services|SampleWebService");
177         node.performPopupActionNoBlock(Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.webservices.action.Bundle", "LBL_WSRegisterAction"));
178         new NbDialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.webservices.ui.Bundle", "Enter_WSDL_Url")).ok();
179         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 120000);
180         MainWindowOperator.getDefault().waitStatusText("Successfully compiled web service client code.");
181         new Node(new RuntimeTabOperator().getRootNode(), "Web Services|SampleWebService|SampleWebServiceSEIPort|operation1");
182     }
183     
184     public void testTestOperation() {
185         String JavaDoc popup = "Test Operation";
186         new Node(new RuntimeTabOperator().getRootNode(), "Web Services|SampleWebService|SampleWebServiceSEIPort|operation1").performPopupAction(popup);
187         NbDialogOperator dialog = new NbDialogOperator("Test Web Service Operation");
188         new JButtonOperator(dialog, "Submit").push();
189         JTableOperator table = new JTableOperator(dialog,1);
190         table.waitCell("sampleValue",0,1);
191         dialog.close();
192     }
193     
194     public void testCreateWSClient() {
195         new NewFileAction().performMenu();
196         NewFileWizardOperator wizard = new NewFileWizardOperator();
197         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
198         wizard.selectProject(WSC_SAMPLE_PROJECT_NAME);
199         wizard.selectCategory("Web Services");
200         wizard.selectFileType("Web Service Client");
201         wizard.next();
202         new JTextFieldOperator(wizard, 0).setText("http://localhost:8080/SampleApp-WebModule/SampleWebService?WSDL");
203         new JComboBoxOperator(wizard,0).clearText();
204         new JComboBoxOperator(wizard,0).typeText("test");
205         new JButtonOperator(wizard, "Retrieve WSDL").push();
206         wizard.finish();
207         ProgressSupport.waitFinished("Creating webservice client", 30000);
208     }
209     
210     public void testCallWS() {
211         Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(WSC_SAMPLE_PROJECT_NAME),
212                                  "Source Packages|servlet|TestServlet.java");
213         new OpenAction().performAPI(openFile);
214         EditorOperator editor = new EditorWindowOperator().getEditor("TestServlet.java");
215         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
216         editor.select(35);
217         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
218         new ActionNoBlock(null,"Web Service Client Resources|Call Web Service Operation").perform(editor);
219         NbDialogOperator dialog = new NbDialogOperator("Select Operation to Invoke");
220         new Node(new JTreeOperator(dialog),"SampleWebService|SampleWebServiceSEIPort|operation1").select();
221         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
222         dialog.ok();
223         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
224         new Utils(this).checkAndModify("TestServlet.java", 37, "getSampleWebServiceSEIPort().operation1(/* TODO enter operation arguments */);",
225                                        0, null, 37, true, "out.println(getSampleWebServiceSEIPort().operation1());");
226     }
227     
228     public void testRunWSClient() throws IOException {
229         String JavaDoc CONTROL_TEXT = "sampleValue";
230         String JavaDoc page = Utils.deploy(WSC_SAMPLE_PROJECT_NAME, "http://localhost:8080/SampleApp-WSClient/TestServlet", true);
231         log(page);
232         assertTrue("TestServlet doesn't contain expected text '"+CONTROL_TEXT+"'. See log for content.", page.indexOf(CONTROL_TEXT)>=0);
233     }
234     
235     public void testUndeployWSClient() {
236         Utils.undeploy(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_WebModules"), WSC_SAMPLE_PROJECT_NAME);
237     }
238     
239     public void testNewWebServiceFromWSDL() {
240         String JavaDoc dataDir = System.getProperty("xtest.data");
241         String JavaDoc wsdlFile = dataDir + File.separator + "QuotesService.wsdl";
242         File file = new File(wsdlFile);
243         if (!file.exists())
244             throw new RuntimeException JavaDoc("WSDL file not found:"+file.getAbsolutePath());
245         new NewFileAction().performMenu();
246         NewFileWizardOperator wizard = new NewFileWizardOperator();
247         new org.netbeans.jemmy.EventTool().waitNoEvent(2000);
248         wizard.selectProject(EAR_SAMPLE_PROJECT_NAME+"-war");
249         wizard.selectCategory("Web Services");
250         wizard.selectFileType("Web Service");
251         wizard.next();
252         new JTextFieldOperator(wizard, 0).setText("QuotesWebService");
253         new JTextFieldOperator(wizard,2).typeText("quotes");
254         new JRadioButtonOperator(wizard,"From Local WSDL File").push();
255         new JTextFieldOperator(wizard,3).setText(file.getAbsolutePath());
256         wizard.finish();
257         JDialogOperator status = new JDialogOperator("Progress");
258         status.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
259         status.waitClosed();
260     }
261             
262 }
263
Popular Tags