Ignore:
Timestamp:
10/07/05 13:45:56 (19 years ago)
Author:
boris
Message:
  • changed new project wizard test to actually click on the finish button, not just invoke 'performFinish()'
Location:
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewProjectWizard.java

    r60 r62  
    4242package org.modelica.mdt.test;
    4343
    44 import java.util.concurrent.Semaphore;
    45 
    4644import org.eclipse.core.resources.IProject;
    4745import org.eclipse.core.resources.ResourcesPlugin;
    4846import org.eclipse.core.runtime.CoreException;
    49 import org.eclipse.jface.viewers.StructuredSelection;
    50 import org.eclipse.jface.wizard.WizardDialog;
     47import org.eclipse.swt.widgets.Button;
    5148import org.eclipse.swt.widgets.Text;
    52 import org.eclipse.ui.IWorkbench;
    5349import org.eclipse.ui.IWorkbenchWizard;
    5450import org.eclipse.ui.PlatformUI;
    55 import org.eclipse.ui.wizards.IWizardDescriptor;
    5651import org.modelica.mdt.NewProjectWizard;
    5752
     53import abbot.finder.matchers.swt.TextMatcher;
     54import abbot.finder.swt.BasicFinder;
     55import abbot.finder.swt.MultipleWidgetsFoundException;
     56import abbot.finder.swt.TestHierarchy;
     57import abbot.finder.swt.WidgetNotFoundException;
     58import abbot.tester.swt.ButtonTester;
    5859import abbot.tester.swt.TextTester;
    5960
     
    7071         * init and display wizard
    7172         */
    72         IWorkbench workbench = PlatformUI.getWorkbench();
    73         IWizardDescriptor wizDesc =
    74             workbench.getNewWizardRegistry().findWizard("org.modelica.mdt.NewProjectWizard");       
    75         assertNotNull("new project wizard not found", wizDesc);
    76        
    77         IWorkbenchWizard wizard = null;
    78         try
    79         {
    80             wizard = wizDesc.createWizard();
    81         }
    82         catch (CoreException e)
    83         {
    84             fail("Could not create new project wizard, CoreException thrown\n"
    85                     + e.getMessage());
    86         }
    87         assertNotNull(wizard);
    88        
    89         wizard.init(workbench, StructuredSelection.EMPTY);
    90         final WizardDialog dialog =
    91             new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
    92         dialog.create();
    93 
    94         openDialog(dialog);
    95        
     73        IWorkbenchWizard wizard = Utility.openWizard("org.modelica.mdt.NewProjectWizard");
    9674        assertFalse(wizard.canFinish());
    9775
     
    10381        assertTrue(wizard.canFinish());
    10482
    105         /* create project */
    106         boolean finishRes = wizard.performFinish();
    107         assertTrue("New wizard dialog failed to finish", finishRes);
     83        /*
     84         * create project
     85         */
     86        BasicFinder finder =  /* find finish button */
     87            new BasicFinder(new TestHierarchy(PlatformUI.getWorkbench().getDisplay()));
     88
     89        Button finish = null;
     90        try
     91        {
     92            finish = (Button) finder.find(new TextMatcher("&Finish"));
     93        }
     94        catch (WidgetNotFoundException e)
     95        {
     96            fail("Finish button not found.");
     97        }
     98        catch (MultipleWidgetsFoundException e)
     99        {
     100            fail("Multiple finish buttons found.");
     101        }
     102       
     103        /* create project by clicking finish button */
     104        while (!finish.getEnabled())
     105        {
     106            /* wait for the name changed to propogate to enable the finish button */
     107        }       
     108        ButtonTester.getButtonTester().actionClick(finish);
     109       
    108110       
    109111        /* check that project was created */
    110112        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
    111113               
    112         assertTrue("new wizard fail to create project", project.exists());
     114        assertTrue("new wizard failed to create project", project.exists());
    113115        assertTrue("new wizard didnt open the created project", project.isOpen());
    114116       
     
    126128            fail("CoreException thrown while probing for modelica nature " + e.getMessage());
    127129        }
    128        
    129        
    130         /* clean up */
    131         dialog.close();
     130
    132131    }
    133132
    134     /**
    135      * opens (runs dialog.open() method ) a dialog in UI thread and waits until it
    136      * is open before returning
    137      *
    138      * @param dialog the dialog to open, it is assumed that dialog is fully initialized
    139      *
    140      */
    141     private void openDialog(final WizardDialog dialog)
    142     {
    143         final Semaphore sem = new Semaphore(0);
    144        
    145         dialog.getShell().getDisplay().syncExec(new Runnable()
    146         {
    147             public void run()
    148             {
    149                 dialog.setBlockOnOpen(false);
    150                 dialog.open();
    151                 sem.release();
    152             }
    153         });
    154        
    155         try
    156         {
    157             sem.acquire();
    158         }
    159         catch (InterruptedException e)
    160         {
    161             fail("interruped while waiting for dialog to open");
    162         }
    163     }
    164 
    165133}
Note: See TracChangeset for help on using the changeset viewer.