Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7a65fd8b560b907663ce256b08d0b60cb1cfa1a6 (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
/*******************************************************************************
 * Copyright (c) 2001, 2009 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.tests.tabbed.properties.sections;


import java.io.IOException;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jst.jsf.common.ui.internal.dialogfield.DialogField;
import org.eclipse.jst.pagedesigner.editors.HTMLEditor;
import org.eclipse.jst.pagedesigner.editors.properties.IPropertyPageDescriptor;
import org.eclipse.jst.pagedesigner.properties.internal.AttributeGroupSection;
import org.eclipse.jst.pagedesigner.properties.internal.NullQuickEditTabSection;
import org.eclipse.jst.pagedesigner.properties.internal.QuickEditTabManager;
import org.eclipse.jst.pagedesigner.properties.internal.QuickEditTabSectionsDescriptor;
import org.eclipse.jst.pagedesigner.ui.dialogfields.DialogFieldWrapper;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.views.properties.tabbed.ISection;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class BasicTabbedPropertyPageTests extends BaseTestCase {
	public void testSanity() {
		HTMLEditor ed = null;
		try {			
			
			final IFile file = getJSPFile("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage.jsp");
			assertNotNull(file);
			
			IViewPart view = showPropertiesView();
			assertNotNull(view);
			ed = openHTMLEditor(file);	
			assertNotNull(ed);
					
			Node node = getNode(file, 425);
            assertTrue(node instanceof Element);
            assertEquals("tagWithQuickEditMD", node.getLocalName()); 
            
            ISelection sel = getSelection(node);
            view.getViewSite().getSelectionProvider().setSelection(sel);
            ISelection selection = view.getViewSite().getSelectionProvider().getSelection();
            assertEquals(sel, selection);
            
		} catch(Exception ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} finally {
			if (ed != null)
				closeEditor(ed);
		}
	}
	
	
	/**
	 * A little white-box testing covering basic sanity of the framework 
	 * including sanity check of ITagAttributeCellEditorFactory
	 */
	public void testQuickEditTabManager() {
		IFile file = null;
		QuickEditTabManager mgr = null;
		HTMLEditor ed = null;
		try {
			file = getJSPFile("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage.jsp");
			assertNotNull(file);
			ed = openHTMLEditor(file);	
			assertNotNull(ed);
			showPropertiesView();
			mgr = getWPETabbedPropertySheetPage(ed).getTabManager();
			assertNotNull(mgr);
			
			//Node with QuickEdit MD
			Node node1 = getNode(file, 425);            
			ISelection selection = getSelection(node1);			
			mgr.selectionChanged(ed, selection);
			QuickEditTabSectionsDescriptor tsg1 = mgr.getCurrentTabGroupDescriptor();
			assertNotNull("QuickEditTabSectionsDescriptor was null for Qtag with QE MD", tsg1);
			
			List<ISection> sections = tsg1.getSections();
			assertEquals("Expected 3 sections for tag qith QE MD", 3, sections.size());
			//check for expected sections
			//section 1 is a section group with 3 attributes
			ISection sec = sections.get(0);
			assertTrue("section was not AttributeGroupSection", sec instanceof AttributeGroupSection);
			//check expected DialogFields
			DialogField[] fields = ((AttributeGroupSection)sec).getAttributeGroup().getDialogFields();
			assertEquals("Expecting 4 dialog fields for the 4 attributes", 4, fields.length);
			
			//check dialog fields - sanity check of tag attribute cell editor factory
				//aBoolean
				DialogField fld = fields[0];
				assertTrue("IPropertyPageDescriptor not located for tagWithQuickEditMD", fld.getAttachedData("KEY_ATTR") instanceof IPropertyPageDescriptor);
				IPropertyPageDescriptor ppd = (IPropertyPageDescriptor)fld.getAttachedData("KEY_ATTR");
				assertEquals("aBoolean", ppd.getAttributeName());
				assertTrue("aBoolean fld should be a DialogFieldWrapper", fld instanceof DialogFieldWrapper);
				assertTrue("aBoolean should be a MDEnabledComboDialogField", ((DialogFieldWrapper)fld).getWrappedDialogField().getClass().getName().equals("org.eclipse.jst.pagedesigner.properties.dialogfields.MDEnabledComboDialogField"));
			
				//aStyle
				fld = fields[1];
				assertEquals("aStyle", ((IPropertyPageDescriptor)fld.getAttachedData("KEY_ATTR")).getAttributeName());
				assertTrue("aStyle should be a StyleButtonDialogField", ((DialogFieldWrapper)fld).getWrappedDialogField().getClass().getName().equals("org.eclipse.jst.pagedesigner.ui.dialogfields.StyleButtonDialogField"));

				//aStringPropWithMd
				fld = fields[2];
				assertEquals("aStringPropWithMd", ((IPropertyPageDescriptor)fld.getAttachedData("KEY_ATTR")).getAttributeName());
				assertTrue("aStringPropWithMd should be a MDEnabledComboDialogField", ((DialogFieldWrapper)fld).getWrappedDialogField().getClass().getName().equals("org.eclipse.jst.pagedesigner.properties.dialogfields.MDEnabledComboDialogField"));
				
				//aStringPropNoMd
				fld = fields[3];
				assertEquals("aStringPropNoMd", ((IPropertyPageDescriptor)fld.getAttachedData("KEY_ATTR")).getAttributeName());
				assertTrue("aStringPropNoMd should be a StringDialogField", ((DialogFieldWrapper)fld).getWrappedDialogField().getClass().getName().equals("org.eclipse.jst.jsf.common.ui.internal.dialogfield.StringDialogField"));

			///
				
			//2nd section in tabSectionDesc
			sec = sections.get(1);
			assertTrue("section was not FakePropertySection", sec instanceof FakePropertySection);
			//
			sec = sections.get(2);
			assertTrue("section was not FakePropertySectionUsingDialogField", sec instanceof FakePropertySectionUsingDialogField);
			
			//Node without QuickEdit MD
			Node node2 = getNode(file, 475);
			selection = getSelection(node2);			
			mgr.selectionChanged(ed, selection);
			QuickEditTabSectionsDescriptor tsg2 = mgr.getCurrentTabGroupDescriptor();
			assertNotNull("QuickEditTabSectionsDescriptor was null", tsg2);
			
			sections = tsg2.getSections();
			assertEquals("Expected single section", 1, sections.size());
			//check for expected sections
			sec = sections.get(0);
			assertTrue("section was not NullQuickEditTabSection", sec instanceof NullQuickEditTabSection);			
			
			//set back to QuikEditMD node... should be same descriptor
			selection = getSelection(node1);			
			mgr.selectionChanged(ed, selection);
			assertSame("Desc w/MD not same", tsg1, mgr.getCurrentTabGroupDescriptor());
			
			//null desc
			selection = getSelection(node2);			
			mgr.selectionChanged(ed, selection);			
			assertSame("Desc wo/MD not same", tsg2, mgr.getCurrentTabGroupDescriptor());
			
			//test tag with bad QE MD			
			Node node3 = getNode(file, 530);
			selection = getSelection(node3);			
			mgr.selectionChanged(ed, selection);
			QuickEditTabSectionsDescriptor tsg3 = mgr.getCurrentTabGroupDescriptor();
			assertNotNull("QuickEditTabSectionsDescriptor was null for Qtag with bad QE MD", tsg3);
			
			sections = tsg3.getSections();
			assertEquals("Expected 2 sections for tag with bad QE MD", 2, sections.size());//missing section is skipped
			//check for expected sections
			//section 1 is a section group with 2 attributes.  One bad attr was skipped
			sec = sections.get(0);
			assertTrue("section was not AttributeGroupSection", sec instanceof AttributeGroupSection);
			//
			sec = sections.get(1);
			assertTrue("section was not FakePropertySectionUsingDialogField", sec instanceof FakePropertySectionUsingDialogField);

		} catch (IOException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (CoreException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} finally {
			mgr = null;
			if (ed != null)
				closeEditor(ed);
		
		}				
	}

	public void testMultipleJSPs(){
		QuickEditTabManager mgr1 = null;
		QuickEditTabManager mgr2 = null;
		HTMLEditor ed1 = null;
		HTMLEditor ed2 = null; 
		try {
			IFile file = getJSPFile("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage.jsp");
			assertNotNull(file);
			ed1 = openHTMLEditor(file);	
			assertNotNull(ed1);
			showPropertiesView();
			mgr1 = getWPETabbedPropertySheetPage(ed1).getTabManager();			
			assertNotNull(mgr1);
			
			//Node with QuickEdit MD
			Node node1 = getNode(file, 425);            
			ISelection selection = getSelection(node1);			
			mgr1.selectionChanged(ed1, selection);
			QuickEditTabSectionsDescriptor tsg1 = mgr1.getCurrentTabGroupDescriptor();
			assertNotNull(tsg1);
			
			//open 2nd page
			file = getJSPFile("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage2.jsp");
			assertNotNull(file);
			ed2 = openHTMLEditor(file);	
			assertNotNull(ed2);
			showPropertiesView();
			mgr2 = getWPETabbedPropertySheetPage(ed2).getTabManager();
			assertNotNull(mgr2);
			
			//Manager instances should be the same for different WPE instances within same project
			assertSame("Manager instances should be the same for different WPE instances within same project", mgr1.getQuickEditTabSectionsManager(), mgr2.getQuickEditTabSectionsManager());
			
			Node node2 = getNode(file, 425);            
			selection = getSelection(node2);			
			mgr2.selectionChanged(ed2, selection);
			QuickEditTabSectionsDescriptor tsg2= mgr2.getCurrentTabGroupDescriptor();
			assertSame("section descriptor for tag on different pages should be the same", tsg1, tsg2);
						
			
		} catch (IOException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (CoreException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} finally {				
			mgr1 = null;
			mgr2 = null;
			if (ed1 != null) {
				closeEditor(ed1);
				ed1 = null;
			}
			if (ed2 != null){
				//should cause disposal of QuickEditTabManager and SectionManager
				closeEditor(ed2);
				ed2 = null;
			}
		}
	}
	
	public void testMultiProject() {
		QuickEditTabManager mgr1 = null;
		QuickEditTabManager mgr2 = null;
		HTMLEditor ed1 = null;
		HTMLEditor ed2 = null; 
		try {
			IFile file = getJSPFile("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage.jsp");
			assertNotNull(file);
			ed1 = openHTMLEditor(file);	
			assertNotNull(ed1);
			showPropertiesView();
			mgr1 = getWPETabbedPropertySheetPage(ed1).getTabManager();			
			assertNotNull(mgr1);
			
			//Node with QuickEdit MD
			Node node1 = getNode(file, 425);            
			ISelection selection = getSelection(node1);			
			mgr1.selectionChanged(ed1, selection);
			QuickEditTabSectionsDescriptor tsg1 = mgr1.getCurrentTabGroupDescriptor();
			assertNotNull(tsg1);
			
			//open 2nd page from second project
			file = getJSPFileFromSecondProject("/testdata/propertypages/testPropertyPage.jsp.data", "/testPropertyPage2.jsp");
			assertNotNull(file);
			ed2 = openHTMLEditor(file);	
			assertNotNull(ed2);
			showPropertiesView();
			mgr2 = getWPETabbedPropertySheetPage(ed2).getTabManager();
			assertNotNull(mgr2);
			
			//Manager instances should be the DIFFERENT for different WPE instances within DIFFERENT projects
			assertNotSame("Should have different QuickEditMgrInstances for different projects", mgr1.getQuickEditTabSectionsManager(), mgr2.getQuickEditTabSectionsManager());
			
			Node node2 = getNode(file, 425);            
			selection = getSelection(node2);			
			mgr2.selectionChanged(ed2, selection);
			QuickEditTabSectionsDescriptor tsg2= mgr2.getCurrentTabGroupDescriptor();
			assertNotSame("section descriptor for tag on different pages from different projects should be different", tsg1, tsg2);
						
		} catch (IOException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (CoreException ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} catch (Exception ex) {
			ex.printStackTrace();
			fail(ex.getLocalizedMessage());
		} finally {				
			mgr1 = null;
			mgr2 = null;
			if (ed1 != null) {
				//should cause disposal of QuickEditTabManager and SectionManager
				closeEditor(ed1);
				ed1 = null;
			}
			if (ed2 != null){
				//should cause disposal of QuickEditTabManager and SectionManager
				closeEditor(ed2);
				ed2 = null;
			}
		}
	}
	
}

Back to the top