Skip to main content
summaryrefslogtreecommitdiffstats
blob: 02941fc3bcf042052b6fc37b9322bf2d84e59bba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
package org.eclipse.ui.tests.dialogs;

import java.util.ResourceBundle;

import junit.framework.TestCase;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.tests.util.DialogCheck;


public class UIMessageDialogsAuto extends TestCase {
	private static final String DUMMY_RESOURCE = "Dummy.resource";
	private static final String DUMMY_PROJECT = "DummyProject";
	private static final String DUMMY_ABSOLUTE_PATH = "C:\\Dummypath\\Dummy.resource";
	private static final String DUMMY_RELATIVE_PATH = "\\" + DUMMY_PROJECT + "\\" + DUMMY_RESOURCE;
	
	public UIMessageDialogsAuto(String name) {
		super(name);
	}
	private Shell getShell() {
		return DialogCheck.getShell();
	}
	
	/*
	 * Convenience method simliar to org.eclipse.jface.dialogs.MessageDialog::openConfirm.
	 * The method will return the dialog instead of opening.
	 * @param title the dialog's title, or <code>null</code> if none.
	 * @param message the message.
	 * @return Dialog the confirm dialog.
	 */
	private MessageDialog getConfirmDialog(String title, String message) {
		return new MessageDialog(
			getShell(), 
			title, 
			null,
			message, 
			MessageDialog.QUESTION, 
			new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 
			0);
	}
	/*
	 * Convenience method simliar to org.eclipse.jface.dialogs.MessageDialog::openError.
	 * The method will return the dialog instead of opening.
	 * @param title the dialog's title, or <code>null</code> if none.
	 * @param message the message.
	 * @return MessageDialog the error confirm dialog.
	 */
	private MessageDialog getErrorDialog(String title, String message) {
		return new MessageDialog(
			getShell(),
			title, 
			null,
			message, 
			MessageDialog.ERROR, 
			new String[] {IDialogConstants.OK_LABEL}, 
			0);
	}
	/*
	 * Convenience method simliar to org.eclipse.jface.dialogs.MessageDialog::openInformation.
	 * The method will return the dialog instead of opening.
	 * @param title the dialog's title, or <code>null</code> if none.
	 * @param message the message.
	 * @return MessageDialog the information dialog.
	 */
	private MessageDialog getInformationDialog(String title, String message) {
		return new MessageDialog(
			getShell(),
			title,
			null,
			message,
			MessageDialog.INFORMATION,
			new String[] { IDialogConstants.OK_LABEL },
			0);
	}
	/*
	 * Convenience method simliar to org.eclipse.jface.dialogs.MessageDialog::openQuestion.
	 * The method will return the dialog instead of opening.
	 * @param title the dialog's title, or <code>null</code> if none.
	 * @param message the message.
	 * @return MessageDialog the question dialog.
	 */
	private MessageDialog getQuestionDialog(String title, String message) {
		return new MessageDialog(
			getShell(),
			title, 
			null,
			message, 
			MessageDialog.QUESTION, 
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL}, 
			0);
	}
	/*
	 * Convenience method simliar to org.eclipse.jface.dialogs.MessageDialog::getWarningDialog.
	 * The method will return the dialog instead of opening.
	 * @param title the dialog's title, or <code>null</code> if none.
	 * @param message the message.
	 * @return MessageDialog the confirm dialog.
	 */
	private MessageDialog getWarningDialog(String title, String message) {
		return new MessageDialog(
			getShell(),
			title, 
			null,
			message, 
			MessageDialog.WARNING, 
			new String[] {IDialogConstants.OK_LABEL}, 
			0);
	}
	
	public void testAbortPageFlipping() {
		Dialog dialog = getWarningDialog (
			JFaceResources.getString("AbortPageFlippingDialog.title"),
			JFaceResources.getString("AbortPageFlippingDialog.message") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testCloseFileDeleted() {
		Dialog dialog = null;
		ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.EditorMessages");
		if (bundle != null) {
			dialog = getConfirmDialog(
				bundle.getString("Editor.error.activated.deleted.close.title"),
				bundle.getString("Editor.error.activated.deleted.close.message") );
		}
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testCopyOverwrite() {
		Dialog dialog = getQuestionDialog(
			WorkbenchMessages.getString("CopyResourceAction.resourceExists"),
			WorkbenchMessages.format("CopyResourceAction.overwriteQuestion", new Object[] {DUMMY_RELATIVE_PATH}) );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testDeleteProject() {
		String title = WorkbenchMessages.getString("DeleteResourceAction.titleProject");
		String msg = WorkbenchMessages.format("DeleteResourceAction.confirmProject1", new Object[] {DUMMY_PROJECT, DUMMY_ABSOLUTE_PATH});
		Dialog dialog = new MessageDialog(
			getShell(),
			title, 
			null,	// accept the default window icon
			msg, 
			MessageDialog.QUESTION, 
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testDeleteReadOnlyCheck() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("DeleteResourceAction.checkDelete"),
			null,
			WorkbenchMessages.format("DeleteResourceAction.readOnlyQuestion", new Object[] {DUMMY_RESOURCE}),
			MessageDialog.QUESTION,
			new String[] {
				IDialogConstants.YES_LABEL,
				IDialogConstants.YES_TO_ALL_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL },
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testDeleteResource() {
		Dialog dialog = getQuestionDialog(
			WorkbenchMessages.getString("DeleteResourceAction.title"),
			WorkbenchMessages.format("DeleteResourceAction.confirm1", new Object[] {DUMMY_RESOURCE}) );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testDeleteResources() {
		Dialog dialog = getQuestionDialog(
			WorkbenchMessages.getString("DeleteResourceAction.title"),
			WorkbenchMessages.format("DeleteResourceAction.confirmN", new Object[] {DUMMY_RESOURCE}) );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testDropOverwrite() {
		Dialog dialog = new MessageDialog(
			getShell(),
			ResourceNavigatorMessagesCopy.getString("DropAdapter.question"),
			null,
			ResourceNavigatorMessagesCopy.format("DropAdapter.overwriteQuery", new Object[] {DUMMY_RELATIVE_PATH}),
			MessageDialog.QUESTION,
			new String[] {
				IDialogConstants.YES_LABEL,
				IDialogConstants.YES_TO_ALL_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testErrorClosing() {
		Dialog dialog = getQuestionDialog(
			WorkbenchMessages.getString("Error"),
			WorkbenchMessages.getString("ErrorClosingNoArg") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testFileChanged() {
		MessageDialog dialog = null;
		ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.EditorMessages");
		if (bundle != null) {
			dialog = getQuestionDialog(
				bundle.getString("Editor.error.activated.outofsync.title"),
				bundle.getString("Editor.error.activated.outofsync.message") );
		}
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testFileExtensionEmpty() {
		Dialog dialog = getInformationDialog(
			WorkbenchMessages.getString("FileEditorPreference.extensionEmptyTitle"),
			WorkbenchMessages.getString("FileEditorPreference.extensionEmptyMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testFileNameWrong() {
		Dialog dialog = getInformationDialog(
			WorkbenchMessages.getString("FileEditorPreference.fileNameInvalidTitle"),
			WorkbenchMessages.getString("FileEditorPreference.fileNameInvalidMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testFileTypeExists() {
		Dialog dialog = getInformationDialog(
			WorkbenchMessages.getString("FileEditorPreference.existsTitle"),
			WorkbenchMessages.getString("FileEditorPreference.existsMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testInvalidType_1() {
		Dialog dialog = getWarningDialog(
			WorkbenchMessages.getString("FileExtension.invalidTitle"),
			WorkbenchMessages.getString("FileExtension.invalidMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testInvalidType_2() {
		Dialog dialog = getWarningDialog(
			WorkbenchMessages.getString("FileExtension.invalidType"),
			WorkbenchMessages.getString("FileExtension.invalidTypeMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testMoveReadOnlyCheck() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("MoveResourceAction.title"),
			null,
			WorkbenchMessages.format("MoveResourceAction.checkMoveMessage", new Object[] {DUMMY_RESOURCE}),
			MessageDialog.QUESTION,
			new String[] {
				IDialogConstants.YES_LABEL,
				IDialogConstants.YES_TO_ALL_LABEL,
				IDialogConstants.NO_LABEL,
				IDialogConstants.CANCEL_LABEL },
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testNoBuilders() {
		Dialog dialog = getWarningDialog(
			WorkbenchMessages.getString("BuildAction.warning"),
			WorkbenchMessages.getString("BuildAction.noBuilders") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testNoGlobalBuildersDialog() {
		Dialog dialog = getWarningDialog(
			WorkbenchMessages.getString("GlobalBuildAction.warning"),
			WorkbenchMessages.getString("GlobalBuildAction.noBuilders") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testNoPropertyPage() {
		Dialog dialog = getInformationDialog(
			WorkbenchMessages.getString("PropertyDialog.messageTitle"),
			WorkbenchMessages.format("PropertyDialog.noPropertyMessage", new Object[] {"DummyPropertyPage"}) );	
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testNoSelectedExportResources() {
		Dialog dialog = getInformationDialog(
			DataTransferMessagesCopy.getString("DataTransfer.information"),
			DataTransferMessagesCopy.getString("FileExport.noneSelected") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testNoSelectedImportResources() {
		Dialog dialog = getInformationDialog(
			DataTransferMessagesCopy.getString("DataTransfer.information"),
			DataTransferMessagesCopy.getString("FileImport.noneSelected") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testOperationNotAvailable() {
		Dialog dialog = getInformationDialog(
			WorkbenchMessages.getString("Information"),
			WorkbenchMessages.getString("PluginActino.operationNotAvailableMessage") );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testOverwritePerspective() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("SavePerspective.overwriteTitle"),
			null,
			WorkbenchMessages.format("SavePerspective.overwriteQuestion", new Object[] {"Dummy Perspective"}),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testRefreshDeleteProject() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("RefreshAction.dialogTitle"),
			null,
			WorkbenchMessages.format("RefreshAction.locationDeletedMessage", new Object[] {DUMMY_PROJECT, "c:\\dummypath\\" + DUMMY_PROJECT}),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testRenameOverwrite() {
		Dialog dialog = getQuestionDialog(
			WorkbenchMessages.getString("RenameResourceAction.resourceExists"),
			WorkbenchMessages.format("RenameResourceAction.overwriteQuestion", new Object[] {DUMMY_RELATIVE_PATH}) );
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testResetPerspective() {		
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("ResetPerspective.title"),
			null,
			WorkbenchMessages.format("ResetPerspective.message", new Object[] {"Dummy Perspective"}),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testSaveAsOverwrite() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("Question"),
			null,
			WorkbenchMessages.format("SaveAsDialog.overwriteQuestion", new Object[] {DUMMY_RELATIVE_PATH}),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testSaveChanges() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("Save_Resource"),
			null,
			WorkbenchMessages.format("EditorManager.saveChangesQuestion", new Object[] {DUMMY_RESOURCE}),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testSaveFileDeleted() {
		MessageDialog dialog = null;
		ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.EditorMessages");
		if (bundle != null) {
			dialog= new MessageDialog(
				getShell(),
				bundle.getString("Editor.error.activated.deleted.save.title"),
				null,
				bundle.getString("Editor.error.activated.deleted.save.message"),
				MessageDialog.QUESTION,
				new String[] {
					bundle.getString("Editor.error.activated.deleted.save.button.save"),
					bundle.getString("Editor.error.activated.deleted.save.button.close")},
				0);
		}
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testUpdateConflict() {
		MessageDialog dialog = null;
		ResourceBundle bundle = ResourceBundle.getBundle("org.eclipse.ui.texteditor.EditorMessages");
		if (bundle != null) {
			dialog = getQuestionDialog(
				bundle.getString("Editor.error.save.outofsync.title"),
				bundle.getString("Editor.error.save.outofsync.message") );
		}
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testWizardClosing() {
		Dialog dialog = new MessageDialog(
			getShell(),
			JFaceResources.getString("WizardClosingDialog.title"),
			null,
			JFaceResources.getString("WizardClosingDialog.message"),
			MessageDialog.QUESTION,
			new String[] {IDialogConstants.OK_LABEL},
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}
	public void testWizardOverwrite() {
		Dialog dialog = new MessageDialog(
			getShell(),
			WorkbenchMessages.getString("Question"),
			null, 
			WorkbenchMessages.format("WizardDataTransfer.existsQuestion", new Object[] {DUMMY_ABSOLUTE_PATH}),
			MessageDialog.QUESTION, 
			new String[] {
				IDialogConstants.YES_LABEL, 
				IDialogConstants.YES_TO_ALL_LABEL, 
				IDialogConstants.NO_LABEL, 
				IDialogConstants.CANCEL_LABEL}, 
			0);
		DialogCheck.assertDialogTexts(dialog, this);
	}



}

Back to the top