1 19 package org.netbeans.test.j2ee.wizard; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import org.netbeans.jellytools.EditorWindowOperator; 29 import org.netbeans.jellytools.JellyTestCase; 30 import org.netbeans.jellytools.NewProjectNameLocationStepOperator; 31 import org.netbeans.jellytools.NewProjectWizardOperator; 32 import org.netbeans.jellytools.ProjectsTabOperator; 33 import org.netbeans.jellytools.nodes.Node; 34 import org.netbeans.jemmy.EventTool; 35 import org.netbeans.jemmy.operators.JComboBoxOperator; 36 import org.netbeans.junit.NbTestCase; 37 import org.netbeans.junit.NbTestSuite; 38 import org.netbeans.test.j2ee.lib.Reporter; 39 import org.netbeans.test.j2ee.lib.RequiredFiles; 40 import org.netbeans.test.j2ee.lib.J2eeProjectSupport; 41 import org.netbeans.test.j2ee.lib.Utils; 42 43 53 public class NewProjectWizardsTest extends JellyTestCase { 54 55 private static final int EJB = 0; 56 private static final int WEB = 1; 57 private static final int WEB_JAKARTA = 2; 58 private static final int J2EE_DEFAULT = 3; 59 private static final int APP_CLIENT_DEFAULT = 4; 60 61 private String projectLocation; 62 private String projectName; 63 private String version; 64 private Reporter reporter; 65 66 public NewProjectWizardsTest(String testName) { 67 this(testName, "1.4"); 68 } 69 70 public NewProjectWizardsTest(String testName, String version) { 71 super(testName); 72 this.version = version; 73 } 74 75 public void setUp() throws Exception { 76 reporter = Reporter.getReporter((NbTestCase)this); 77 } 78 79 public void tearDown() throws Exception { 80 reporter.close(); 81 } 82 83 public static void main(java.lang.String [] args) { 84 junit.textui.TestRunner.run(suite()); 85 } 86 87 public static Test suite() { 88 TestSuite suite = new NbTestSuite(NewProjectWizardsTest.class); 89 return suite; 90 } 91 92 96 public void testDefaultNewEJBModWizard() throws Exception { 97 Utils.openOutputTab(); 98 projectLocation = getWorkDir().getAbsolutePath(); 99 projectName = "def EJB Mod" + version; 100 NewProjectWizardOperator wiz 101 = WizardUtils.createNewProject("Enterprise", "EJB Module"); 102 NewProjectNameLocationStepOperator op 103 = WizardUtils.setProjectNameLocation(projectName, 104 projectLocation); 105 WizardUtils.setJ2eeSpecVersion(op, WizardUtils.MODULE_EJB, version); 106 wiz.finish(); 107 checkProjectStructure(EJB); 108 checkProjectNodes(); 109 } 110 111 114 public void testNewEJBModWizard() throws Exception { 115 projectLocation = getWorkDir().getAbsolutePath(); 116 projectName = "BadModule" + version; 117 NewProjectWizardOperator wiz 118 = WizardUtils.createNewProject("Enterprise", "EJB Module"); 119 NewProjectNameLocationStepOperator op 120 = WizardUtils.setProjectNameLocation(projectName, 121 projectLocation); 122 WizardUtils.setJ2eeSpecVersion(op, WizardUtils.MODULE_EJB, version); 123 wiz.finish(); 124 checkProjectStructure(EJB); 125 checkProjectNodes(); 126 } 127 128 129 133 public void testDefaultAppClientWizard() throws Exception { 134 projectLocation = getWorkDir().getAbsolutePath(); 135 projectName = "App client" + version; 136 NewProjectWizardOperator wiz 137 = WizardUtils.createNewProject("Enterprise", "Enterprise Application Client"); 138 NewProjectNameLocationStepOperator op 139 = WizardUtils.setProjectNameLocation(projectName, 140 projectLocation); 141 WizardUtils.setJ2eeSpecVersion(op, WizardUtils.MODULE_CAR, version); 142 wiz.finish(); 143 checkProjectStructure(APP_CLIENT_DEFAULT); 144 checkProjectNodes(); 145 } 146 147 151 public void testDefaultNewWebModWizard() throws Exception { 152 projectLocation = getWorkDir().getAbsolutePath(); 153 projectName = "def Web app" + version; 154 NewProjectWizardOperator wiz 155 = WizardUtils.createNewProject("Web", "Web Application"); 156 NewProjectNameLocationStepOperator op 157 = WizardUtils.setProjectNameLocation(projectName, 158 projectLocation); 159 WizardUtils.setJ2eeSpecVersion(op, WizardUtils.MODULE_WAR, version); 160 wiz.finish(); 161 Thread.sleep(1000); 162 checkProjectStructure(WEB); 163 checkProjectNodes(); 164 } 165 166 169 public void testDefaultNewJakartaWebModWizard() throws Exception { 170 projectLocation = getWorkDir().getAbsolutePath(); 171 projectName = "Jakarta Web App" + version; 172 NewProjectWizardOperator wiz 173 = WizardUtils.createNewProject("Web", "Web Application"); 174 NewProjectNameLocationStepOperator nlsop 175 = WizardUtils.setProjectNameLocation(projectName, 176 projectLocation); 177 JComboBoxOperator cbop = new JComboBoxOperator(nlsop, "BluePrints"); 178 cbop.setSelectedIndex(1); WizardUtils.setJ2eeSpecVersion(nlsop, WizardUtils.MODULE_WAR, version); 180 wiz.finish(); 181 Thread.sleep(1000); 182 checkProjectStructure(WEB_JAKARTA); 183 checkProjectNodes(); 184 } 185 186 190 public void testDefaultNewJ2eeAppWizard() throws Exception { 191 projectLocation = getWorkDir().getAbsolutePath(); 192 projectName = "def EAR app" + version; 193 NewProjectWizardOperator wiz 194 = WizardUtils.createNewProject("Enterprise", "Enterprise Application"); 195 NewProjectNameLocationStepOperator op 196 = WizardUtils.setProjectNameLocation(projectName, 197 projectLocation); 198 WizardUtils.setJ2eeSpecVersion(op, WizardUtils.MODULE_EAR, version); 199 wiz.finish(); 200 checkProjectStructure(J2EE_DEFAULT); 201 Node root = checkProjectNodes(); 202 Node modules = new Node(root, "Java EE Modules"); 203 modules.expand(); 204 String [] s = modules.getChildren(); 205 assertEquals("Expected: \"def_EAR_app" + version + "-ejb.jar\", was: \"" + s[1] 206 + "\"", "def_EAR_app" + version + "-ejb.jar", s[1]); 207 assertEquals("Expected: \"def_EAR_app" + version + "-war.war\", was: \"" + s[0] 208 + "\"", "def_EAR_app" + version + "-war.war", s[0]); 209 } 210 211 private void checkProjectStructure(int prjType) { 212 RequiredFiles r = null; 213 switch (prjType) { 214 case EJB: 215 r = readRF("structures/ejbProject.str"); 216 break; 217 case WEB: 218 r = readRF("structures/webProject.str"); 219 break; 220 case WEB_JAKARTA: 221 r = readRF("structures/webProjectJakarta.str"); 222 break; 223 case J2EE_DEFAULT: 224 r = readRF("structures/defEAR.str"); 225 break; 226 case APP_CLIENT_DEFAULT: 227 r = readRF("structures/carProject.str"); 228 break; 229 default: 230 throw new IllegalArgumentException (); 231 } 232 try { 233 Thread.currentThread().sleep(5000); 234 } catch (InterruptedException ex) { 235 } 237 Set l = J2eeProjectSupport.getFileSet(projectLocation + File.separatorChar + projectName); 238 Set rf = r.getRequiredFiles(); 239 reporter.ref("Project: " + projectLocation); 240 reporter.ref("Expected: " + rf); 241 reporter.ref("Real: " + l); 242 if ((EJB == prjType) && ("5".equals(version))) { 243 Set result = getDifference(l, rf); 244 if (!result.remove("src" + File.separator + "conf" + File.separator + "ejb-jar.xml")) { 245 fail("Files: " + result + " are missing in project at: " + projectLocation); 246 } 247 } else { 248 assertTrue("Files: " + getDifference(l, rf) + " are missing in project at: " + projectLocation , l.containsAll(rf)); 249 } 250 rf = r.getRequiredFiles(); 251 reporter.ref("Project: " + projectLocation); 252 reporter.ref("Expected: " + rf); 253 reporter.ref("Real: " + l); 254 Set s = getDifference(rf, l); 255 assertTrue("Files: " + s + " are new in project: " + projectLocation , s.isEmpty()); 256 } 257 258 public void closeProjects() { 259 ProjectsTabOperator pto = new ProjectsTabOperator(); 260 pto.getProjectRootNode("def EJB Mod").performPopupAction("Close Project"); 261 pto.getProjectRootNode("BadModule").performPopupAction("Close Project"); 262 pto.getProjectRootNode("def EAR app").performPopupAction("Close Project"); 263 pto.getProjectRootNode("def Web app").performPopupAction("Close Project"); 264 new EventTool().waitNoEvent(2500); 267 } 268 269 private RequiredFiles readRF(String fileName) { 270 RequiredFiles rf = null; 271 try { 272 rf = new RequiredFiles(new File (getDataDir(), fileName)); 273 } catch (IOException ioe) { 274 ioe.printStackTrace(reporter.getLogStream()); 275 } 276 assertNotNull(rf); 277 return rf; 278 } 279 280 private Set getDifference(Set s1, Set s2) { 281 Set result = new HashSet (); 282 s2.removeAll(s1); 283 for (Iterator i = s2.iterator(); i.hasNext();) { 284 String s = (String ) i.next(); 285 if (s.indexOf(".LCK") < 0) { 286 result.add(s); 287 } else { 288 reporter.log("Additional file: " + s); 289 } 290 } 291 return result; 292 } 293 294 private Node checkProjectNodes() { 295 Node node = new ProjectsTabOperator().getProjectRootNode(projectName); 296 try { 297 Thread.sleep(1500); 298 } catch (InterruptedException ie) { 299 } 301 assertTrue("Project " + projectName + " is not expanded", node.isExpanded()); 302 return node; 303 } 304 } 305 | Popular Tags |