KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
23 import java.io.FilenameFilter JavaDoc;
24 import java.io.IOException JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.jellytools.*;
27 import org.netbeans.jellytools.actions.Action;
28 import org.netbeans.jellytools.actions.ActionNoBlock;
29 import org.netbeans.jellytools.actions.OpenAction;
30 import org.netbeans.jellytools.nodes.Node;
31 import org.netbeans.jemmy.JemmyException;
32 import org.netbeans.jemmy.Waitable;
33 import org.netbeans.jemmy.Waiter;
34 import org.netbeans.jemmy.operators.*;
35 import org.netbeans.junit.NbTestSuite;
36 import org.netbeans.junit.ide.ProjectSupport;
37 import org.netbeans.test.j2ee.*;
38 import org.netbeans.test.j2ee.lib.Utils;
39
40 /**
41  *
42  * @author lm97939
43  */

44 public class FreeFormProjects extends JellyTestCase {
45     
46     public static final String JavaDoc CMP2_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + "freeform_projects" + File.separator + "cmp2";
47     public static final String JavaDoc TRAVEL_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + "freeform_projects" + File.separator + "travel";
48     public static final String JavaDoc SECURE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + "freeform_projects" + File.separator + "Secure";
49
50     /** Creates a new instance of AddMethodTest */
51     public FreeFormProjects(String JavaDoc name) {
52         super(name);
53     }
54     
55     public static NbTestSuite suite() {
56         NbTestSuite suite = new NbTestSuite();
57         suite.addTest(new FreeFormProjects("testFreeFormEjb"));
58         suite.addTest(new FreeFormProjects("testEjbWithSources"));
59         suite.addTest(new FreeFormProjects("testEarWithSources"));
60         return suite;
61     }
62     
63     /** Use for execution inside IDE */
64     public static void main(java.lang.String JavaDoc[] args) {
65         // run whole suite
66
TestRunner.run(suite());
67     }
68     
69     public void setUp() {
70         System.out.println("######## "+getName()+" #######");
71     }
72     
73     public void testFreeFormEjb() {
74         createNewFreeFormEjbProject(CMP2_PROJECT_PATH, null,
75                 new String JavaDoc[] {"Gangster Entity Bean", "Job Entity Bean", "Organization Entity Bean"},
76                 new String JavaDoc[] {"GangsterBean", "JobBean", "OrganizationBean"});
77     }
78     
79     public void testEjbWithSources() {
80         createNewEjbProjectFromExistingSources(TRAVEL_PROJECT_PATH, "Travel", TRAVEL_PROJECT_PATH+"-projects",
81                 new String JavaDoc[] {"TravelAgentEJB", "CabinEJB"},
82                 new String JavaDoc[] {"TravelAgentBean", "CabinBean"});
83     }
84     
85     public void testEarWithSources() {
86         createNewEarProjectFromExistingSources(SECURE_PROJECT_PATH, "Secure", SECURE_PROJECT_PATH+"-projects");
87     }
88     
89     private void createNewFreeFormEjbProject(String JavaDoc location, String JavaDoc name, String JavaDoc beans[], String JavaDoc files[]) {
90         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
91         npwo.selectCategory("Enterprise");
92         npwo.selectProject("EJB Module with Existing Ant Script");
93         npwo.next();
94         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
95         new JTextFieldOperator(npnlso,3).setText(location); // NOI18N
96
if (name != null)
97             new JTextFieldOperator(npnlso,1).setText(name);
98         else
99             name = new JTextFieldOperator(npnlso,1).getText();
100         npnlso.next();
101         new NewProjectWizardOperator().next();
102         new NewProjectWizardOperator().next();
103         new NewProjectWizardOperator().next();
104         new NewProjectWizardOperator().finish();
105         //wait project appear in projects view
106
Node rootNode = new ProjectsTabOperator().getProjectRootNode(name);
107         // wait classpath scanning finished
108
ProjectSupport.waitScanFinished();
109         
110         Node beansNode = new Node(rootNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node"));
111         if (beans != null) {
112             for (int i=0; i<beans.length; i++) {
113                 Node node = new Node(beansNode, beans[i]);
114                 node.expand();
115                 String JavaDoc children[] = node.getChildren();
116                 if (children == null || children.length <= 0) {
117                     fail ("Bean node "+beans[i]+" has no children");
118                 }
119                 if (beans != null) {
120                     new OpenAction().perform(node);
121                     new EditorOperator(files[i]).close();
122                 }
123             }
124         }
125         new Node(new ProjectsTabOperator().getProjectRootNode(name),
126                       "Configuration Files|ejb-jar.xml");
127         // Build project
128
rootNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Actions/Build"));
129         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
130         MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String JavaDoc[] {name+" (build)"}));
131
132     }
133     
134     private void createNewEjbProjectFromExistingSources(String JavaDoc location, String JavaDoc name, String JavaDoc folder, String JavaDoc beans[], String JavaDoc files[]) {
135         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
136         npwo.selectCategory("Enterprise");
137         npwo.selectProject("EJB Module with Existing Sources");
138         npwo.next();
139         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
140         new JTextFieldOperator(npnlso,0).setText(location); // NOI18N
141
new JTextFieldOperator(npnlso,1).setText(name); // NOI18N
142
new JTextFieldOperator(npnlso,2).setText(folder); // NOI18N
143
new NewProjectWizardOperator().next();
144         new NewProjectWizardOperator().finish();
145         //wait project appear in projects view
146
Node rootNode = new ProjectsTabOperator().getProjectRootNode(name);
147         // wait classpath scanning finished
148
ProjectSupport.waitScanFinished();
149         Node beansNode = new Node(rootNode, Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node"));
150         if (beans != null) {
151             for (int i=0; i<beans.length; i++) {
152                 Node node = new Node(beansNode, beans[i]);
153                 node.expand();
154                 String JavaDoc children[] = node.getChildren();
155                 if (children == null || children.length <= 0) {
156                     fail ("Bean node "+beans[i]+" has no children");
157                 }
158                 if (beans != null) {
159                     new OpenAction().perform(node);
160                     new EditorOperator(files[i]).close();
161                 }
162             }
163         }
164         new Node(new ProjectsTabOperator().getProjectRootNode(name), "Configuration Files|ejb-jar.xml");
165         // Build project
166
rootNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Actions/Build"));
167         MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
168         MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String JavaDoc[] {name+" (dist)"}));
169     }
170     
171     private void createNewEarProjectFromExistingSources(String JavaDoc location, String JavaDoc name, String JavaDoc folder) {
172         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
173         npwo.selectCategory("Enterprise");
174         npwo.selectProject("Enterprise Application with Existing Sources");
175         npwo.next();
176         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
177         new JTextFieldOperator(npnlso,1).setText(location); // NOI18N
178
new JTextFieldOperator(npnlso,0).setText(name); // NOI18N
179
new JTextFieldOperator(npnlso,2).setText(folder); // NOI18N
180
new NewProjectWizardOperator().finish();
181         new NbDialogOperator("Warning").ok();
182         //wait project appear in projects view
183
Node rootNode = new ProjectsTabOperator().getProjectRootNode(name);
184         // wait classpath scanning finished
185
ProjectSupport.waitScanFinished();
186        
187         // Build project
188
//rootNode.performPopupAction(Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Actions/Build"));
189
//MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 300000);
190
//MainWindowOperator.getDefault().waitStatusText(Bundle.getString("org.apache.tools.ant.module.run.Bundle", "FMT_finished_target_status", new String[] {name+" (build)"}));
191
}
192     
193 }
194
Popular Tags