source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestNewPackageWizard.java @ 288

Last change on this file since 288 was 288, checked in by boris, 19 years ago
  • added a 'parent package' field to new package dialog and implemented infrastructure to be animate it among others:
  • IModelicaProject.getPackageRoots() method to fetch all top level package in a project
  • IModelicaProject.getPackage() method to fetch a package by its full name
  • IModelicaProject.findElement() method to fetch project's elements by path
  • modelica source files are now wraped by IModelicaSourceFile
  • plain files are now wraped by IModelicaFile inside a modelica project
  • an abstract wizard page superclass NewTypePage? added wich implemets source and parent package fields which are used in createing new classes/packages
  • some other stuff i forgot about, this kinda got out of hand, smaller commits in the future !
File size: 8.9 KB
Line 
1/*
2 * This file is part of Modelica Development Tooling.
3 *
4 * Copyright (c) 2005, Link�pings universitet, Department of
5 * Computer and Information Science, PELAB
6 *
7 * All rights reserved.
8 *
9 * (The new BSD license, see also
10 * http://www.opensource.org/licenses/bsd-license.php)
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 *   notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 *   notice, this list of conditions and the following disclaimer in
22 *   the documentation and/or other materials provided with the
23 *   distribution.
24 *
25 * * Neither the name of Link�pings universitet nor the names of its
26 *   contributors may be used to endorse or promote products derived from
27 *   this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42package org.modelica.mdt.test;
43
44import org.eclipse.core.resources.IFile;
45import org.eclipse.core.resources.IFolder;
46import org.eclipse.core.resources.IProject;
47import org.eclipse.core.resources.ResourcesPlugin;
48import org.eclipse.jface.viewers.StructuredSelection;
49import org.eclipse.jface.wizard.IWizard;
50import org.eclipse.swt.widgets.Button;
51import org.eclipse.swt.widgets.Text;
52import org.eclipse.ui.PlatformUI;
53import org.modelica.mdt.core.ModelicaCore;
54import org.modelica.mdt.test.util.Utility;
55import org.modelica.mdt.ui.wizards.NewPackageWizard;
56import org.modelica.mdt.ui.wizards.NewTypePage;
57
58import abbot.tester.swt.ButtonTester;
59import abbot.tester.swt.TextTester;
60
61import junit.framework.TestCase;
62
63/**
64 * @author Elmir Jagudin
65 */
66
67public class TestNewPackageWizard extends TestCase
68{
69    private static final String PROJECT_NAME_1 = 
70        TestNewPackageWizard.class.getName() + "1";
71
72    private TextTester ttester;
73    private ButtonTester btester;
74   
75    private Text packageName;
76    private Text packageDesc;
77    private Text sourceFolder;
78    private Button isEncapsulated;
79    private Button finish;
80   
81    private IProject project;
82    private StructuredSelection fileDestination; 
83
84    @Override
85    protected void setUp() throws Exception
86    {
87        /*
88         * setup project
89         */
90        project = 
91            ModelicaCore.createProject(PROJECT_NAME_1,
92                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
93        assertNotNull("failed to create project", project);
94       
95        /*
96         * create the selection that points at the root of the created project
97         */
98        fileDestination = 
99            new StructuredSelection(ResourcesPlugin.getWorkspace().getRoot().
100                    getProject(PROJECT_NAME_1));       
101        /*
102         * setup testing support objects
103         */
104        ttester = TextTester.getTextTester();
105        btester = ButtonTester.getButtonTester();
106
107    }
108   
109    public void openWizardAndFetchWidgets()
110    {
111        /*
112         * pop-up the wizard
113         */
114        IWizard wizard = 
115            Utility.openWizard("org.modelica.mdt.NewPackageWizard",
116                    fileDestination);       
117        assertFalse(wizard.canFinish());
118
119       
120       
121        /* fetch widgets */
122        packageName = 
123            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG);
124        packageDesc = 
125            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG);
126        sourceFolder = 
127            TextTester.getInstrumentedText(NewTypePage.SOURCE_FOLDER_TAG);
128        isEncapsulated = 
129            ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG);
130        finish = 
131            Utility.findButtonByText("&Finish");
132
133       
134        /* make some checks on the state of the wizards */
135        assertEquals("Wrong source folder selected", 
136                sourceFolder.getText(), PROJECT_NAME_1);       
137        assertEquals("Junk present in package name field", 
138                packageName.getText(), "");
139        assertFalse("is encapsulated unexpectedly selected",
140                isEncapsulated.getSelection());
141        assertFalse("Finish button not disabled", 
142                finish.getEnabled());
143       
144
145    }
146
147    /**
148     * create a plain package
149     */
150    public void testCreatePackge()
151    {
152        openWizardAndFetchWidgets();
153       
154        String name = "pkg1";
155       
156        /*
157         * fill in the wizard fields
158         */
159        ttester.actionEnterText(packageName, name);
160
161        /* wait for the name change to propogate to enable the finish button */
162        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
163        btester.actionClick(finish);
164
165        /* check if the package folder was created */
166        IFolder folder = project.getFolder(name);
167        assertTrue("no package folder was created", folder.exists());
168
169        /*
170         * check that the generated package.mo exists and is sane
171         */
172        IFile packageMo = folder.getFile("package.mo");
173        assertTrue("package.mo was not created", packageMo.exists());
174       
175        boolean same = 
176            Utility.compareContent(packageMo, 
177                "package " + name + "\n"+
178                "\n"+
179                "end " + name + ";");
180        assertTrue("unexpected conted created in the package.mo", same);
181    }
182   
183    /**
184     * create a plain package with description
185     */
186    public void testCreatePackgeWithDesc()
187    {
188        openWizardAndFetchWidgets();
189       
190        String name = "pkg2";
191        String description = "jolly good package";
192       
193        /*
194         * fill in the wizard fields
195         */
196        ttester.actionEnterText(packageName, name);
197        ttester.actionEnterText(packageDesc, description);
198   
199
200        /* wait for the name change to propogate to enable the finish button */
201        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
202        btester.actionClick(finish);
203
204        /* check if the package folder was created */
205        IFolder folder = project.getFolder(name);
206        assertTrue("no package folder was created", folder.exists());
207
208        /*
209         * check that the generated package.mo exists and is sane
210         */
211        IFile packageMo = folder.getFile("package.mo");
212        assertTrue("package.mo was not created", packageMo.exists());
213       
214        boolean same = 
215            Utility.compareContent(packageMo, 
216                "package " + name + " \"" + description + "\"" + "\n"+
217                "\n"+
218                "end " + name + ";");
219        assertTrue("unexpected conted created in the package.mo", same);
220    }
221   
222    /**
223     * create a encapsulated package
224     */
225    public void testEncapsulatedCreatePackge()
226    {
227        openWizardAndFetchWidgets();
228       
229        String name = "pkg3";
230       
231        /*
232         * fill in the wizard fields
233         */
234        ttester.actionEnterText(packageName, name);
235        btester.actionClick(isEncapsulated);
236
237        /* wait for the name change to propogate to enable the finish button */
238        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
239        btester.actionClick(finish);
240
241        /* check if the package folder was created */
242        IFolder folder = project.getFolder(name);
243        assertTrue("no package folder was created", folder.exists());
244
245        /*
246         * check that the generated package.mo exists and is sane
247         */
248        IFile packageMo = folder.getFile("package.mo");
249        assertTrue("package.mo was not created", packageMo.exists());
250       
251        boolean same = 
252            Utility.compareContent(packageMo, 
253                "encapsulated package " + name + "\n"+
254                "\n"+
255                "end " + name + ";");
256        assertTrue("unexpected conted created in the package.mo", same);
257       
258    }
259   
260    /**
261     * create a encapsulated package with description
262     */
263    public void testEncapsulatedCreatePackgeWithDesc()
264    {
265        openWizardAndFetchWidgets();
266       
267        String name = "pkg4";
268        String description = "lebensmittelverpackung mit butter";
269       
270        /*
271         * fill in the wizard fields
272         */
273        ttester.actionEnterText(packageName, name);
274        btester.actionClick(isEncapsulated);
275        ttester.actionEnterText(packageDesc, description);
276   
277
278        /* wait for the name change to propogate to enable the finish button */
279        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
280        btester.actionClick(finish);
281
282        /* check if the package folder was created */
283        IFolder folder = project.getFolder(name);
284        assertTrue("no package folder was created", folder.exists());
285
286        /*
287         * check that the generated package.mo exists and is sane
288         */
289        IFile packageMo = folder.getFile("package.mo");
290        assertTrue("package.mo was not created", packageMo.exists());
291       
292        boolean same = 
293            Utility.compareContent(packageMo, 
294                "encapsulated package " + name + " \"" + description + "\"" + "\n"+
295                "\n"+
296                "end " + name + ";");
297        assertTrue("unexpected conted created in the package.mo", same);
298       
299    }
300}
Note: See TracBrowser for help on using the repository browser.