KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > wizard > NewFileWizardsTest


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 package org.netbeans.test.j2ee.wizard;
20
21 import java.io.File JavaDoc;
22 import java.io.FilenameFilter JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29 import junit.textui.TestRunner;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.jellytools.JellyTestCase;
32 import org.netbeans.jellytools.NewFileNameLocationStepOperator;
33 import org.netbeans.jellytools.NewFileWizardOperator;
34 import org.netbeans.jellytools.OutputOperator;
35 import org.netbeans.jellytools.ProjectsTabOperator;
36 import org.netbeans.jemmy.EventTool;
37 import org.netbeans.jemmy.operators.JCheckBoxOperator;
38 import org.netbeans.jemmy.operators.JComboBoxOperator;
39 import org.netbeans.jemmy.operators.JRadioButtonOperator;
40 import org.netbeans.jemmy.operators.JTextFieldOperator;
41 import org.netbeans.junit.NbTestCase;
42 import org.netbeans.junit.NbTestSuite;
43 import org.netbeans.test.j2ee.lib.ContentComparator;
44 import org.netbeans.test.j2ee.lib.FilteringLineDiff;
45 import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
46 import org.netbeans.test.j2ee.lib.Reporter;
47 import org.netbeans.test.j2ee.lib.Ejb;
48 import org.netbeans.test.j2ee.lib.Utils;
49 import org.netbeans.test.j2ee.lib.WebSvc;
50
51 /**
52  * Test New File wizards in J2EE area. These tests are
53  * part of J2EE Functional test suite.
54  * In each test is checked if all classes are created
55  * and if deployment descriptors are changed accordingly.
56  *
57  * @author jungi
58  * @see <a HREF="http://qa.netbeans.org/modules/j2ee/promo-f/testspec/j2ee-wizards-testspec.html">J2EE Wizards Test Specification</a>
59  */

