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 | |
---|
42 | package org.modelica.mdt.test; |
---|
43 | |
---|
44 | import org.eclipse.core.resources.IFile; |
---|
45 | import org.eclipse.core.resources.IFolder; |
---|
46 | import org.eclipse.core.resources.IProject; |
---|
47 | import org.eclipse.core.resources.ResourcesPlugin; |
---|
48 | import org.eclipse.jface.viewers.StructuredSelection; |
---|
49 | import org.eclipse.jface.wizard.IWizard; |
---|
50 | import org.eclipse.swt.widgets.Button; |
---|
51 | import org.eclipse.swt.widgets.Text; |
---|
52 | import org.modelica.mdt.core.IModelicaProject; |
---|
53 | import org.modelica.mdt.core.ModelicaCore; |
---|
54 | import org.modelica.mdt.test.util.Utility; |
---|
55 | import org.modelica.mdt.ui.wizards.NewPackageWizard; |
---|
56 | import org.modelica.mdt.ui.wizards.NewTypePage; |
---|
57 | |
---|
58 | import abbot.tester.swt.ButtonTester; |
---|
59 | import abbot.tester.swt.TextTester; |
---|
60 | |
---|
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 | |
---|
76 | private Text packageName; |
---|
77 | // private Text parentPackage; |
---|
78 | private Text packageDesc; |
---|
79 | private Text sourceFolder; |
---|
80 | private Button isEncapsulated; |
---|
81 | 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_NAME_1); |
---|
100 | Assert.assertNotNull("failed to create project", mproj); |
---|
101 | |
---|
102 | project = mproj.getProject(); |
---|
103 | } |
---|
104 | |
---|
105 | /* |
---|
106 | * create the selection that points at the root of the created project |
---|
107 | */ |
---|
108 | fileDestination = new StructuredSelection(project); |
---|
109 | |
---|
110 | /* |
---|
111 | * setup testing support objects |
---|
112 | */ |
---|
113 | ttester = TextTester.getTextTester(); |
---|
114 | 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); |
---|
126 | assertFalse(wizard.canFinish()); |
---|
127 | |
---|
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 | |
---|
156 | } |
---|
157 | |
---|
158 | /** |
---|
159 | * create a plain package |
---|
160 | */ |
---|
161 | public void testCreatePackge() |
---|
162 | { |
---|
163 | openWizardAndFetchWidgets(); |
---|
164 | |
---|
165 | String name = "pkg1"; |
---|
166 | |
---|
167 | /* |
---|
168 | * fill in the wizard fields |
---|
169 | */ |
---|
170 | ttester.actionEnterText(packageName, name); |
---|
171 | |
---|
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 */ |
---|
177 | IFolder folder = project.getFolder(name); |
---|
178 | assertTrue("no package folder was created", folder.exists()); |
---|
179 | |
---|
180 | /* |
---|
181 | * check that the generated package.mo exists and is sane |
---|
182 | */ |
---|
183 | IFile packageMo = folder.getFile("package.mo"); |
---|
184 | 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 + ";"); |
---|
191 | 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 | // |
---|
203 | // String subName = "sub_pkg1"; |
---|
204 | // |
---|
205 | // /* |
---|
206 | // * fill in the wizard fields |
---|
207 | // */ |
---|
208 | // ttester.actionEnterText(packageName, subName); |
---|
209 | // ttester.actionEnterText(parentPackage, name); |
---|
210 | // |
---|
211 | // /* wait for the name change to propogate to enable the finish button */ |
---|
212 | // while (!finish.getEnabled()) { Utility.sleep(this, 100); } |
---|
213 | // Utility.sleep(this, 10000); // TODO remove me |
---|
214 | // btester.actionClick(finish); |
---|
215 | // |
---|
216 | // /* check if the package folder was created */ |
---|
217 | // folder = folder.getFolder(subName); |
---|
218 | // assertTrue("no package folder was created", folder.exists()); |
---|
219 | // |
---|
220 | // /* |
---|
221 | // * check that the generated package.mo exists and is sane |
---|
222 | // */ |
---|
223 | // packageMo = folder.getFile("package.mo"); |
---|
224 | // assertTrue("package.mo was not created", packageMo.exists()); |
---|
225 | // |
---|
226 | // same = |
---|
227 | // Utility.compareContent(packageMo, |
---|
228 | // "within " + name + ";\n" + |
---|
229 | // "\n" + |
---|
230 | // "package " + subName + "\n" + |
---|
231 | // "\n"+ |
---|
232 | // "end " + name + ";"); |
---|
233 | // assertTrue("unexpected conted created in the package.mo", same); |
---|
234 | // |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * create a plain package with description |
---|
239 | */ |
---|
240 | public void testCreatePackgeWithDesc() |
---|
241 | { |
---|
242 | openWizardAndFetchWidgets(); |
---|
243 | |
---|
244 | String name = "pkg2"; |
---|
245 | String description = "jolly good package"; |
---|
246 | |
---|
247 | /* |
---|
248 | * fill in the wizard fields |
---|
249 | */ |
---|
250 | ttester.actionEnterText(packageName, name); |
---|
251 | ttester.actionEnterText(packageDesc, description); |
---|
252 | |
---|
253 | |
---|
254 | /* wait for the name change to propogate to enable the finish button */ |
---|
255 | while (!finish.getEnabled()) { Utility.sleep(this, 100); } |
---|
256 | btester.actionClick(finish); |
---|
257 | |
---|
258 | /* check if the package folder was created */ |
---|
259 | IFolder folder = project.getFolder(name); |
---|
260 | assertTrue("no package folder was created", folder.exists()); |
---|
261 | |
---|
262 | /* |
---|
263 | * check that the generated package.mo exists and is sane |
---|
264 | */ |
---|
265 | IFile packageMo = folder.getFile("package.mo"); |
---|
266 | assertTrue("package.mo was not created", packageMo.exists()); |
---|
267 | |
---|
268 | boolean same = |
---|
269 | Utility.compareContent(packageMo, |
---|
270 | "package " + name + " \"" + description + "\"" + "\n"+ |
---|
271 | "\n"+ |
---|
272 | "end " + name + ";"); |
---|
273 | assertTrue("unexpected conted created in the package.mo", same); |
---|
274 | } |
---|
275 | |
---|
276 | /** |
---|
277 | * create a encapsulated package |
---|
278 | */ |
---|
279 | public void testEncapsulatedCreatePackge() |
---|
280 | { |
---|
281 | openWizardAndFetchWidgets(); |
---|
282 | |
---|
283 | String name = "pkg3"; |
---|
284 | |
---|
285 | /* |
---|
286 | * fill in the wizard fields |
---|
287 | */ |
---|
288 | ttester.actionEnterText(packageName, name); |
---|
289 | btester.actionClick(isEncapsulated); |
---|
290 | |
---|
291 | /* wait for the name change to propogate to enable the finish button */ |
---|
292 | while (!finish.getEnabled()) { Utility.sleep(this, 100); } |
---|
293 | btester.actionClick(finish); |
---|
294 | |
---|
295 | /* check if the package folder was created */ |
---|
296 | IFolder folder = project.getFolder(name); |
---|
297 | assertTrue("no package folder was created", folder.exists()); |
---|
298 | |
---|
299 | /* |
---|
300 | * check that the generated package.mo exists and is sane |
---|
301 | */ |
---|
302 | IFile packageMo = folder.getFile("package.mo"); |
---|
303 | assertTrue("package.mo was not created", packageMo.exists()); |
---|
304 | |
---|
305 | boolean same = |
---|
306 | Utility.compareContent(packageMo, |
---|
307 | "encapsulated package " + name + "\n"+ |
---|
308 | "\n"+ |
---|
309 | "end " + name + ";"); |
---|
310 | assertTrue("unexpected conted created in the package.mo", same); |
---|
311 | |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * create a encapsulated package with description |
---|
316 | */ |
---|
317 | public void testEncapsulatedCreatePackgeWithDesc() |
---|
318 | { |
---|
319 | openWizardAndFetchWidgets(); |
---|
320 | |
---|
321 | String name = "pkg4"; |
---|
322 | String description = "lebensmittelverpackung mit butter"; |
---|
323 | |
---|
324 | /* |
---|
325 | * fill in the wizard fields |
---|
326 | */ |
---|
327 | ttester.actionEnterText(packageName, name); |
---|
328 | btester.actionClick(isEncapsulated); |
---|
329 | ttester.actionEnterText(packageDesc, description); |
---|
330 | |
---|
331 | |
---|
332 | /* wait for the name change to propogate to enable the finish button */ |
---|
333 | while (!finish.getEnabled()) { Utility.sleep(this, 100); } |
---|
334 | btester.actionClick(finish); |
---|
335 | |
---|
336 | /* check if the package folder was created */ |
---|
337 | IFolder folder = project.getFolder(name); |
---|
338 | assertTrue("no package folder was created", folder.exists()); |
---|
339 | |
---|
340 | /* |
---|
341 | * check that the generated package.mo exists and is sane |
---|
342 | */ |
---|
343 | IFile packageMo = folder.getFile("package.mo"); |
---|
344 | assertTrue("package.mo was not created", packageMo.exists()); |
---|
345 | |
---|
346 | boolean same = |
---|
347 | Utility.compareContent(packageMo, |
---|
348 | "encapsulated package " + name + " \"" + description + "\"" + "\n"+ |
---|
349 | "\n"+ |
---|
350 | "end " + name + ";"); |
---|
351 | assertTrue("unexpected conted created in the package.mo", same); |
---|
352 | |
---|
353 | } |
---|
354 | } |
---|