Changeset 1834
- Timestamp:
- 11/11/13 01:14:18 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewPackageWizard.java
r720 r1834 2 2 * This file is part of Modelica Development Tooling. 3 3 * 4 * Copyright (c) 2005, Link �pings universitet, Department of4 * Copyright (c) 2005, Linköpings universitet, Department of 5 5 * Computer and Information Science, PELAB 6 6 * … … 23 23 * distribution. 24 24 * 25 * * Neither the name of Link �pings universitet nor the names of its25 * * Neither the name of Link�pings universitet nor the names of its 26 26 * contributors may be used to endorse or promote products derived from 27 27 * this software without specific prior written permission. … … 42 42 package org.modelica.mdt.test; 43 43 44 import static org.junit.Assert.assertEquals; 45 import static org.junit.Assert.assertFalse; 46 import static org.junit.Assert.assertNotNull; 47 import static org.junit.Assert.assertTrue; 48 44 49 import org.eclipse.core.resources.IFile; 45 50 import org.eclipse.core.resources.IFolder; 46 51 import org.eclipse.core.resources.IProject; 52 import org.eclipse.core.resources.IWorkspace; 53 import org.eclipse.core.resources.IWorkspaceRoot; 47 54 import org.eclipse.core.resources.ResourcesPlugin; 55 import org.eclipse.core.runtime.CoreException; 48 56 import org.eclipse.jface.viewers.StructuredSelection; 49 57 import org.eclipse.jface.wizard.IWizard; 50 58 import org.eclipse.swt.widgets.Button; 51 59 import org.eclipse.swt.widgets.Text; 60 import org.junit.BeforeClass; 61 import org.junit.Test; 52 62 import org.modelica.mdt.core.IModelicaProject; 53 63 import org.modelica.mdt.core.ModelicaCore; … … 59 69 import abbot.tester.swt.TextTester; 60 70 61 import junit.framework.Assert; 62 import junit.framework.TestCase; 63 64 /** 65 * @author Elmir Jagudin 66 */ 67 68 public class TestNewPackageWizard extends TestCase 69 { 70 private static final String PROJECT_NAME_1 = 71 TestNewPackageWizard.class.getName() + "1"; 72 73 private TextTester ttester; 74 private ButtonTester btester; 75 71 public class TestNewPackageWizard { 72 private static final String PROJECT_NAME_1 = TestNewPackageWizard.class.getName() + "1"; 73 74 private static TextTester ttester; 75 private static ButtonTester btester; 76 76 77 private Text packageName; 77 78 private Text parentPackage; … … 80 81 private Button isEncapsulated; 81 82 private Button finish; 82 83 private IProject project; 84 private StructuredSelection fileDestination; 85 86 @Override 87 protected void setUp() throws Exception 88 { 89 /* 90 * setup project 91 */ 92 project = 93 ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME_1); 94 95 /* create project only if it does not exist yet */ 96 if (!project.exists()) 97 { 98 IModelicaProject mproj = 99 ModelicaCore.getModelicaRoot().createProject(project);//PROJECT_NAME_1); 100 Assert.assertNotNull("failed to create project", mproj); 101 83 84 private static IProject project; 85 private static StructuredSelection fileDestination; 86 87 @BeforeClass 88 public static void setUp() throws CoreException { 89 IWorkspace workspace = ResourcesPlugin.getWorkspace(); 90 IWorkspaceRoot workspaceRoot = workspace.getRoot(); 91 project = workspaceRoot.getProject(PROJECT_NAME_1); 92 93 if (!project.exists()) { 94 IModelicaProject mproj = ModelicaCore.getModelicaRoot().createProject(project); 95 assertNotNull("failed to create project", mproj); 96 102 97 project = mproj.getWrappedProject(); 103 98 } 104 99 105 /* 106 * create the selection that points at the root of the created project 107 */ 100 // create the selection that points at the root of the created project 108 101 fileDestination = new StructuredSelection(project); 109 110 /* 111 * setup testing support objects 112 */ 102 103 // setup testing support objects 113 104 ttester = TextTester.getTextTester(); 114 105 btester = ButtonTester.getButtonTester(); 115 116 } 117 118 public void openWizardAndFetchWidgets() 119 { 120 /* 121 * pop-up the wizard 122 */ 123 IWizard wizard = 124 Utility.openWizard("org.modelica.mdt.NewPackageWizard", 125 fileDestination); 106 } 107 108 private void openWizardAndFetchWidgets() { 109 // pop-up the wizard 110 IWizard wizard = Utility.openWizard("org.modelica.mdt.NewPackageWizard", fileDestination); 126 111 assertFalse(wizard.canFinish()); 127 112 128 129 130 /* fetch widgets */ 131 packageName = 132 TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG); 133 parentPackage = 134 TextTester.getInstrumentedText(NewTypePage.PARENT_PACKAGE_TAG); 135 packageDesc = 136 TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG); 137 sourceFolder = 138 TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG); 139 isEncapsulated = 140 ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG); 141 finish = 142 Utility.findButtonByText("&Finish"); 143 144 145 /* make some checks on the state of the wizards */ 146 assertEquals("Wrong source folder selected", 147 sourceFolder.getText(), PROJECT_NAME_1); 148 assertEquals("Junk present in package name field", 149 packageName.getText(), ""); 150 assertFalse("is encapsulated unexpectedly selected", 151 isEncapsulated.getSelection()); 152 assertFalse("Finish button not disabled", 153 finish.getEnabled()); 154 155 113 // fetch widgets 114 packageName = TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG); 115 parentPackage = TextTester.getInstrumentedText(NewTypePage.PARENT_PACKAGE_TAG); 116 packageDesc = TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG); 117 sourceFolder = TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG); 118 isEncapsulated = ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG); 119 finish = Utility.findButtonByText("&Finish"); 120 121 // make some checks on the state of the wizards 122 assertEquals("Wrong source folder selected", sourceFolder.getText(), PROJECT_NAME_1); 123 assertEquals("Junk present in package name field", packageName.getText(), ""); 124 assertFalse("is encapsulated unexpectedly selected", isEncapsulated.getSelection()); 125 assertFalse("Finish button not disabled", finish.getEnabled()); 156 126 } 157 127 … … 159 129 * create a plain package 160 130 */ 161 public void testCreatePackge()162 {163 openWizardAndFetchWidgets(); 164 131 @Test 132 public void testCreatePackage() { 133 openWizardAndFetchWidgets(); 134 165 135 String name = "pkg1"; 166 167 /* 168 * fill in the wizard fields 169 */ 136 137 // fill in the wizard fields 170 138 ttester.actionEnterText(packageName, name); 171 139 172 /* wait for the name change to propogate to enable the finish button */ 173 while (!finish.getEnabled()) { Utility.sleep(this, 100); } 174 btester.actionClick(finish); 175 176 /* check if the package folder was created */ 140 // wait for the name change to propagate to enable the finish button 141 while (!finish.getEnabled()) { 142 Utility.sleep(this, 100); 143 } 144 btester.actionClick(finish); 145 146 // check if the package folder was created 177 147 IFolder folder = project.getFolder(name); 178 148 assertTrue("no package folder was created", folder.exists()); 179 149 180 /* 181 * check that the generated package.mo exists and is sane 182 */ 150 // check that the generated package.mo exists and is sane 183 151 IFile packageMo = folder.getFile("package.mo"); 184 152 assertTrue("package.mo was not created", packageMo.exists()); 185 186 boolean same = 187 Utility.compareContent(packageMo, 188 "package " + name + "\n"+ 189 "\n"+ 190 "end " + name + ";"); 153 154 String expectedContent = String.format("package %s\n\nend %s;", name, name); 155 boolean same = Utility.compareContent(packageMo, expectedContent); 191 156 assertTrue("unexpected conted created in the package.mo", same); 192 193 //TODO fix the bug that causes this test below to fail and expand 194 // testCreatePackageWithDesc(), testEncapsulatedCreatePackage() and 195 // testEncapsulatedCreatePackageWithDesc() tests with creating a subpackage 196 // after the main package is created 197 /* 198 * test to create a nested package inside pkg1 199 */ 200 201 openWizardAndFetchWidgets(); 202 157 158 // test to create a nested package inside pkg1 159 openWizardAndFetchWidgets(); 160 203 161 String subName = "sub_pkg1"; 204 205 /* 206 * fill in the wizard fields 207 */ 162 163 // fill in the wizard fields 208 164 ttester.actionEnterText(packageName, subName); 209 165 ttester.actionEnterText(parentPackage, name); 210 166 211 /* 212 * wait tops 5 seconds for the name change to propogate 213 * to enable the finish button 214 */ 167 // wait tops 5 seconds for the name change to propagate 168 // to enable the finish button 215 169 long waitUntil = System.currentTimeMillis() + 5000; 216 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) 217 { 170 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) { 218 171 Utility.sleep(this, 95); 219 172 } 220 173 btester.actionClick(finish); 221 174 222 / * check if the package folder was created */175 // check if the package folder was created 223 176 folder = folder.getFolder(subName); 224 177 assertTrue("no package folder was created", folder.exists()); 225 178 226 /* 227 * check that the generated package.mo exists and is sane 228 */ 179 // check that the generated package.mo exists and is sane 229 180 packageMo = folder.getFile("package.mo"); 230 181 assertTrue("package.mo was not created", packageMo.exists()); 231 232 same = 233 Utility.compareContent(packageMo, 234 "within " + name + ";\n" + 235 "\n" + 236 "package " + subName + "\n" + 237 "\n"+ 238 "end " + subName + ";"); 239 assertTrue("unexpected conted created in the package.mo", same); 240 241 } 242 182 183 String expectedContentSub = String.format("within %s;\n\npackage %s\n\nend %s;", 184 name, subName, subName); 185 boolean sameSub = Utility.compareContent(packageMo, expectedContentSub); 186 assertTrue("unexpected conted created in the package.mo", sameSub); 187 } 188 243 189 /** 244 190 * create a plain package with description 245 191 */ 246 public void testCreatePackgeWithDesc()247 {248 openWizardAndFetchWidgets(); 249 192 @Test 193 public void testCreatePackgeWithDesc() { 194 openWizardAndFetchWidgets(); 195 250 196 String name = "pkg2"; 251 197 String description = "jolly good package"; 252 253 /* 254 * fill in the wizard fields 255 */ 198 199 // fill in the wizard fields 256 200 ttester.actionEnterText(packageName, name); 257 201 ttester.actionEnterText(packageDesc, description); 258 259 260 /* wait for the name change to propogate to enable the finish button */ 261 while (!finish.getEnabled()) { Utility.sleep(this, 100); } 262 btester.actionClick(finish); 263 264 /* check if the package folder was created */ 202 203 // wait for the name change to propagate to enable the finish button 204 while (!finish.getEnabled()) { 205 Utility.sleep(this, 100); 206 } 207 btester.actionClick(finish); 208 209 // check if the package folder was created 265 210 IFolder folder = project.getFolder(name); 266 211 assertTrue("no package folder was created", folder.exists()); 267 212 268 /* 269 * check that the generated package.mo exists and is sane 270 */ 213 // check that the generated package.mo exists and is sane 271 214 IFile packageMo = folder.getFile("package.mo"); 272 215 assertTrue("package.mo was not created", packageMo.exists()); 273 274 boolean same = 275 Utility.compareContent(packageMo, 276 "package " + name + " \"" + description + "\"" + "\n"+ 277 "\n"+ 278 "end " + name + ";"); 216 217 String expectedContent = String.format("package %s \"%s\"\n\nend %s;", name, description, name); 218 boolean same = Utility.compareContent(packageMo, expectedContent); 279 219 assertTrue("unexpected conted created in the package.mo", same); 280 281 /* 282 * test to create a nested package inside pkg2 283 */ 284 285 openWizardAndFetchWidgets(); 286 220 221 // test to create a nested package inside pkg2 222 openWizardAndFetchWidgets(); 223 287 224 String subName = "sub_pkg2"; 288 225 description = "a jolly good subpackage"; 289 290 /* 291 * fill in the wizard fields 292 */ 226 227 // fill in the wizard fields 293 228 ttester.actionEnterText(packageName, subName); 294 229 ttester.actionEnterText(parentPackage, name); 295 230 ttester.actionEnterText(packageDesc, description); 296 231 297 /* 298 * wait tops 5 seconds for the name change to propogate 299 * to enable the finish button 300 */ 232 // wait tops 5 seconds for the name change to propagate 233 // to enable the finish button 301 234 long waitUntil = System.currentTimeMillis() + 5000; 302 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) 303 { 235 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) { 304 236 Utility.sleep(this, 95); 305 237 } 306 238 btester.actionClick(finish); 307 239 308 / * check if the package folder was created */240 // check if the package folder was created 309 241 folder = folder.getFolder(subName); 310 242 assertTrue("no package folder was created", folder.exists()); 311 243 312 /* 313 * check that the generated package.mo exists and is sane 314 */ 244 // check that the generated package.mo exists and is sane 315 245 packageMo = folder.getFile("package.mo"); 316 246 assertTrue("package.mo was not created", packageMo.exists()); 317 318 same = 319 Utility.compareContent(packageMo, 320 "within " + name + ";\n" + 321 "\n" + 322 "package " + subName + " \"" + description + "\"" + "\n" + 323 "\n"+ 324 "end " + subName + ";"); 325 assertTrue("unexpected conted created in the package.mo", same); 326 } 327 247 248 String expectedContentSub = String.format("within %s;\n\npackage %s \"%s\"\n\nend %s;", 249 name, subName, description, subName); 250 boolean sameSub = Utility.compareContent(packageMo, expectedContentSub); 251 assertTrue("unexpected conted created in the package.mo", sameSub); 252 } 253 328 254 /** 329 255 * create a encapsulated package 330 256 */ 331 public void testEncapsulatedCreatePackge()332 {333 openWizardAndFetchWidgets(); 334 257 @Test 258 public void testEncapsulatedCreatePackge() { 259 openWizardAndFetchWidgets(); 260 335 261 String name = "pkg3"; 336 337 /* 338 * fill in the wizard fields 339 */ 262 263 // fill in the wizard fields 340 264 ttester.actionEnterText(packageName, name); 341 265 btester.actionClick(isEncapsulated); 342 266 343 /* wait for the name change to propogate to enable the finish button */ 344 while (!finish.getEnabled()) { Utility.sleep(this, 100); } 345 btester.actionClick(finish); 346 347 /* check if the package folder was created */ 267 // wait for the name change to propagate to enable the finish button 268 while (!finish.getEnabled()) { 269 Utility.sleep(this, 100); 270 } 271 btester.actionClick(finish); 272 273 // check if the package folder was created 348 274 IFolder folder = project.getFolder(name); 349 275 assertTrue("no package folder was created", folder.exists()); 350 276 351 /* 352 * check that the generated package.mo exists and is sane 353 */ 277 // check that the generated package.mo exists and is sane 354 278 IFile packageMo = folder.getFile("package.mo"); 355 279 assertTrue("package.mo was not created", packageMo.exists()); 356 357 boolean same = 358 Utility.compareContent(packageMo, 359 "encapsulated package " + name + "\n"+ 360 "\n"+ 361 "end " + name + ";"); 280 281 String expectedContent = String.format("encapsulated package %s\n\nend %s;", name, name); 282 boolean same = Utility.compareContent(packageMo, expectedContent); 362 283 assertTrue("unexpected conted created in the package.mo", same); 363 364 /* 365 * test to create a nested package inside pkg3 366 */ 367 368 openWizardAndFetchWidgets(); 369 284 285 // test to create a nested package inside pkg3 286 openWizardAndFetchWidgets(); 287 370 288 String subName = "sub_pkg3"; 371 372 /* 373 * fill in the wizard fields 374 */ 289 290 // fill in the wizard fields 375 291 ttester.actionEnterText(packageName, subName); 376 292 ttester.actionEnterText(parentPackage, name); 377 293 btester.actionClick(isEncapsulated); 378 294 379 /* 380 * wait tops 5 seconds for the name change to propogate 381 * to enable the finish button 382 */ 295 // wait tops 5 seconds for the name change to propagate 296 // to enable the finish button 383 297 long waitUntil = System.currentTimeMillis() + 5000; 384 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) 385 { 298 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) { 386 299 Utility.sleep(this, 95); 387 300 } 388 301 btester.actionClick(finish); 389 302 390 / * check if the package folder was created */303 // check if the package folder was created 391 304 folder = folder.getFolder(subName); 392 305 assertTrue("no package folder was created", folder.exists()); 393 306 394 /* 395 * check that the generated package.mo exists and is sane 396 */ 307 // check that the generated package.mo exists and is sane 397 308 packageMo = folder.getFile("package.mo"); 398 309 assertTrue("package.mo was not created", packageMo.exists()); 399 400 same = 401 Utility.compareContent(packageMo, 402 "within " + name + ";\n" + 403 "\n" + 404 "encapsulated package " + subName + "\n" + 405 "\n"+ 406 "end " + subName + ";"); 407 assertTrue("unexpected conted created in the package.mo", same); 408 } 409 310 311 String expectedContentSub = String.format("within %s;\n\nencapsulated package %s\n\nend %s;", 312 name, subName, subName); 313 boolean sameSub = Utility.compareContent(packageMo, expectedContentSub); 314 assertTrue("unexpected conted created in the package.mo", sameSub); 315 } 316 410 317 /** 411 318 * create a encapsulated package with description 412 319 */ 413 public void testEncapsulatedCreatePackgeWithDesc()414 {415 openWizardAndFetchWidgets(); 416 320 @Test 321 public void testEncapsulatedCreatePackgeWithDesc() { 322 openWizardAndFetchWidgets(); 323 417 324 String name = "pkg4"; 418 325 String description = "lebensmittelverpackung mit butter"; 419 420 /* 421 * fill in the wizard fields 422 */ 326 327 // fill in the wizard fields 423 328 ttester.actionEnterText(packageName, name); 424 329 btester.actionClick(isEncapsulated); 425 330 ttester.actionEnterText(packageDesc, description); 426 427 428 /* wait for the name change to propogate to enable the finish button */ 429 while (!finish.getEnabled()) { Utility.sleep(this, 100); } 430 btester.actionClick(finish); 431 432 /* check if the package folder was created */ 331 332 // wait for the name change to propagate to enable the finish button 333 while (!finish.getEnabled()) { 334 Utility.sleep(this, 100); 335 } 336 btester.actionClick(finish); 337 338 // check if the package folder was created 433 339 IFolder folder = project.getFolder(name); 434 340 assertTrue("no package folder was created", folder.exists()); 435 341 436 /* 437 * check that the generated package.mo exists and is sane 438 */ 342 // check that the generated package.mo exists and is sane 439 343 IFile packageMo = folder.getFile("package.mo"); 440 344 assertTrue("package.mo was not created", packageMo.exists()); 441 442 boolean same = 443 Utility.compareContent(packageMo, 444 "encapsulated package " + name + " \"" + description + "\"" + "\n"+ 445 "\n"+ 446 "end " + name + ";"); 345 346 String expectedContent = String.format("encapsulated package %s \"%s\"\n\nend %s;", name, description, name); 347 boolean same = Utility.compareContent(packageMo, expectedContent); 447 348 assertTrue("unexpected conted created in the package.mo", same); 448 449 /* 450 * test to create a nested package inside pkg4 451 */ 452 453 openWizardAndFetchWidgets(); 454 349 350 // test to create a nested package inside pkg4 351 openWizardAndFetchWidgets(); 352 455 353 String subName = "sub_pkg4"; 456 354 description = "deutsche, jaaa"; 457 355 458 /* 459 * fill in the wizard fields 460 */ 356 // fill in the wizard fields 461 357 ttester.actionEnterText(packageName, subName); 462 358 ttester.actionEnterText(parentPackage, name); 463 359 ttester.actionEnterText(packageDesc, description); 464 360 btester.actionClick(isEncapsulated); 465 466 467 /* 468 * wait tops 5 seconds for the name change to propogate 469 * to enable the finish button 470 */ 361 362 // wait tops 5 seconds for the name change to propagate 363 // to enable the finish button 471 364 long waitUntil = System.currentTimeMillis() + 5000; 472 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) 473 { 365 while (!finish.getEnabled() && waitUntil > System.currentTimeMillis()) { 474 366 Utility.sleep(this, 95); 475 367 } 476 368 btester.actionClick(finish); 477 369 478 / * check if the package folder was created */370 // check if the package folder was created 479 371 folder = folder.getFolder(subName); 480 372 assertTrue("no package folder was created", folder.exists()); 481 373 482 /* 483 * check that the generated package.mo exists and is sane 484 */ 374 // check that the generated package.mo exists and is sane 485 375 packageMo = folder.getFile("package.mo"); 486 376 assertTrue("package.mo was not created", packageMo.exists()); 487 488 same = 489 Utility.compareContent(packageMo, 490 "within " + name + ";\n" + 491 "\n" + 492 "encapsulated package " + subName + " \"" + description + "\"" + "\n" + 493 "\n"+ 494 "end " + subName + ";"); 495 assertTrue("unexpected conted created in the package.mo", same); 496 377 378 String expectedContentSub = String.format("within %s;\n\nencapsulated package %s \"%s\"\n\nend %s;", 379 name, subName, description, subName); 380 boolean sameSub = Utility.compareContent(packageMo, expectedContentSub); 381 assertTrue("unexpected conted created in the package.mo", sameSub); 497 382 } 498 383 }
Note: See TracChangeset
for help on using the changeset viewer.