60 public class NewFileWizardsTest extends JellyTestCase {
61     
62     private static boolean CREATE_GOLDEN_FILES = Boolean.getBoolean("org.netbeans.test.j2ee.wizard.golden");
63 // private static boolean CREATE_GOLDEN_FILES = true;
64

65     private static final String JavaDoc DEF_EJB_MOD =
66             "../../org.netbeans.test.j2ee.wizard.NewProjectWizardsTest/" +
67             "testDefaultNewEJBModWizard/def EJB Mod";
68     private static final String JavaDoc DEF_WEB_MOD =
69             "../../org.netbeans.test.j2ee.wizard.NewProjectWizardsTest/" +
70             "testDefaultNewWebModWizard/def Web app";
71     private static final String JavaDoc BAD_EJB_MOD =
72             "../../org.netbeans.test.j2ee.wizard.NewProjectWizardsTest/" +
73             "testNewEJBModWizard/BadModule";
74     public static final String JavaDoc MULTI_EJB = System.getProperty("xtest.tmpdir") +
75             File.separator + "MultiSrcRootEjb";
76     public static final String JavaDoc MULTI_WEB = System.getProperty("xtest.tmpdir") +
77             File.separator + "MultiSrcRootWar";
78     
79     private Reporter reporter;
80     private String JavaDoc version;
81     
82     public NewFileWizardsTest(String JavaDoc testName) {
83         this(testName, "1.4");
84     }
85     
86     public NewFileWizardsTest(String JavaDoc testName, String JavaDoc version) {
87         super(testName);
88         this.version = version;
89     }
90     
91     public static void main(String JavaDoc[] args) {
92         TestRunner.run(suite());
93     }
94     
95     public static Test suite() {
96         TestSuite suite = new NbTestSuite(NewFileWizardsTest.class);
97         return suite;
98     }
99     
100     public void setUp() throws Exception JavaDoc {
101         reporter = Reporter.getReporter((NbTestCase) this);
102     }
103     
104     public void tearDown() throws Exception JavaDoc {
105         reporter.close();
106     }
107     
108     /**
109      * Create new web service from scratch in EJB module.
110      */

111     public void testNewWebSvcWizardInEjb() throws Exception JavaDoc {
112         webSvcTest(DEF_EJB_MOD + version, "DefaultWSinEjb", "websvc", null);
113     }
114     
115     /**
116      * Create new message handler from template in EJB module.
117      */

118     public void testMsgHandlerInEjb() throws Exception JavaDoc {
119         msgHandlerTest(DEF_EJB_MOD + version, "MsgHandler", "handler", null);
120     }
121     
122     /**
123      * Create new web service from scratch in Web application.
124      */

125     public void testNewWebSvcWizardInWeb() throws Exception JavaDoc {
126         webSvcTest(DEF_WEB_MOD + version, "DefaultWSinWeb", "websvc", null);
127     }
128     
129     /**
130      * Create new web service from scratch in JavaEE5 Web application.
131      */

132     public void testNewWebSvcWizardInWeb5() throws Exception JavaDoc {
133         webSvcTest5(DEF_WEB_MOD + version, "DefaultWSinWeb5", "websvc", null);
134     }
135     
136     /**
137      * Create new web service from scratch in JavaEE5 Ejb Module.
138      */

139     public void testNewWebSvcWizardInEjb5() throws Exception JavaDoc {
140         webSvcTest5(DEF_EJB_MOD + version, "DefaultWSinEjb5", "websvc", null);
141     }
142     
143     /**
144      * Create new message handler from template in Web application.
145      */

146     public void testMsgHandlerInWeb() throws Exception JavaDoc {
147         msgHandlerTest(DEF_WEB_MOD + version, "MsgHandler", "handler", null);
148     }
149     
150     /**
151      * Create new stateless session bean with local interface.
152      */

153     public void testLocalSessionBean() throws Exception JavaDoc {
154         ejbTest("Session Bean", DEF_EJB_MOD + version, "LocalSession",
155                 "ejbs.local", true, false, true, null);
156     }
157     
158     /**
159      * Create new stateless session bean with remote interface.
160      */

161     public void testRemoteSessionBean() throws Exception JavaDoc {
162         ejbTest("Session Bean", DEF_EJB_MOD + version, "RemoteSession",
163                 "ejbs.remote", false, true, true, null);
164     }
165     
166     /**
167      * Create new stateless session bean with local and remote interfaces.
168      */

169     public void testLocalRemoteSessionBean() throws Exception JavaDoc {
170         ejbTest("Session Bean", DEF_EJB_MOD + version, "LocalAndRemoteSession",
171                 "ejbs", true, true, true, null);
172     }
173     
174     /**
175      * Create new stateful session bean with local interface.
176      */

177     public void testLocalStatefulSessionBean() throws Exception JavaDoc {
178         ejbTest("Session Bean", DEF_EJB_MOD + version, "LocalStatefulSession",
179                 "stateful.ejbs.local", true, false, false, null);
180     }
181     
182     /**
183      * Create new stateful session bean with remote interface.
184      */

185     public void testRemoteStatefulSessionBean() throws Exception JavaDoc {
186         ejbTest("Session Bean", DEF_EJB_MOD + version, "RemoteStatefulSession",
187                 "stateful.ejbs.remote", false, true, false, null);
188     }
189     
190     /**
191      * Create new stateful session bean with local and remote interfaces.
192      */

193     public void testLocalRemoteStatefulSessionBean() throws Exception JavaDoc {
194         ejbTest("Session Bean", DEF_EJB_MOD + version, "LocalAndRemoteStatefulSession",
195                 "stateful.ejbs", true, true, false, null);
196     }
197     
198     /**
199      * Create new CMP entity bean with local interface
200      * and <code>String</code> as primary key class.
201      */

202     public void testLocalEntityBean() throws Exception JavaDoc {
203         ejbTest("Entity Bean", DEF_EJB_MOD + version, "LocalEntity",
204                 "ejbs.entity.local", true, false, true, null);
205     }
206     
207     /**
208      * Create new CMP entity bean with remote interface
209      * and <code>String</code> as primary key class.
210      */

211     public void testRemoteEntityBean() throws Exception JavaDoc {
212         ejbTest("Entity Bean", DEF_EJB_MOD + version, "RemoteEntity",
213                 "ejbs.entity.remote", false, true, true, null);
214     }
215     
216     /**
217      * Create new CMP entity bean with local and remote interfaces
218      * and <code>String</code> as primary key class.
219      */

220     public void testLocalRemoteEntityBean() throws Exception JavaDoc {
221         ejbTest("Entity Bean", DEF_EJB_MOD + version, "LocalAndRemoteEntity",
222                 "ejbs.entity", true, true, true, null);
223     }
224     
225     /**
226      * Create new BMP entity bean with local interface
227      * and <code>String</code> as primary key class.
228      */

229     public void testLocalBeanEntityBean() throws Exception JavaDoc {
230         ejbTest("Entity Bean", BAD_EJB_MOD + version, "LocalBeanEntity",
231                 "ejbs.entity.bean.local", true, false, false, null);
232     }
233     
234     /**
235      * Create new BMP entity bean with remote interface
236      * and <code>String</code> as primary key class.
237      */

238     public void testRemoteBeanEntityBean() throws Exception JavaDoc {
239         ejbTest("Entity Bean", BAD_EJB_MOD + version, "RemoteBeanEntity",
240                 "ejbs.entity.bean.remote", false, true, false, null);
241     }
242     
243     /**
244      * Create new BMP entity bean with local and remote interfaces
245      * and <code>String</code> as primary key class.
246      */

247     public void testLocalRemoteBeanEntityBean() throws Exception JavaDoc {
248         ejbTest("Entity Bean", BAD_EJB_MOD + version, "LocalAndRemoteBeanEntity",
249                 "ejbs.entity.bean", true, true, false, null);
250     }
251     
252     /**
253      * Create new queue message-driven bean.
254      */

255     public void testQueueMdbBean() throws Exception JavaDoc {
256         ejbTest("Message-Driven Bean", DEF_EJB_MOD + version, "QueueMdb",
257                 "ejbs.mdb", false, false, true, null);
258     }
259     
260     /**
261      * Create new topic message-driven bean.
262      */

263     public void testTopicMdbBean() throws Exception JavaDoc {
264         ejbTest("Message-Driven Bean", DEF_EJB_MOD + version, "TopicMdb",
265                 "ejbs.mdb", false, false, false, null);
266     }
267     
268     /**
269      * Create new persistence unit in Ejb module.
270      */

271     public void testPersistenceUnitInEjb() throws Exception JavaDoc {
272         puTest(DEF_EJB_MOD + version, "ejbPu");
273     }
274     
275     /**
276      * Create new persistence unit in Web module.
277      */

278     public void testPersistenceUnitInWeb() throws Exception JavaDoc {
279         puTest(DEF_WEB_MOD + version, "webPu");
280     }
281     
282     /**
283      * Create new entity class in Ejb module.
284      */

285     public void testEntityClassInEjb() throws Exception JavaDoc {
286         entityClassTest(DEF_EJB_MOD + version, "EjbEntity",
287                 "ejb.entity", null);
288     }
289     
290     /**
291      * Create new entity class in Web module.
292      */

293     public void testEntityClassInWeb() throws Exception JavaDoc {
294         entityClassTest(DEF_WEB_MOD + version, "WebEntity",
295                 "web.entity", null);
296     }
297     
298     /**
299      * Create new service locator from template in EJB module.
300      */

301     public void testServiceLocatorInEjb() throws Exception JavaDoc {
302         serviceLocatorTest(DEF_EJB_MOD + version, "ServiceLocator",
303                 "locator", false, null);
304     }
305     
306     /**
307      * Create new caching service locator from template in EJB module.
308      */

309     public void testCachingServiceLocatorInEjb() throws Exception JavaDoc {
310         serviceLocatorTest(DEF_EJB_MOD + version, "CachingServiceLocator",
311                 "locator.cache", true, null);
312     }
313     
314     /**
315      * Create new service locator from template in Web application.
316      */

317     public void testServiceLocatorInWeb() throws Exception JavaDoc {
318         serviceLocatorTest(DEF_WEB_MOD + version, "ServiceLocator",
319                 "locator", false, null);
320     }
321     
322     /**
323      * Create new service locator from template in Web application.
324      */

325     public void testCachingServiceLocatorInWeb() throws Exception JavaDoc {
326         serviceLocatorTest(DEF_WEB_MOD + version, "CachingServiceLocator",
327                 "locator.cache", true, null);
328     }
329     
330     /**
331      * Create new WSDL file from template in Web application.
332      */

333     public void testWSDLinWeb() throws Exception JavaDoc {
334         wsdlFileTest(DEF_WEB_MOD + version, "web_wsdl", "web/WEB-INF/wsdl", null);
335     }
336     
337     /**
338      * Create new WSDL file from template in EJB module.
339      */

340     public void testWSDLinEjb() throws Exception JavaDoc {
341         wsdlFileTest(DEF_EJB_MOD + version, "ejb_wsdl", "src/conf/wsdl", null);
342     }
343     
344     /**
345      * Build EJB Module with created beans, web service
346      * and other objects.
347      */

348     public void testBuildDefaultNewEJBMod() {
349         tearDownProject("def EJB Mod" + version);
350     }
351     
352     /**
353      * Build Web application with web service
354      * and other objects.
355      */

356     public void testBuildDefaultNewWebMod() {
357         tearDownProject("def Web app" + version);
358     }
359     
360     /**
361      * Build Web application with created beans, web service
362      * and other objects.
363      */

364     public void testBuildDefaultNewJakartaWebMod() {
365         tearDownProject("Jakarta Web App" + version);
366     }
367     
368     /**
369      * Go through New Web Service wizard.
370      */

371     private void webSvcTest(String JavaDoc prjRoot, String JavaDoc wsName, String JavaDoc wsPkg,
372             String JavaDoc srcRoot) throws Exception JavaDoc {
373         boolean hasMoreSrcRoots = (srcRoot != null);
374         Project p = (hasMoreSrcRoots)
375         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
376         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
377         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
378                 "Web Services", "Web Service");
379         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
380                 wsName, wsPkg, srcRoot);
381         nop.finish();
382         //wait until webservices.xml is generated
383
//new NbDialogOperator("Progress...").waitClosed();
384
new EventTool().waitNoEvent(30000);
385         WebSvc ws = (hasMoreSrcRoots)
386         ? new WebSvc(wsPkg + "." + wsName, p, srcRoot)
387         : new WebSvc(wsPkg + "." + wsName, p);
388         String JavaDoc[] err = ws.checkExistingFiles();
389         assertTrue(Arrays.asList(err).toString(), err.length == 0);
390         List JavaDoc/*File*/ files = new ArrayList JavaDoc();
391         File JavaDoc prjDir = (hasMoreSrcRoots)
392         ? new File JavaDoc(prjRoot).getCanonicalFile()
393         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
394         if (wsName.indexOf("Ejb") > 0) {
395             files.add(new File JavaDoc(prjDir, "src/conf/ejb-jar.xml"));
396             files.add(new File JavaDoc(prjDir, "src/conf/sun-ejb-jar.xml"));
397             files.add(new File JavaDoc(prjDir, "src/conf/webservices.xml"));
398         } else {
399             files.add(new File JavaDoc(prjDir, "web/WEB-INF/web.xml"));
400             files.add(new File JavaDoc(prjDir, "web/WEB-INF/sun-web.xml"));
401             files.add(new File JavaDoc(prjDir, "web/WEB-INF/webservices.xml"));
402         }
403         if (!hasMoreSrcRoots) {
404             files.addAll(Arrays.asList(
405                     new File JavaDoc(prjDir, "src/java/" + wsPkg.replace('.', '/') + "/")
406                     .listFiles(new Filter JavaDoc(wsName))));
407         } else {
408             files.addAll(Arrays.asList(
409                     new File JavaDoc(prjDir, srcRoot + "/" + wsPkg.replace('.', '/') + "/")
410                     .listFiles(new Filter JavaDoc(wsName))));
411         }
412         checkFiles(files);
413     }
414     
415     /**
416      * Go through New Web Service wizard.
417      */

