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

Last change on this file since 126 was 126, checked in by boris, 19 years ago
  • new package wizard finished
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;
56
57import abbot.tester.swt.ButtonTester;
58import abbot.tester.swt.TextTester;
59
60import junit.framework.TestCase;
61
62/**
63 * @author Elmir Jagudin
64 */
65
66public class TestNewPackageWizard extends TestCase
67{
68    private static final String PROJECT_NAME_1 = 
69        TestNewPackageWizard.class.getName() + "1";
70
71    private TextTester ttester;
72    private ButtonTester btester;
73   
74    private Text packageName;
75    private Text packageDesc;
76    private Text sourceFolder;
77    private Button isEncapsulated;
78    private Button finish;
79   
80    private IProject project;
81    private StructuredSelection fileDestination; 
82
83//  @Override
84//  protected void setUp() throws Exception
85    // TODO change back to protected
86    public void setUp() throws Exception
87    {
88        /*
89         * setup project
90         */
91        project = 
92            ModelicaCore.createProject(PROJECT_NAME_1,
93                    PlatformUI.getWorkbench().getActiveWorkbenchWindow());
94        assertNotNull("failed to create project", project);
95       
96        /*
97         * create the selection that points at the root of the created project
98         */
99        fileDestination = 
100            new StructuredSelection(ResourcesPlugin.getWorkspace().getRoot().
101                    getProject(PROJECT_NAME_1));       
102        /*
103         * setup testing support objects
104         */
105        ttester = TextTester.getTextTester();
106        btester = ButtonTester.getButtonTester();
107
108    }
109   
110    public void openWizardAndFetchWidgets()
111    {
112        /*
113         * pop-up the wizard
114         */
115        IWizard wizard = 
116            Utility.openWizard("org.modelica.mdt.NewPackageWizard",
117                    fileDestination);       
118        assertFalse(wizard.canFinish());
119
120       
121       
122        /* fetch widgets */
123        packageName = 
124            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_NAME_TAG);
125        packageDesc = 
126            TextTester.getInstrumentedText(NewPackageWizard.PACKAGE_DESC_TAG);
127        sourceFolder = 
128            TextTester.getInstrumentedText(NewPackageWizard.SOURCE_FOLDER_TAG);
129        isEncapsulated = 
130            ButtonTester.getInstrumentedButton(NewPackageWizard.IS_ENCAPSULATED_TAG);
131        finish = 
132            Utility.findFinishButton();
133
134       
135        /* make some checks on the state of the wizards */
136        assertEquals("Wrong source folder selected", 
137                sourceFolder.getText(), PROJECT_NAME_1);       
138        assertEquals("Junk present in package name field", 
139                packageName.getText(), "");
140        assertFalse("is encapsulated unexpectedly selected",
141                isEncapsulated.getSelection());
142        assertFalse("Finish button not disabled", 
143                finish.getEnabled());
144       
145
146    }
147
148    /**
149     * create a plain package
150     */
151    public void testCreatePackge()
152    {
153        openWizardAndFetchWidgets();
154       
155        String name = "pkg1";
156       
157        /*
158         * fill in the wizard fields
159         */
160        ttester.actionEnterText(packageName, name);
161
162        /* wait for the name change to propogate to enable the finish button */
163        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
164        btester.actionClick(finish);
165
166        /* check if the package folder was created */
167        IFolder folder = project.getFolder(name);
168        assertTrue("no package folder was created", folder.exists());
169
170        /*
171         * check that the generated package.mo exists and is sane
172         */
173        IFile packageMo = folder.getFile("package.mo");
174        assertTrue("package.mo was not created", packageMo.exists());
175       
176        boolean same = 
177            Utility.compareContent(packageMo, 
178                "package " + name + "\n"+
179                "\n"+
180                "end " + name + ";");
181        assertTrue("unexpected conted created in the package.mo", same);
182    }
183   
184    /**
185     * create a plain package with description
186     */
187    public void testCreatePackgeWithDesc()
188    {
189        openWizardAndFetchWidgets();
190       
191        String name = "pkg2";
192        String description = "jolly good package";
193       
194        /*
195         * fill in the wizard fields
196         */
197        ttester.actionEnterText(packageName, name);
198        ttester.actionEnterText(packageDesc, description);
199   
200
201        /* wait for the name change to propogate to enable the finish button */
202        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
203        btester.actionClick(finish);
204
205        /* check if the package folder was created */
206        IFolder folder = project.getFolder(name);
207        assertTrue("no package folder was created", folder.exists());
208
209        /*
210         * check that the generated package.mo exists and is sane
211         */
212        IFile packageMo = folder.getFile("package.mo");
213        assertTrue("package.mo was not created", packageMo.exists());
214       
215        boolean same = 
216            Utility.compareContent(packageMo, 
217                "package " + name + " \"" + description + "\"" + "\n"+
218                "\n"+
219                "end " + name + ";");
220        assertTrue("unexpected conted created in the package.mo", same);
221    }
222   
223    /**
224     * create a encapsulated package
225     */
226    public void testEncapsulatedCreatePackge()
227    {
228        openWizardAndFetchWidgets();
229       
230        String name = "pkg3";
231       
232        /*
233         * fill in the wizard fields
234         */
235        ttester.actionEnterText(packageName, name);
236        btester.actionClick(isEncapsulated);
237
238        /* wait for the name change to propogate to enable the finish button */
239        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
240        btester.actionClick(finish);
241
242        /* check if the package folder was created */
243        IFolder folder = project.getFolder(name);
244        assertTrue("no package folder was created", folder.exists());
245
246        /*
247         * check that the generated package.mo exists and is sane
248         */
249        IFile packageMo = folder.getFile("package.mo");
250        assertTrue("package.mo was not created", packageMo.exists());
251       
252        boolean same = 
253            Utility.compareContent(packageMo, 
254                "encapsulated package " + name + "\n"+
255                "\n"+
256                "end " + name + ";");
257        assertTrue("unexpected conted created in the package.mo", same);
258       
259    }
260   
261    /**
262     * create a encapsulated package with description
263     */
264    public void testEncapsulatedCreatePackgeWithDesc()
265    {
266        openWizardAndFetchWidgets();
267       
268        String name = "pkg4";
269        String description = "lebensmittelverpackung mit butter";
270       
271        /*
272         * fill in the wizard fields
273         */
274        ttester.actionEnterText(packageName, name);
275        btester.actionClick(isEncapsulated);
276        ttester.actionEnterText(packageDesc, description);
277   
278
279        /* wait for the name change to propogate to enable the finish button */
280        while (!finish.getEnabled()) { Utility.sleep(this, 100); }
281        btester.actionClick(finish);
282
283        /* check if the package folder was created */
284        IFolder folder = project.getFolder(name);
285        assertTrue("no package folder was created", folder.exists());
286
287        /*
288         * check that the generated package.mo exists and is sane
289         */
290        IFile packageMo = folder.getFile("package.mo");
291        assertTrue("package.mo was not created", packageMo.exists());
292       
293        boolean same = 
294            Utility.compareContent(packageMo, 
295                "encapsulated package " + name + " \"" + description + "\"" + "\n"+
296                "\n"+
297                "end " + name + ";");
298        assertTrue("unexpected conted created in the package.mo", same);
299       
300    }
301}
Note: See TracBrowser for help on using the repository browser.