websvc.restkit/test/qa-functional/src/org/netbeans/modules/ws/qaf/rest/RestCStubsTest.java
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL
25 * or only the GPL Version 2, indicate your decision by adding
26 * "[Contributor] elects to include this software in this distribution
27 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28 * single choice of license, a recipient has the option to distribute
29 * your version of this file under either the CDDL, the GPL Version 2 or
30 * to extend the choice of license to its licensees as provided above.
31 * However, if you add GPL Version 2 code and therefore, elected the GPL
32 * Version 2 license, then the option applies only if the new code is
33 * made subject to such option by the copyright holder.
37 * Portions Copyrighted 2007 Sun Microsystems, Inc.
39 package org.netbeans.modules.ws.qaf.rest;
42 import java.io.IOException;
43 import javax.swing.JButton;
44 import javax.swing.ListModel;
45 import junit.framework.Test;
46 import org.netbeans.api.project.Project;
47 import org.netbeans.api.project.ProjectManager;
48 import org.netbeans.jellytools.Bundle;
49 import org.netbeans.jellytools.NbDialogOperator;
50 import org.netbeans.jellytools.ProjectsTabOperator;
51 import org.netbeans.jellytools.WizardOperator;
52 import org.netbeans.jellytools.nodes.ProjectRootNode;
53 import org.netbeans.jemmy.operators.JButtonOperator;
54 import org.netbeans.jemmy.operators.JCheckBoxOperator;
55 import org.netbeans.jemmy.operators.JListOperator;
56 import org.netbeans.jemmy.operators.JRadioButtonOperator;
57 import org.netbeans.jemmy.operators.JTextFieldOperator;
58 import org.netbeans.jemmy.operators.JTreeOperator;
59 import org.netbeans.junit.NbModuleSuite;
60 import org.netbeans.modules.project.ui.OpenProjectList;
61 import org.openide.filesystems.FileUtil;
62 import org.openide.nodes.Node;
65 * Tests for New REST service client stub wizard
69 public class RestCStubsTest extends RestTestBase {
71 private static boolean haveProjects = false;
73 public RestCStubsTest(String name) {
78 public void setUp() throws Exception {
81 File f = new File(getProjectsRootDir(), "FromEntities"); //NOI18N
82 assertTrue("dependent project not found", f.exists() && f.isDirectory());
83 Project p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f));
85 if (!OpenProjectList.getDefault().isOpen(p)) {
86 openProjects(f.getAbsolutePath());
88 f = new File(getProjectsRootDir(), "FromPatterns"); //NOI18N
89 assertTrue("dependent project not found", f.exists() && f.isDirectory());
90 p = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f));
92 if (!OpenProjectList.getDefault().isOpen(p)) {
93 openProjects(f.getAbsolutePath());
100 protected String getProjectName() {
101 return "RESTClient"; //NOI18N
106 * - select target folder using browse... (browse folders dialog)
109 * - then Cancel the wizard
111 public void testWizard() {
113 //RESTful Web Service Client Stubs
114 String cStubsLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "Templates/WebServices/RestClientStubs");
115 String path = FileUtil.toFile(getProject("FromEntities").getProjectDirectory()).getAbsolutePath(); //NOI18N
116 String path2 = FileUtil.toFile(getProject("FromPatterns").getProjectDirectory()).getAbsolutePath(); //NOI18N
117 createNewWSFile(getProject(), cStubsLabel);
118 WizardOperator wo = new WizardOperator(cStubsLabel);
119 //browse to set target folder
120 String browseLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_BrowseFolder");
121 JButtonOperator jbo = new JButtonOperator(wo, browseLabel);
123 String browseFoldersLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_BrowseFolders");
124 NbDialogOperator ndo = new NbDialogOperator(browseFoldersLabel);
125 JTreeOperator jto = new JTreeOperator(ndo);
126 new org.netbeans.jellytools.nodes.Node(jto, jto.findPath("Source Packages")).select(); //NOI18N
128 assertEquals("browse selection not propagated", "", new JTextFieldOperator(wo, 2).getText().trim()); //NOI18N
130 ndo = new NbDialogOperator(browseFoldersLabel);
131 jto = new JTreeOperator(ndo);
132 new org.netbeans.jellytools.nodes.Node(jto, "Web Pages|WEB-INF").select(); //NOI18N
134 assertEquals("browse selection not propagated", "WEB-INF", new JTextFieldOperator(wo, 2).getText().trim()); //NOI18N
136 addProject(wo, path);
137 JListOperator jlo = new JListOperator(wo, 1);
138 ListModel lm = jlo.getModel();
141 } catch (InterruptedException ie) {
143 assertEquals(1, lm.getSize());
145 addProject(wo, path2);
148 } catch (InterruptedException ie) {
150 assertEquals(2, lm.getSize());
151 //select first project
154 String removeLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_RemoveProject");
155 new JButtonOperator(wo, removeLabel).push();
158 } catch (InterruptedException ie) {
160 assertEquals(1, lm.getSize());
161 //cancel/close the wizard
166 * Test stubs creation from a foreign project
168 public void testCreateSimpleStubs() {
169 createStubs("FromEntities"); //NOI18N
173 * Test stubs creation from a local WADL file
175 public void testFromWADL() throws IOException {
176 //RESTful Web Service Client Stubs
177 String cStubsLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "Templates/WebServices/RestClientStubs");
178 createNewWSFile(getProject(), cStubsLabel);
179 WizardOperator wo = new WizardOperator(cStubsLabel);
180 String browseLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_BrowseFolder");
181 String browseFoldersLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_BrowseFolders");
182 JButtonOperator jbo = new JButtonOperator(wo, browseLabel);
184 new NbDialogOperator(browseFoldersLabel).cancel();
185 assertEquals("browse selection propagated", "rest", new JTextFieldOperator(wo, 2).getText().trim()); //NOI18N
186 //click on the use wadl button
187 JRadioButtonOperator jrbo = new JRadioButtonOperator(wo, 1);
189 JTextFieldOperator jtfo = new JTextFieldOperator(wo, 0);
191 jtfo.typeText(new File(getRestDataDir(), "testApplication.wadl").getCanonicalFile().getAbsolutePath()); //NOI18N
193 new JCheckBoxOperator(wo, 0).setSelected(true);
195 //click on the radio button again to force the wizard to revalidate itself
196 //WA for: http://www.netbeans.org/issues/show_bug.cgi?id=128445
199 //Generating Client Stubs From RESTful Web Services...
200 String progressLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_ClientStubsProgress");
201 waitDialogClosed(progressLabel);
204 protected void createStubs(String sourceProject) {
205 String sourcePath = FileUtil.toFile(getProject(sourceProject).getProjectDirectory()).getAbsolutePath();
206 //RESTful Web Service Client Stubs
207 String cStubsLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "Templates/WebServices/RestClientStubs");
208 createNewWSFile(getProject(), cStubsLabel);
209 WizardOperator wo = new WizardOperator(cStubsLabel);
210 addProject(wo, sourcePath);
212 new JCheckBoxOperator(wo, 0).setSelected(true);
215 //Generating Client Stubs From RESTful Web Services...
216 String progressLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_ClientStubsProgress");
217 waitDialogClosed(progressLabel);
220 protected boolean useJMaki() {
224 private void addProject(WizardOperator wo, String path) {
226 String addProjectLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_AddProject");
227 new JButtonOperator(wo, addProjectLabel).pushNoBlock();
229 String prjDlgTitle = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "LBL_ProjectChooserTitle");
230 NbDialogOperator ndo = new NbDialogOperator(prjDlgTitle);
231 JTextFieldOperator jtfo = new JTextFieldOperator(ndo, 0);
235 JButton jb = JButtonOperator.findJButton(ndo.getContentPane(), "Open", false, false); //NOI18N
237 JButtonOperator jbo = new JButtonOperator(jb);
240 fail("Open button not found...."); //NOI18N
244 private Project getProject(String name) {
245 ProjectRootNode n = ProjectsTabOperator.invoke().getProjectRootNode(name);
246 return ((Node) n.getOpenideNode()).getLookup().lookup(Project.class);
250 * Creates suite from particular test cases. You can define order of testcases here.
252 public static Test suite() {
253 return NbModuleSuite.create(addServerTests(Server.GLASSFISH, NbModuleSuite.createConfiguration(RestCStubsTest.class),
254 "testWizard", //NOI18N
255 "testCreateSimpleStubs", //NOI18N
256 "testFromWADL", //NOI18N
257 "testCloseProject" //NOI18N
258 ).enableModules(".*").clusters(".*")); //NOI18N