418     private void webSvcTest5(String JavaDoc prjRoot, String JavaDoc wsName, String JavaDoc wsPkg,
419             String JavaDoc srcRoot) throws Exception JavaDoc {
420         Project p = J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
421         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
422                 "Web Services", "Web Service");
423         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
424                 wsName, wsPkg, srcRoot);
425         nop.finish();
426         new EventTool().waitNoEvent(30000);
427         List JavaDoc/*File*/ files = new ArrayList JavaDoc();
428         File JavaDoc prjDir = new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
429         files.addAll(Arrays.asList(
430                 new File JavaDoc(prjDir, "src/java/" + wsPkg.replace('.', '/') + "/")
431                 .listFiles(new Filter JavaDoc(wsName))));
432         checkFiles(files);
433     }
434     
435     /**
436      * Go through New Message Handler wizard.
437      */

438     private void msgHandlerTest(String JavaDoc prjRoot, String JavaDoc name, String JavaDoc pkg, String JavaDoc srcRoot)
439     throws Exception JavaDoc {
440         boolean hasMoreSrcRoots = (srcRoot != null);
441         Project p = (hasMoreSrcRoots)
442         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
443         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
444         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
445                 "Web Services", "Message Handler");
446         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
447                 name, pkg, srcRoot);
448         nop.finish();
449         List JavaDoc/*File*/ files = new ArrayList JavaDoc(1);
450         File JavaDoc prjDir = (hasMoreSrcRoots)
451         ? new File JavaDoc(prjRoot).getCanonicalFile()
452         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
453         if (!hasMoreSrcRoots) {
454             files.add(new File JavaDoc(prjDir, "src/java/" + pkg.replace('.', '/') + "/" + name + ".java"));
455         } else {
456             files.add(new File JavaDoc(prjDir, srcRoot + "/" + pkg.replace('.', '/') + "/" + name + ".java"));
457         }
458         checkFiles(files);
459     }
460     
461     /**
462      * Go through New Session/Entity/Message-Driven Bean wizard.
463      *
464      *@param stateless stateless/stateful option in case of session bean,
465      * container/bean in case of entity bean,
466      * queue/topic in case of mdb bean
467      */

