001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.tests.model.xml;
011:
012: import org.eclipse.pde.core.plugin.IPluginElement;
013: import org.eclipse.pde.core.plugin.IPluginExtension;
014: import org.eclipse.pde.core.plugin.IPluginObject;
015:
016: import junit.framework.Test;
017: import junit.framework.TestSuite;
018:
019: public class ExtensionAttributeTestCase extends ExtensionTestCase {
020:
021: public static Test suite() {
022: return new TestSuite(ExtensionAttributeTestCase.class);
023: }
024:
025: public void testAddNewExtensionAttribute1LF() throws Exception {
026: testAddNewExtensionAttribute1(LF);
027: }
028:
029: public void testAddNewExtensionAttribute2LF() throws Exception {
030: testAddNewExtensionAttribute2(LF);
031: }
032:
033: public void testAddNewExtensionAttribute3LF() throws Exception {
034: testAddNewExtensionAttribute3(LF);
035: }
036:
037: public void testAddNewExtensionAttribute1CRLF() throws Exception {
038: testAddNewExtensionAttribute1(CRLF);
039: }
040:
041: public void testAddNewExtensionAttribute2CRLF() throws Exception {
042: testAddNewExtensionAttribute2(CRLF);
043: }
044:
045: public void testAddNewExtensionAttribute3CRLF() throws Exception {
046: testAddNewExtensionAttribute3(CRLF);
047: }
048:
049: private void testAddNewExtensionAttribute1(String newLine)
050: throws Exception {
051: StringBuffer sb = new StringBuffer(
052: "<extension point=\"org.eclipse.pde.ui.samples\"><sample /></extension>");
053: testAddNewExtensionAttribute(sb, newLine);
054: }
055:
056: private void testAddNewExtensionAttribute2(String newLine)
057: throws Exception {
058: StringBuffer buffer = new StringBuffer(
059: "<extension point=\"org.eclipse.pde.ui.samples\">");
060: buffer.append(newLine);
061: buffer.append("<sample />");
062: buffer.append(newLine);
063: buffer.append("</extension>");
064: testAddNewExtensionAttribute(buffer, newLine);
065: }
066:
067: private void testAddNewExtensionAttribute3(String newLine)
068: throws Exception {
069: StringBuffer buffer = new StringBuffer(
070: "<extension point=\"org.eclipse.pde.ui.samples\">");
071: buffer.append(newLine);
072: buffer.append("\t<sample />");
073: buffer.append(newLine);
074: buffer.append("\t</extension>");
075: testAddNewExtensionAttribute(buffer, newLine);
076: }
077:
078: public void testAddExtensionAttribute1LF() throws Exception {
079: testAddExtensionAttribute1(LF);
080: }
081:
082: public void testAddExtensionAttribute2LF() throws Exception {
083: testAddExtensionAttribute2(LF);
084: }
085:
086: public void testAddExtensionAttribute3LF() throws Exception {
087: testAddExtensionAttribute3(LF);
088: }
089:
090: public void testAddExtensionAttribute1CRLF() throws Exception {
091: testAddExtensionAttribute1(CRLF);
092: }
093:
094: public void testAddExtensionAttribute2CRLF() throws Exception {
095: testAddExtensionAttribute2(CRLF);
096: }
097:
098: public void testAddExtensionAttribute3CRLF() throws Exception {
099: testAddExtensionAttribute3(CRLF);
100: }
101:
102: private void testAddExtensionAttribute1(String newLine)
103: throws Exception {
104: StringBuffer buffer = new StringBuffer(
105: "<extension point=\"org.eclipse.pde.ui.samples\">");
106: buffer
107: .append("<sample id=\"org.eclipse.pde.sample1\"/></extension>");
108: testAddExtensionAttribute(buffer, newLine);
109: }
110:
111: private void testAddExtensionAttribute2(String newLine)
112: throws Exception {
113: StringBuffer buffer = new StringBuffer(
114: "<extension point=\"org.eclipse.pde.ui.samples\">");
115: buffer.append(newLine);
116: buffer.append("<sample id=\"org.eclipse.pde.sample1\"/>");
117: buffer.append(newLine);
118: buffer.append("</extension>");
119: testAddExtensionAttribute(buffer, newLine);
120: }
121:
122: private void testAddExtensionAttribute3(String newLine)
123: throws Exception {
124: StringBuffer buffer = new StringBuffer(
125: "<extension point=\"org.eclipse.pde.ui.samples\">");
126: buffer.append(newLine);
127: buffer.append("\t<sample id=\"org.eclipse.pde.sample1\"/>");
128: buffer.append(newLine);
129: buffer.append("\t</extension>");
130: testAddExtensionAttribute(buffer, newLine);
131: }
132:
133: public void testAddNewMultipleAttributes1LF() throws Exception {
134: testAddNewMultipleAttributes1(LF);
135: }
136:
137: public void testAddNewMultipleAttributes2LF() throws Exception {
138: testAddNewMultipleAttributes2(LF);
139: }
140:
141: public void testAddNewMultipleAttributes3LF() throws Exception {
142: testAddNewMultipleAttributes3(LF);
143: }
144:
145: public void testAddNewMultipleAttributes1CRLF() throws Exception {
146: testAddNewMultipleAttributes1(CRLF);
147: }
148:
149: public void testAddNewMultipleAttributes2CRLF() throws Exception {
150: testAddNewMultipleAttributes2(CRLF);
151: }
152:
153: public void testAddNewMultipleAttributes3CRLF() throws Exception {
154: testAddNewMultipleAttributes3(CRLF);
155: }
156:
157: private void testAddNewMultipleAttributes1(String newLine)
158: throws Exception {
159: StringBuffer sb = new StringBuffer(
160: "<extension point=\"org.eclipse.pde.ui.samples\"><sample /></extension>");
161: testAddNewMultipleExtensionAttributes(sb, newLine);
162: }
163:
164: private void testAddNewMultipleAttributes2(String newLine)
165: throws Exception {
166: StringBuffer buffer = new StringBuffer(
167: "<extension point=\"org.eclipse.pde.ui.samples\">");
168: buffer.append(newLine);
169: buffer.append("<sample />");
170: buffer.append(newLine);
171: buffer.append("</extension>");
172: testAddNewMultipleExtensionAttributes(buffer, newLine);
173: }
174:
175: private void testAddNewMultipleAttributes3(String newLine)
176: throws Exception {
177: StringBuffer buffer = new StringBuffer(
178: "<extension point=\"org.eclipse.pde.ui.samples\">");
179: buffer.append(newLine);
180: buffer.append("\t<sample />");
181: buffer.append(newLine);
182: buffer.append("\t</extension>");
183: testAddNewMultipleExtensionAttributes(buffer, newLine);
184: }
185:
186: public void testRemoveExtensionAttribute1LF() throws Exception {
187: testRemoveExtensionAttribute1(LF);
188: }
189:
190: public void testRemoveExtensionAttribute2LF() throws Exception {
191: testRemoveExtensionAttribute2(LF);
192: }
193:
194: public void testRemoveExtensionAttribute3LF() throws Exception {
195: testRemoveExtensionAttribute3(LF);
196: }
197:
198: public void testRemoveExtensionAttribute1CRLF() throws Exception {
199: testRemoveExtensionAttribute1(CRLF);
200: }
201:
202: public void testRemoveExtensionAttribute2CRLF() throws Exception {
203: testRemoveExtensionAttribute2(CRLF);
204: }
205:
206: public void testRemoveExtensionAttribute3CRLF() throws Exception {
207: testRemoveExtensionAttribute3(CRLF);
208: }
209:
210: private void testRemoveExtensionAttribute1(String newLine)
211: throws Exception {
212: StringBuffer buffer = new StringBuffer(
213: "<extension point=\"org.eclipse.pde.ui.samples\">\t");
214: buffer
215: .append("<sample id=\"org.eclipse.pde.sample1\"/>\t</extension>");
216: testRemoveExtensionAttribute(buffer, newLine);
217: }
218:
219: private void testRemoveExtensionAttribute2(String newLine)
220: throws Exception {
221: StringBuffer buffer = new StringBuffer(
222: "<extension point=\"org.eclipse.pde.ui.samples\">");
223: buffer.append(newLine);
224: buffer.append("\t<sample id=\"org.eclipse.pde.sample1\"/>");
225: buffer.append(newLine);
226: buffer.append("</extension>");
227: testRemoveExtensionAttribute(buffer, newLine);
228: }
229:
230: private void testRemoveExtensionAttribute3(String newLine)
231: throws Exception {
232: StringBuffer buffer = new StringBuffer(
233: "<extension point=\"org.eclipse.pde.ui.samples\">");
234: buffer.append(newLine);
235: buffer.append("<sample id=\"org.eclipse.pde.sample1\"/>");
236: buffer.append(newLine);
237: buffer.append("\t</extension>");
238: testRemoveExtensionAttribute(buffer, newLine);
239: }
240:
241: public void testRemoveMultipleExtensionAttributes1LF()
242: throws Exception {
243: testRemoveMultipleExtensionAttributes1(LF);
244: }
245:
246: public void testRemoveMultipleExtensionAttributes2LF()
247: throws Exception {
248: testRemoveMultipleExtensionAttributes2(LF);
249: }
250:
251: public void testRemoveMultipleExtensionAttributes3LF()
252: throws Exception {
253: testRemoveMultipleExtensionAttributes3(LF);
254: }
255:
256: public void testRemoveMultipleExtensionAttributes1CRLF()
257: throws Exception {
258: testRemoveMultipleExtensionAttributes1(CRLF);
259: }
260:
261: public void testRemoveMultipleExtensionAttributes2CRLF()
262: throws Exception {
263: testRemoveMultipleExtensionAttributes2(CRLF);
264: }
265:
266: public void testRemoveMultipleExtensionAttributes3CRLF()
267: throws Exception {
268: testRemoveMultipleExtensionAttributes3(CRLF);
269: }
270:
271: private void testRemoveMultipleExtensionAttributes1(String newLine)
272: throws Exception {
273: StringBuffer buffer = new StringBuffer(
274: "<extension point=\"org.eclipse.pde.ui.samples\">\t");
275: buffer
276: .append("<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/></extension>");
277: testRemoveMultipleExtensionAttributes(buffer, newLine);
278: }
279:
280: private void testRemoveMultipleExtensionAttributes2(String newLine)
281: throws Exception {
282: StringBuffer buffer = new StringBuffer(
283: "<extension point=\"org.eclipse.pde.ui.samples\">");
284: buffer.append(newLine);
285: buffer
286: .append("\t<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/>");
287: buffer.append(newLine);
288: buffer.append("</extension>");
289: testRemoveMultipleExtensionAttributes(buffer, newLine);
290: }
291:
292: private void testRemoveMultipleExtensionAttributes3(String newLine)
293: throws Exception {
294: StringBuffer buffer = new StringBuffer(
295: "<extension point=\"org.eclipse.pde.ui.samples\">");
296: buffer.append(newLine);
297: buffer
298: .append("<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/>");
299: buffer.append(newLine);
300: buffer.append("\t</extension>");
301: testRemoveMultipleExtensionAttributes(buffer, newLine);
302: }
303:
304: public void testChangeExtensionAttribute1LF() throws Exception {
305: testChangeExtensionAttribute1(LF);
306: }
307:
308: public void testChangeExtensionAttribute2LF() throws Exception {
309: testChangeExtensionAttribute2(LF);
310: }
311:
312: public void testChangeExtensionAttribute3LF() throws Exception {
313: testChangeExtensionAttribute3(LF);
314: }
315:
316: public void testChangeExtensionAttribute1CRLF() throws Exception {
317: testChangeExtensionAttribute1(CRLF);
318: }
319:
320: public void testChangeExtensionAttribute2CRLF() throws Exception {
321: testChangeExtensionAttribute2(CRLF);
322: }
323:
324: public void testChangeExtensionAttribute3CRLF() throws Exception {
325: testChangeExtensionAttribute3(CRLF);
326: }
327:
328: private void testChangeExtensionAttribute1(String newLine)
329: throws Exception {
330: StringBuffer buffer = new StringBuffer(
331: "<extension point=\"org.eclipse.pde.ui.samples\">");
332: buffer
333: .append("<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/></extension>");
334: testChangeExtensionAttribute(buffer, newLine);
335: }
336:
337: private void testChangeExtensionAttribute2(String newLine)
338: throws Exception {
339: StringBuffer buffer = new StringBuffer(
340: "<extension point=\"org.eclipse.pde.ui.samples\">");
341: buffer.append(newLine);
342: buffer
343: .append("\t<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/>");
344: buffer.append(newLine);
345: buffer.append("</extension>");
346: testChangeExtensionAttribute(buffer, newLine);
347: }
348:
349: private void testChangeExtensionAttribute3(String newLine)
350: throws Exception {
351: StringBuffer buffer = new StringBuffer(
352: "<extension point=\"org.eclipse.pde.ui.samples\">");
353: buffer.append(newLine);
354: buffer
355: .append("\t\t\t<sample id=\"org.eclipse.pde.sample1\" name=\"pde sample\" perspectiveId=\"org.eclipse.pde.ui.PDEPerspective\"/>");
356: buffer.append(newLine);
357: buffer.append("\t</extension>");
358: testChangeExtensionAttribute(buffer, newLine);
359: }
360:
361: private void testAddNewExtensionAttribute(StringBuffer buffer,
362: String newLine) throws Exception {
363: StringBuffer sb = new StringBuffer(
364: "<extension point=\"org.eclipse.pde.ui.samples\"><sample /></extension>");
365: setXMLContents(sb, LF);
366: load(true);
367:
368: IPluginExtension[] extensions = fModel.getPluginBase()
369: .getExtensions();
370: assertEquals(extensions.length, 1);
371: assertEquals(extensions[0].getChildCount(), 1);
372: IPluginObject child = extensions[0].getChildren()[0];
373:
374: assertTrue(child instanceof IPluginElement);
375: IPluginElement elem = (IPluginElement) child;
376: elem.setAttribute("id", "org.eclipse.pde.sample1");
377:
378: IPluginExtension ext = reloadModel();
379: assertEquals(ext.getChildCount(), 1);
380: elem = (IPluginElement) ext.getChildren()[0];
381: assertEquals(elem.getName(), "sample");
382: assertEquals(elem.getAttribute("id").getValue(),
383: "org.eclipse.pde.sample1");
384: }
385:
386: private void testAddExtensionAttribute(StringBuffer buffer,
387: String newLine) throws Exception {
388: setXMLContents(buffer, newLine);
389: load(true);
390:
391: IPluginExtension[] extensions = fModel.getPluginBase()
392: .getExtensions();
393: assertEquals(extensions.length, 1);
394: assertEquals(extensions[0].getChildCount(), 1);
395: IPluginObject child = extensions[0].getChildren()[0];
396:
397: assertTrue(child instanceof IPluginElement);
398: IPluginElement elem = (IPluginElement) child;
399: assertEquals(elem.getAttribute("id").getValue(),
400: "org.eclipse.pde.sample1");
401: elem.setAttribute("name", "pde sample");
402:
403: IPluginExtension ext = reloadModel();
404:
405: assertEquals(ext.getChildCount(), 1);
406: elem = (IPluginElement) ext.getChildren()[0];
407: assertEquals(elem.getName(), "sample");
408: assertEquals(elem.getAttributeCount(), 2);
409: assertEquals(elem.getAttribute("id").getValue(),
410: "org.eclipse.pde.sample1");
411: assertEquals(elem.getAttribute("name").getValue(), "pde sample");
412: }
413:
414: private void testAddNewMultipleExtensionAttributes(
415: StringBuffer buffer, String newLine) throws Exception {
416: setXMLContents(buffer, newLine);
417: load(true);
418:
419: IPluginExtension[] extensions = fModel.getPluginBase()
420: .getExtensions();
421: assertEquals(extensions.length, 1);
422: assertEquals(extensions[0].getChildCount(), 1);
423: IPluginObject child = extensions[0].getChildren()[0];
424: assertTrue(child instanceof IPluginElement);
425: IPluginElement elem = (IPluginElement) child;
426: elem.setAttribute("id", "org.eclipse.pde.sample1");
427: elem.setAttribute("name", "pde sample");
428:
429: IPluginExtension ext = reloadModel();
430:
431: assertEquals(ext.getChildCount(), 1);
432: elem = (IPluginElement) ext.getChildren()[0];
433: assertEquals(elem.getName(), "sample");
434: assertEquals(elem.getAttribute("id").getValue(),
435: "org.eclipse.pde.sample1");
436: assertEquals(elem.getAttribute("name").getValue(), "pde sample");
437: }
438:
439: private void testRemoveExtensionAttribute(StringBuffer buffer,
440: String newLine) throws Exception {
441: setXMLContents(buffer, newLine);
442: load(true);
443:
444: IPluginExtension[] extensions = fModel.getPluginBase()
445: .getExtensions();
446: assertEquals(extensions.length, 1);
447: assertEquals(extensions[0].getChildCount(), 1);
448: IPluginObject child = extensions[0].getChildren()[0];
449:
450: assertTrue(child instanceof IPluginElement);
451: IPluginElement elem = (IPluginElement) child;
452: assertEquals(elem.getAttribute("id").getValue(),
453: "org.eclipse.pde.sample1");
454: elem.setAttribute("id", null);
455:
456: IPluginExtension ext = reloadModel();
457:
458: assertEquals(ext.getChildCount(), 1);
459: elem = (IPluginElement) ext.getChildren()[0];
460: assertEquals(elem.getName(), "sample");
461: assertEquals(elem.getAttributeCount(), 0);
462: }
463:
464: private void testRemoveMultipleExtensionAttributes(
465: StringBuffer buffer, String newLine) throws Exception {
466: setXMLContents(buffer, newLine);
467: load(true);
468:
469: IPluginExtension[] extensions = fModel.getPluginBase()
470: .getExtensions();
471: assertEquals(extensions.length, 1);
472: assertEquals(extensions[0].getChildCount(), 1);
473: IPluginObject child = extensions[0].getChildren()[0];
474: assertTrue(child instanceof IPluginElement);
475: assertEquals(((IPluginElement) child).getAttributeCount(), 3);
476:
477: assertTrue(child instanceof IPluginElement);
478: IPluginElement elem = (IPluginElement) child;
479: assertEquals(elem.getAttribute("id").getValue(),
480: "org.eclipse.pde.sample1");
481: elem.setAttribute("id", null);
482: elem.setAttribute("perspectiveId", null);
483:
484: IPluginExtension ext = reloadModel();
485:
486: assertEquals(ext.getChildCount(), 1);
487: elem = (IPluginElement) ext.getChildren()[0];
488: assertEquals(elem.getName(), "sample");
489: assertEquals(elem.getAttributeCount(), 1);
490: assertEquals(elem.getAttribute("name").getValue(), "pde sample");
491: }
492:
493: private void testChangeExtensionAttribute(StringBuffer buffer,
494: String newLine) throws Exception {
495: setXMLContents(buffer, newLine);
496: load(true);
497:
498: IPluginExtension[] extensions = fModel.getPluginBase()
499: .getExtensions();
500: assertEquals(extensions.length, 1);
501: assertEquals(extensions[0].getChildCount(), 1);
502: IPluginObject child = extensions[0].getChildren()[0];
503: assertTrue(child instanceof IPluginElement);
504: IPluginElement elem = (IPluginElement) child;
505: assertEquals(elem.getAttribute("id").getValue(),
506: "org.eclipse.pde.sample1");
507: elem.setAttribute("id", "org.eclipse.pde.sample2");
508:
509: IPluginExtension ext = reloadModel();
510:
511: assertEquals(ext.getChildCount(), 1);
512: elem = (IPluginElement) ext.getChildren()[0];
513: assertEquals(elem.getName(), "sample");
514: assertEquals(elem.getAttributeCount(), 3);
515: assertEquals(elem.getAttribute("id").getValue(),
516: "org.eclipse.pde.sample2");
517: assertEquals(elem.getAttribute("name").getValue(), "pde sample");
518: assertEquals(elem.getAttribute("perspectiveId").getValue(),
519: "org.eclipse.pde.ui.PDEPerspective");
520: }
521: }
|