source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewProjectWizard.java @ 55

Last change on this file since 55 was 52, checked in by boris, 19 years ago
  • added tests on new project wizard
File size: 3.4 KB
Line 
1package org.modelica.mdt.test;
2
3import java.util.concurrent.Semaphore;
4
5import org.eclipse.core.resources.IProject;
6import org.eclipse.core.resources.ResourcesPlugin;
7import org.eclipse.core.runtime.CoreException;
8import org.eclipse.jface.viewers.StructuredSelection;
9import org.eclipse.jface.wizard.WizardDialog;
10import org.eclipse.swt.widgets.Display;
11import org.eclipse.swt.widgets.Text;
12import org.eclipse.ui.IWorkbench;
13import org.eclipse.ui.IWorkbenchWizard;
14import org.eclipse.ui.PlatformUI;
15import org.eclipse.ui.wizards.IWizardDescriptor;
16import org.modelica.mdt.NewProjectWizard;
17
18import abbot.tester.swt.TextTester;
19
20import junit.framework.TestCase;
21
22public class TestNewProjectWizard extends TestCase
23{
24    /* name of the project that test creates */
25    public static final String PROJECT_NAME = "test";
26   
27    public void testWizard()
28    {
29        /*
30         * init and display wizard
31         */
32        IWorkbench workbench = PlatformUI.getWorkbench();
33        IWizardDescriptor wizDesc = 
34            workbench.getNewWizardRegistry().findWizard("org.modelica.mdt.NewProjectWizard");       
35        assertNotNull("new project wizard not found", wizDesc);
36       
37        IWorkbenchWizard wizard = null;
38        try
39        {
40            wizard = wizDesc.createWizard();
41        }
42        catch (CoreException e)
43        {
44            fail("Could not create new project wizard, CoreException thrown\n" 
45                    + e.getMessage());
46        }
47        assertNotNull(wizard);
48       
49        wizard.init(workbench, StructuredSelection.EMPTY);
50        final WizardDialog dialog = 
51            new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
52        dialog.create();
53
54        openDialog(dialog);
55       
56        assertFalse(wizard.canFinish());
57
58        /* fetch project name text field */
59        Text name = TextTester.getInstrumentedText(NewProjectWizard.PROJECT_NAME_TAG);     
60        /* enter project name */
61        TextTester.getTextTester().actionEnterText(name, PROJECT_NAME);
62       
63        assertTrue(wizard.canFinish());
64
65        /* create project */
66        boolean finishRes = wizard.performFinish();
67        assertTrue("New wizard dialog failed to finish", finishRes);
68       
69        /* check that project was created */
70        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
71               
72        assertTrue("new wizard fail to create project", project.exists());
73        assertTrue("new wizard didnt open the created project", project.isOpen());
74       
75        /* check that it have modelica nature */
76        try         
77        {
78            assertTrue("modelica nature not added to the project", 
79                    project.hasNature("org.modelica.mdt.ModelicaNature"));
80            assertTrue("modelica nature was not enabled on the project", 
81                    project.isNatureEnabled("org.modelica.mdt.ModelicaNature"));
82
83        }
84        catch (CoreException e)
85        {
86            fail("CoreException thrown while probing for modelica nature " + e.getMessage());
87        }
88       
89       
90        /* clean up */
91        dialog.close();
92    }
93
94    /**
95     * opens (runs dialog.open() method ) a dialog in UI thread and waits until it
96     * is open before returning
97     *
98     * @param dialog the dialog to open, it is assumed that dialog is fully initialized
99     *
100     */
101    private void openDialog(final WizardDialog dialog)
102    {
103        final Semaphore sem = new Semaphore(0);
104       
105        dialog.getShell().getDisplay().syncExec(new Runnable()
106        {
107            public void run()
108            {
109                dialog.setBlockOnOpen(false);
110                dialog.open();
111                sem.release();
112            }
113        });
114       
115        try
116        {
117            sem.acquire();
118        } 
119        catch (InterruptedException e)
120        {
121            fail("interruped while waiting for dialog to open");
122        }
123    } 
124
125}
Note: See TracBrowser for help on using the repository browser.