468     private void ejbTest(String JavaDoc type, String JavaDoc prjRoot, String JavaDoc ejbName, String JavaDoc ejbPkg,
469             boolean local, boolean remote, boolean stateless, String JavaDoc srcRoot) throws Exception JavaDoc {
470         boolean hasMoreSrcRoots = (srcRoot != null);
471         Project p = (hasMoreSrcRoots)
472         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
473         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
474         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
475                 "Enterprise", type);
476         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
477                 ejbName, ejbPkg, srcRoot);
478         if (type.equals("Message-Driven Bean")) {
479             if (!stateless) {
480                 new JRadioButtonOperator(nop, "Topic").setSelected(true);
481             }
482         } else {
483             if (!stateless) {
484                 if (type.equals("Session Bean")) {
485                     new JRadioButtonOperator(nop, "Stateful").setSelected(true);
486                 } else {
487                     new JRadioButtonOperator(nop, "Bean").setSelected(true);
488                 }
489             }
490             new JCheckBoxOperator(nop, "Local").setSelected(local);
491             new JCheckBoxOperator(nop, "Remote").setSelected(remote);
492         }
493         nop.finish();
494         Ejb ejb = (hasMoreSrcRoots)
495         ? new Ejb(ejbPkg + "." + ejbName, p, local, remote, srcRoot)
496         : new Ejb(ejbPkg + "." + ejbName, p, local, remote);
497         if ("1.4".equals(version)) {
498             String JavaDoc[] err = ejb.checkExistingFiles();
499             assertTrue(Arrays.asList(err).toString(), err.length == 0);
500         }
501         List JavaDoc/*File*/ files = new ArrayList JavaDoc();
502         File JavaDoc prjDir = (hasMoreSrcRoots)
503         ? new File JavaDoc(prjRoot).getCanonicalFile()
504         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
505         if ("1.4".equals(version)) {
506             files.add(new File JavaDoc(prjDir, "src/conf/ejb-jar.xml"));
507             files.add(new File JavaDoc(prjDir, "src/conf/sun-ejb-jar.xml"));
508         }
509         if (!hasMoreSrcRoots) {
510             files.addAll(Arrays.asList(
511                     new File JavaDoc(prjDir, "src/java/" + ejbPkg.replace('.', '/') + "/")
512                     .listFiles(new Filter JavaDoc(ejbName))));
513         } else {
514             files.addAll(Arrays.asList(
515                     new File JavaDoc(prjDir, srcRoot + "/" + ejbPkg.replace('.', '/') + "/")
516                     .listFiles(new Filter JavaDoc(ejbName))));
517         }
518         checkFiles(files);
519     }
520     
521     /**
522      * Go through New (Caching) Service Locator wizard.
523      */

