Lines 4-10
Link Here
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* Oracle Corporation - initial API and implementation |
9 |
* Oracle Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
Lines 38-51
Link Here
|
38 |
* @author cbateman |
38 |
* @author cbateman |
39 |
* |
39 |
* |
40 |
*/ |
40 |
*/ |
41 |
public class TestTagCreationFactory extends BaseTestClass |
41 |
public class TestTagCreationFactory extends BaseTestClass |
42 |
{ |
42 |
{ |
43 |
public TestTagCreationFactory() { |
43 |
public TestTagCreationFactory() { |
44 |
super("jsf"); |
44 |
super("jsf"); |
45 |
} |
45 |
} |
46 |
|
46 |
|
47 |
@Override |
47 |
@Override |
48 |
protected void setUp() throws Exception |
48 |
protected void setUp() throws Exception |
49 |
{ |
49 |
{ |
50 |
super.setUp(); |
50 |
super.setUp(); |
51 |
|
51 |
|
Lines 58-64
Link Here
|
58 |
} |
58 |
} |
59 |
|
59 |
|
60 |
@Override |
60 |
@Override |
61 |
protected void tearDown() throws Exception |
61 |
protected void tearDown() throws Exception |
62 |
{ |
62 |
{ |
63 |
super.tearDown(); |
63 |
super.tearDown(); |
64 |
} |
64 |
} |
Lines 72-79
Link Here
|
72 |
|
72 |
|
73 |
CreationData creationData = |
73 |
CreationData creationData = |
74 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
74 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
75 |
, "tagWithRequiredAttr", "test", jspFile, 501); |
75 |
, "tagWithRequiredAttr", "test", jspFile, 501, null); |
76 |
Element element = CommandUtil.excuteInsertion(creationData.getTagEntry() |
76 |
Element element = CommandUtil.executeInsertion(creationData.getTagCreationProvider() |
77 |
, creationData.getModel() |
77 |
, creationData.getModel() |
78 |
, creationData.getDomPosition() |
78 |
, creationData.getDomPosition() |
79 |
, creationData.getDropCustomizationData()); |
79 |
, creationData.getDropCustomizationData()); |
Lines 96-113
Link Here
|
96 |
,"/testEnsureRequiredAttributes2.jsp"); |
96 |
,"/testEnsureRequiredAttributes2.jsp"); |
97 |
creationData = |
97 |
creationData = |
98 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
98 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
99 |
, "tagWithRequiredAttr2", "test", jspFile, 501); |
99 |
, "tagWithRequiredAttr2", "test", jspFile, 501, null); |
100 |
element = CommandUtil.excuteInsertion(creationData.getTagEntry() |
100 |
element = CommandUtil.executeInsertion(creationData.getTagCreationProvider() |
101 |
, creationData.getModel() |
101 |
, creationData.getModel() |
102 |
, creationData.getDomPosition() |
102 |
, creationData.getDomPosition() |
103 |
, creationData.getDropCustomizationData()); |
103 |
, creationData.getDropCustomizationData()); |
104 |
|
104 |
|
105 |
// on this tag, the first required attr is set by metadata |
105 |
// on this tag, the first required attr is set by metadata |
106 |
assertEquals("foobar", element.getAttribute(TestCreationFactory.REQUIRED_ATTR_1)); |
106 |
assertEquals("foobar", element.getAttribute(TestCreationFactory.REQUIRED_ATTR_1)); |
107 |
// the second one is not set by meta-data, but is required and ensure is called |
107 |
// the second one is not set by meta-data, but is required and ensure is called |
108 |
// by the custom advisor, so it should be set to empty |
108 |
// by the custom advisor, so it should be set to empty |
109 |
assertEquals("", element.getAttribute(TestCreationFactory.REQUIRED_ATTR_2)); |
109 |
assertEquals("", element.getAttribute(TestCreationFactory.REQUIRED_ATTR_2)); |
110 |
|
110 |
|
111 |
// the optional attribute is not set by meta-data and since it's not required, |
111 |
// the optional attribute is not set by meta-data and since it's not required, |
112 |
// the ensure method should not touch it either. |
112 |
// the ensure method should not touch it either. |
113 |
assertNull(element.getAttribute("notRequiredAttr1")); |
113 |
assertNull(element.getAttribute("notRequiredAttr1")); |
Lines 115-129
Link Here
|
115 |
|
115 |
|
116 |
public void testTagCreationMetadata() throws Exception |
116 |
public void testTagCreationMetadata() throws Exception |
117 |
{ |
117 |
{ |
118 |
IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
118 |
final IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
119 |
PageDesignerTestsPlugin.getDefault().getBundle() |
119 |
PageDesignerTestsPlugin.getDefault().getBundle() |
120 |
,"/testdata/tagcreator/testTagCreation.jsp.data" |
120 |
,"/testdata/tagcreator/testTagCreation.jsp.data" |
121 |
,"/testTagCreationMetadata.jsp"); |
121 |
,"/testTagCreationMetadata.jsp"); |
122 |
|
122 |
|
123 |
CreationData creationData = |
123 |
final CreationData creationData = |
124 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
124 |
getCreationData(TestCreationFactory.TAGCREATOR_URI_1 |
125 |
, "tagWithMetadata", "test", jspFile, 501); |
125 |
, "tagWithMetadata", "test", jspFile, 501, null); |
126 |
Element element = CommandUtil.excuteInsertion(creationData.getTagEntry() |
126 |
final Element element = CommandUtil.executeInsertion( |
|
|
127 |
creationData.getTagCreationProvider() |
127 |
, creationData.getModel() |
128 |
, creationData.getModel() |
128 |
, creationData.getDomPosition() |
129 |
, creationData.getDomPosition() |
129 |
, creationData.getDropCustomizationData()); |
130 |
, creationData.getDropCustomizationData()); |
Lines 155-180
Link Here
|
155 |
*/ |
156 |
*/ |
156 |
public void testBug197042() throws Exception |
157 |
public void testBug197042() throws Exception |
157 |
{ |
158 |
{ |
158 |
IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
159 |
final IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
159 |
PageDesignerTestsPlugin.getDefault().getBundle() |
160 |
PageDesignerTestsPlugin.getDefault().getBundle() |
160 |
,"/testdata/tagcreator/tagCreator.jspx.data" |
161 |
,"/testdata/tagcreator/tagCreator.jspx.data" |
161 |
,"/testTagCreationMetadata.jsp"); |
162 |
,"/testTagCreationMetadata.jsp"); |
162 |
|
163 |
|
163 |
final String uri = |
164 |
final String uri = |
164 |
IJSFConstants.TAG_IDENTIFIER_COMMANDBUTTON.getUri(); |
165 |
IJSFConstants.TAG_IDENTIFIER_COMMANDBUTTON.getUri(); |
165 |
final String tagName = |
166 |
final String tagName = |
166 |
IJSFConstants.TAG_IDENTIFIER_COMMANDBUTTON.getTagName(); |
167 |
IJSFConstants.TAG_IDENTIFIER_COMMANDBUTTON.getTagName(); |
167 |
CreationData creationData = |
168 |
final CreationData creationData = |
168 |
getCreationData(uri,tagName,"h", jspFile, 495); |
169 |
getCreationData(uri,tagName,"h", jspFile, 495, null); |
169 |
|
170 |
|
170 |
ITagCreator tagCreator = TagCreationFactory.getInstance() |
171 |
final ITagCreator tagCreator = TagCreationFactory.getInstance() |
171 |
.createTagCreator(creationData.getTagId()); |
172 |
.createTagCreator(creationData.getTagId()); |
172 |
|
173 |
|
173 |
Element element = tagCreator.createTag(creationData); |
174 |
final Element element = tagCreator.createTag(creationData); |
174 |
|
175 |
|
175 |
System.out.println(element.toString()); |
176 |
System.out.println(element.toString()); |
176 |
|
177 |
|
177 |
ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); |
178 |
final ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); |
178 |
getDocumentContext(0, jspFile).getModel().save(resultStream); |
179 |
getDocumentContext(0, jspFile).getModel().save(resultStream); |
179 |
|
180 |
|
180 |
final IPath expectedPath = JSFTestUtil.getAbsolutePath( |
181 |
final IPath expectedPath = JSFTestUtil.getAbsolutePath( |
Lines 188-201
Link Here
|
188 |
|
189 |
|
189 |
public void testDropCustomizerThatCancels() throws Exception |
190 |
public void testDropCustomizerThatCancels() throws Exception |
190 |
{ |
191 |
{ |
191 |
IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
192 |
final IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
192 |
PageDesignerTestsPlugin.getDefault().getBundle() |
193 |
PageDesignerTestsPlugin.getDefault().getBundle() |
193 |
,"/testdata/tagcreator/tagCreator.jsp.data" |
194 |
,"/testdata/tagcreator/tagCreator.jsp.data" |
194 |
,"/testCustomizerCancel.jsp"); |
195 |
,"/testCustomizerCancel.jsp"); |
195 |
|
196 |
|
196 |
TestCreationFactory.setTestParametersForDropCustomer(Status.CANCEL_STATUS, null); |
197 |
TestCreationFactory.setTestParametersForDropCustomer(Status.CANCEL_STATUS, null); |
197 |
|
198 |
|
198 |
MockItemCreationTool tool = |
199 |
final MockItemCreationTool tool = |
199 |
createMockItemCreationTool(jspFile, 358, TestCreationFactory.TAG_WITH_REQUIRED_ATTR, IStatus.CANCEL); |
200 |
createMockItemCreationTool(jspFile, 358, TestCreationFactory.TAG_WITH_REQUIRED_ATTR, IStatus.CANCEL); |
200 |
|
201 |
|
201 |
tool.customizeDropAndMaybeExecute(0); |
202 |
tool.customizeDropAndMaybeExecute(0); |
Lines 206-222
Link Here
|
206 |
@SuppressWarnings("unchecked") |
207 |
@SuppressWarnings("unchecked") |
207 |
public void testDropCustomizationDataAcquistion() throws Exception |
208 |
public void testDropCustomizationDataAcquistion() throws Exception |
208 |
{ |
209 |
{ |
209 |
IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
210 |
final IFile jspFile = (IFile) _webProjectTestEnv.loadResourceInWebRoot( |
210 |
PageDesignerTestsPlugin.getDefault().getBundle() |
211 |
PageDesignerTestsPlugin.getDefault().getBundle() |
211 |
,"/testdata/tagcreator/tagCreator.jsp.data" |
212 |
,"/testdata/tagcreator/tagCreator.jsp.data" |
212 |
,"/testCustomizerCancel.jsp"); |
213 |
,"/testCustomizerCancel.jsp"); |
213 |
|
214 |
|
214 |
IAdaptable adaptable = new IAdaptable() |
215 |
final IAdaptable adaptable = new IAdaptable() |
215 |
{ |
216 |
{ |
216 |
public Object getAdapter(Class adapter) { |
217 |
public Object getAdapter(final Class adapter) { |
217 |
if (Map.class == adapter) |
218 |
if (Map.class == adapter) |
218 |
{ |
219 |
{ |
219 |
HashMap<String, String> map = new HashMap<String, String>(); |
220 |
final HashMap<String, String> map = new HashMap<String, String>(); |
220 |
map.put("color", "red"); |
221 |
map.put("color", "red"); |
221 |
return map; |
222 |
return map; |
222 |
} |
223 |
} |
Lines 226-252
Link Here
|
226 |
|
227 |
|
227 |
TestCreationFactory.setTestParametersForDropCustomer(Status.OK_STATUS, adaptable); |
228 |
TestCreationFactory.setTestParametersForDropCustomer(Status.OK_STATUS, adaptable); |
228 |
|
229 |
|
229 |
MockItemCreationTool tool = |
230 |
final MockItemCreationTool tool = |
230 |
createMockItemCreationTool(jspFile, 358, TestCreationFactory.TAG_WITH_REQUIRED_ATTR, IStatus.CANCEL); |
231 |
createMockItemCreationTool(jspFile, 358, TestCreationFactory.TAG_WITH_REQUIRED_ATTR, IStatus.CANCEL); |
231 |
|
232 |
|
232 |
tool.customizeDropAndMaybeExecute(0); |
233 |
tool.customizeDropAndMaybeExecute(0); |
233 |
Object[] commands = tool.getDomain().getCommandStack().getCommands(); |
234 |
final Object[] commands = tool.getDomain().getCommandStack().getCommands(); |
234 |
assertEquals(1, commands.length); |
235 |
assertEquals(1, commands.length); |
235 |
assertTrue(commands[0] instanceof MockCreateItemCommand); |
236 |
assertTrue(commands[0] instanceof MockCreateItemCommand); |
236 |
|
237 |
|
237 |
IAdaptable value = ((MockCreateItemCommand)commands[0]).getCustomizationDataTesting(); |
238 |
final IAdaptable value = ((MockCreateItemCommand)commands[0]).getCustomizationDataTesting(); |
238 |
assertEquals(adaptable, value); |
239 |
assertEquals(adaptable, value); |
239 |
Map map = (Map) value.getAdapter(Map.class); |
240 |
final Map map = (Map) value.getAdapter(Map.class); |
240 |
assertNotNull(map); |
241 |
assertNotNull(map); |
241 |
assertEquals("red", map.get("color")); |
242 |
assertEquals("red", map.get("color")); |
242 |
} |
243 |
} |
243 |
|
244 |
|
244 |
private void assertExpectedResult(IFile file, String outExt) throws Exception |
245 |
private void assertExpectedResult(final IFile file, final String outExt) throws Exception |
245 |
{ |
246 |
{ |
246 |
final ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); |
247 |
final ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); |
247 |
getDocumentContext(0, file).getModel().save(resultStream); |
248 |
getDocumentContext(0, file).getModel().save(resultStream); |
248 |
|
249 |
|
249 |
final String expected = |
250 |
final String expected = |
250 |
getExpectedResult("/testdata/tagcreator/tagCreator."+outExt+".data").trim(); |
251 |
getExpectedResult("/testdata/tagcreator/tagCreator."+outExt+".data").trim(); |
251 |
final String result = resultStream.toString("ISO-8859-1").trim(); |
252 |
final String result = resultStream.toString("ISO-8859-1").trim(); |
252 |
|
253 |
|