524     private void serviceLocatorTest(String JavaDoc prjRoot, String JavaDoc name, String JavaDoc pkg,
525             boolean caching, String JavaDoc srcRoot) throws Exception JavaDoc {
526         boolean hasMoreSrcRoots = (srcRoot != null);
527         Project p = (hasMoreSrcRoots)
528         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
529         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
530         String JavaDoc type = (caching) ? "Caching Service Locator" : "Service Locator";
531         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
532                 "Enterprise", type);
533         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
534                 name, pkg, srcRoot);
535         nop.finish();
536         List JavaDoc/*File*/ files = new ArrayList JavaDoc(1);
537         File JavaDoc prjDir = (hasMoreSrcRoots)
538         ? new File JavaDoc(prjRoot).getCanonicalFile()
539         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
540         if (!hasMoreSrcRoots) {
541             files.add(new File JavaDoc(prjDir, "src/java/" + pkg.replace('.', '/') + "/" + name + ".java"));
542         } else {
543             files.add(new File JavaDoc(prjDir, srcRoot + "/" + pkg.replace('.', '/') + "/" + name + ".java"));
544         }
545         checkFiles(files);
546     }
547     
548     /**
549      * Go through New WSDL File wizard.
550      */

551     private void wsdlFileTest(String JavaDoc prjRoot, String JavaDoc name, String JavaDoc dir, String JavaDoc srcRoot)
552     throws Exception JavaDoc {
553         Project p = (srcRoot != null)
554         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
555         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
556         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
557                 "Web Services", "WSDL");
558         NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
559         new EventTool().waitNoEvent(500);
560         op.setObjectName(name);
561         new EventTool().waitNoEvent(1000);
562         JTextFieldOperator jtfo = new JTextFieldOperator(op, 2);
563         jtfo.clearText();
564         jtfo.typeText(dir);
565         op.finish();
566         List JavaDoc/*File*/ files = new ArrayList JavaDoc(1);
567         File JavaDoc prjDir = (srcRoot != null)
568         ? new File JavaDoc(prjRoot).getCanonicalFile()
569         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
570         files.add(new File JavaDoc(prjDir, dir + "/" + name + ".wsdl"));
571         checkFiles(files);
572     }
573     
574     private void puTest(String JavaDoc prjRoot, String JavaDoc name) throws Exception JavaDoc {
575         Project p = J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
576         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
577                 "Persistence", "Persistence Unit");
578         JTextFieldOperator jtfo = new JTextFieldOperator(nfwo, 0);
579         jtfo.clearText();
580         jtfo.typeText(name);
581         JComboBoxOperator jcbo = new JComboBoxOperator(nfwo, 1);
582         jcbo.selectItem("sample");
583         nfwo.finish();
584         List JavaDoc/*File*/ files = new ArrayList JavaDoc();
585         File JavaDoc prjDir = new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
586         files.add(new File JavaDoc(prjDir, "src/conf/persistence.xml"));
587         checkFiles(files);
588     }
589     
590     private void entityClassTest(String JavaDoc prjRoot, String JavaDoc name, String JavaDoc pkg, String JavaDoc srcRoot)
591             throws Exception JavaDoc {
592         boolean hasMoreSrcRoots = (srcRoot != null);
593         Project p = (hasMoreSrcRoots)
594         ? J2eeProjectSupport.getProject(new File JavaDoc(prjRoot), ".")
595         : J2eeProjectSupport.getProject(getWorkDir(), prjRoot);
596         NewFileWizardOperator nfwo = WizardUtils.createNewFile(p,
597                 "Persistence", "Entity Class");
598         NewFileNameLocationStepOperator nop = WizardUtils.setFileNameLocation(
599                 name, pkg, srcRoot);
600         nop.finish();
601         List JavaDoc/*File*/ files = new ArrayList JavaDoc();
602         File JavaDoc prjDir = (hasMoreSrcRoots)
603         ? new File JavaDoc(prjRoot).getCanonicalFile()
604         : new File JavaDoc(getWorkDir(), prjRoot).getCanonicalFile();
605         if (!hasMoreSrcRoots) {
606             files.addAll(Arrays.asList(
607                     new File JavaDoc(prjDir, "src/java/" + pkg.replace('.', '/') + "/")
608                     .listFiles(new Filter JavaDoc(name))));
609         } else {
610             files.addAll(Arrays.asList(
611                     new File JavaDoc(prjDir, srcRoot + "/" + pkg.replace('.', '/') + "/")
612                     .listFiles(new Filter JavaDoc(name))));
613         }
614         checkFiles(files);
615     }
616     
617     
618     /**
619      * Check files against golden files.
620      *
621      *@param newFiles files to check
622      */

623     private void checkFiles(List JavaDoc newFiles) {
624         try {
625             //have to wait till files are saved
626
Thread.currentThread().sleep(12500);
627         } catch (InterruptedException JavaDoc ie) {
628             //ignore
629
}
630         if (!CREATE_GOLDEN_FILES) {
631             List JavaDoc l = new ArrayList JavaDoc(newFiles.size() / 2);
632             for (Iterator JavaDoc i = newFiles.iterator(); i.hasNext();) {
633                 File JavaDoc newFile = (File JavaDoc) i.next();
634                 File JavaDoc goldenFile = null;
635                 try {
636                     goldenFile = getGoldenFile(getName() + "_" + version + "/" + newFile.getName() + ".pass");
637                     if (newFile.getName().endsWith(".xml") && !newFile.getName().startsWith("sun-") && !newFile.getName().startsWith("webservices.xml")) {
638                         assertTrue(ContentComparator.equalsXML(goldenFile, newFile));
639                     } else {
640                         assertFile(newFile, goldenFile,
641                                 new File JavaDoc(getWorkDirPath(), newFile.getName() + ".diff"),
642                                 new FilteringLineDiff());
643                     }
644                 } catch (Throwable JavaDoc t) {
645                     goldenFile = getGoldenFile(getName() + "_" + version + "/" + newFile.getName() + ".pass");
646                     Utils.copyFile(newFile, new File JavaDoc(getWorkDirPath(), newFile.getName() + ".bad"));
647                     Utils.copyFile(goldenFile,
648                             new File JavaDoc(getWorkDirPath(), newFile.getName() + ".gf"));
649                     l.add(newFile.getName());
650                 }
651             }
652             assertTrue("File(s) " + l.toString() + " differ(s) from golden files.", l.isEmpty());
653         } else {
654             createGoldenFiles(newFiles);
655         }
656     }
657     
658     private void createGoldenFiles(List JavaDoc/*File*/ from) {
659         File JavaDoc f = getDataDir();;
660         List JavaDoc names = new ArrayList JavaDoc();
661         names.add("goldenfiles");
662         while (!f.getName().equals("test")) {
663             if (!f.getName().equals("sys") && !f.getName().equals("work") &&!f.getName().equals("tests")) {
664                 names.add(f.getName());
665             }
666             f=f.getParentFile();
667         }
668         for (int i=names.size()-1;i > -1;i--) {
669             f=new File JavaDoc(f,(String JavaDoc)(names.get(i)));
670         }
671         f = new File JavaDoc(f, getClass().getName().replace('.', File.separatorChar));
672         File JavaDoc destDir = new File JavaDoc(f, getName() + "_" + version);
673         destDir.mkdirs();
674         for (Iterator JavaDoc i = from.iterator(); i.hasNext();) {
675             File JavaDoc src = (File JavaDoc) i.next();
676             Utils.copyFile(src, new File JavaDoc(destDir, src.getName() + ".pass"));
677         }
678         assertTrue("Golden files generated.", false);
679     }
680     
681     /**
682      * Build project.
683      * @paramprjName project to build
684      * @param projectNameInStatus true if project name is displayed in IDE's status bar
685      */

686     private void tearDownProject(String JavaDoc prjName) {
687         Utils.buildProject(prjName);
688         assertTrue("Project " + prjName + " was not built.",
689                 new OutputOperator().getText().indexOf("BUILD SUCCESSFUL (total time:") > -1);
690     }
691     
692     
693 //----------------------------------------------------- multi src roots projects
694

695     /**
696      * Open EJB Module project with multiple source roots.
697      */

698     public void testOpenEjbMultiRootProject() {
699         assertNotNull(J2eeProjectSupport.openProject(MULTI_EJB));
700         new ProjectsTabOperator().getProjectRootNode("MultiSrcRootEjb").expand();
701     }
702     
703     /**
704      * Open Web application project with multiple source roots.
705      */

706     public void testOpenWebMultiRootProject() {
707         assertNotNull(J2eeProjectSupport.openProject(MULTI_WEB));
708         new ProjectsTabOperator().getProjectRootNode("MultiSrcRootWar").expand();
709     }
710     
711     /**
712      * Create new web service from scratch in EJB module
713      * with multiple source roots.
714      */

715     public void testMultiNewWebSvcWizardInEjb() throws Exception JavaDoc {
716         webSvcTest(MULTI_EJB, "DefaultWSinEjb", "multi.websvc", "src/beans");
717     }
718     
719     /**
720      * Create new message handler from template in EJB module
721      * with multiple source roots.
722      */

723     public void testMultiMsgHandlerInEjb() throws Exception JavaDoc {
724         msgHandlerTest(MULTI_EJB, "MsgHandler", "multi.handler", "src/beans");
725     }
726     
727     /**
728      * Create new web service from scratch in Web application
729      * with multiple source roots.
730      */

731     public void testMultiNewWebSvcWizardInWeb() throws Exception JavaDoc {
732         webSvcTest(MULTI_WEB, "DefaultWSinWeb", "multi.websvc", "src/webservices");
733     }
734     
735     /**
736      * Create new message handler from template in EJB module
737      * with multiple source roots.
738      */

739     public void testMultiMsgHandlerInWeb() throws Exception JavaDoc {
740         msgHandlerTest(MULTI_WEB, "MsgHandler", "multi.handler", "src/webservices");
741     }
742     
743     /**
744      * Create new stateless session bean with local interface
745      * in project with multiple source roots.
746      */

747     public void testMultiLocalSessionBean() throws Exception JavaDoc {
748         ejbTest("Session Bean", MULTI_EJB, "LocalSession",
749                 "multi.ejbs.local", true, false, true, "src/beans");
750     }
751     
752     /**
753      * Create new stateless session bean with remote interface
754      * in project with multiple source roots.
755      */

756     public void testMultiRemoteSessionBean() throws Exception JavaDoc {
757         ejbTest("Session Bean", MULTI_EJB, "RemoteSession",
758                 "multi.ejbs.remote", false, true, true, "src/beans");
759     }
760     
761     /**
762      * Create new stateless session bean with local and remote interfaces
763      * in project with multiple source roots.
764      */

765     public void testMultiLocalRemoteSessionBean() throws Exception JavaDoc {
766         ejbTest("Session Bean", MULTI_EJB, "LocalAndRemoteSession",
767                 "multi.ejbs", true, true, true, "src/beans");
768     }
769     
770     /**
771      * Create new stateful session bean with local interface
772      * in project with multiple source roots.
773      */

774     public void testMultiLocalStatefulSessionBean() throws Exception JavaDoc {
775         ejbTest("Session Bean", MULTI_EJB, "LocalStatefulSession",
776                 "multi.stateful.ejbs.local", true, false, false, "src/beans");
777     }
778     
779     /**
780      * Create new stateful session bean with remote interface
781      * in project with multiple source roots.
782      */

783     public void testMultiRemoteStatefulSessionBean() throws Exception JavaDoc {
784         ejbTest("Session Bean", MULTI_EJB, "RemoteStatefulSession",
785                 "multi.stateful.ejbs.remote", false, true, false, "src/beans");
786     }
787     
788     /**
789      * Create new stateful session bean with local and remote interfaces
790      * in project with multiple source roots.
791      */

792     public void testMultiLocalRemoteStatefulSessionBean() throws Exception JavaDoc {
793         ejbTest("Session Bean", MULTI_EJB, "LocalAndRemoteStatefulSession",
794                 "multi.stateful.ejbs", true, true, false, "src/beans");
795     }
796     
797     /**
798      * Create new CMP entity bean with local interface
799      * and <code>String</code> as primary key class
800      * in project with multiple source roots.
801      */

802     public void testMultiLocalEntityBean() throws Exception JavaDoc {
803         ejbTest("Entity Bean", MULTI_EJB, "LocalEntity",
804                 "multi.ejbs.entity.local", true, false, true, "src/beans");
805     }
806     
807     /**
808      * Create new CMP entity bean with remote interface
809      * and <code>String</code> as primary key class
810      * in project with multiple source roots.
811      */

812     public void testMultiRemoteEntityBean() throws Exception JavaDoc {
813         ejbTest("Entity Bean", MULTI_EJB, "RemoteEntity",
814                 "multi.ejbs.entity.remote", false, true, true, "src/beans");
815     }
816     
817     /**
818      * Create new CMP entity bean with local and remote interfaces
819      * and <code>String</code> as primary key class
820      * in project with multiple source roots.
821      */

822     public void testMultiLocalRemoteEntityBean() throws Exception JavaDoc {
823         ejbTest("Entity Bean", MULTI_EJB, "LocalAndRemoteEntity",
824                 "multi.ejbs.entity", true, true, true, "src/beans");
825     }
826     
827     /**
828      * Create new queue message-driven bean
829      * in project with multiple source roots.
830      */

831     public void testMultiQueueMdbBean() throws Exception JavaDoc {
832         ejbTest("Message-Driven Bean", MULTI_EJB, "QueueMdb",
833                 "multi.ejbs.mdb", false, false, true, "src/beans");
834     }
835     
836     /**
837      * Create new topic message-driven bean
838      * in project with multiple source roots.
839      */

840     public void testMultiTopicMdbBean() throws Exception JavaDoc {
841         ejbTest("Message-Driven Bean", MULTI_EJB, "TopicMdb",
842                 "multi.ejbs.mdb", false, false, false, "src/beans");
843     }
844     
845     /**
846      * Create new service locator from template in EJB module
847      * with multiple source roots.
848      */

849     public void testMultiServiceLocatorInEjb() throws Exception JavaDoc {
850         serviceLocatorTest(MULTI_EJB, "ServiceLocator",
851                 "multi.locator", false, "src/beans");
852     }
853     
854     /**
855      * Create new caching service locator from template in EJB module
856      * with multiple source roots.
857      */

858     public void testMultiCachingServiceLocatorInEjb() throws Exception JavaDoc {
859         serviceLocatorTest(MULTI_EJB, "CachingServiceLocator",
860                 "multi.locator.cache", true, "src/beans");
861     }
862     
863     /**
864      * Create new service locator from template in Web application
865      * with multiple source roots.
866      */

867     public void testMultiServiceLocatorInWeb() throws Exception JavaDoc {
868         serviceLocatorTest(MULTI_WEB, "ServiceLocator",
869                 "multi.locator", false, "src/webservices");
870     }
871     
872     /**
873      * Create new caching service locator from template in Web application
874      * with multiple source roots.
875      */

876     public void testMultiCachingServiceLocatorInWeb() throws Exception JavaDoc {
877         serviceLocatorTest(MULTI_WEB, "CachingServiceLocator",
878                 "multi.locator.cache", true, "src/webservices");
879     }
880     
881     /**
882      * Create new WSDL file from template in Web application
883      * with multiple source roots.
884      */

885     public void testMultiWSDLinWeb() throws Exception JavaDoc {
886         wsdlFileTest(MULTI_WEB, "web_wsdl", "web/WEB-INF/wsdl", "");
887     }
888     
889     /**
890      * Create new WSDL file from template in EJB module
891      * with multiple source roots.
892      */

893     public void testMultiWSDLinEjb() throws Exception JavaDoc {
894         wsdlFileTest(MULTI_EJB, "ejb_wsdl", "src/conf/wsdl", "");
895     }
896     
897     /**
898      * Build EJB Module with created beans, web service
899      * and other objects in other then default source root..
900      */

901     public void testBuildEjbMultiRootProject() {
902         tearDownProject("MultiSrcRootEjb");
903     }
904     
905     /**
906      * Build Web application with created web service
907      * and other objects in other then default source root..
908      */

909     public void testBuildWebMultiRootProject() {
910         tearDownProject("MultiSrcRootWar");
911     }
912
913     private class Filter implements FilenameFilter JavaDoc {
914         
915         private String JavaDoc start;
916         
917         public Filter(String JavaDoc name) {
918             start = name;
919         }
920         
921         public boolean accept(File JavaDoc dir, String JavaDoc name) {
922             return name.startsWith(start);
923         }
924     }
925 }
926
Popular Tags