Source Code Cross Referenced for StructureXMLModelTestCase.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » ui » tests » model » xml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.ui.tests.model.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 junit.framework.Test;
013:        import junit.framework.TestSuite;
014:
015:        import org.eclipse.pde.core.plugin.IPluginElement;
016:        import org.eclipse.pde.core.plugin.IPluginExtension;
017:        import org.eclipse.pde.core.plugin.IPluginObject;
018:        import org.eclipse.pde.internal.core.text.IDocumentElementNode;
019:
020:        public class StructureXMLModelTestCase extends XMLModelTestCase {
021:
022:            // Plugin#write(String indent, PrintWriter writer)
023:            // ~ line 99
024:            static String FIRST_INDENT = "   "; //$NON-NLS-1$
025:            // PluginElement#ATTRIBUTE_SHIFT
026:            // ~ line 35
027:            static String ATTRIBUTE_SHIFT = "      "; //$NON-NLS-1$
028:            // PluginElement#ELEMENT_SHIFT
029:            // ~ line 37
030:            static String ELEMENT_SHIFT = "   "; //$NON-NLS-1$
031:
032:            public static Test suite() {
033:                return new TestSuite(StructureXMLModelTestCase.class);
034:            }
035:
036:            public void testStructureAddExtensionLF() throws Exception {
037:                addExtension(LF);
038:            }
039:
040:            public void testStructureAddExtensionCRLF() throws Exception {
041:                addExtension(CRLF);
042:            }
043:
044:            public void testStructureAddElementLF() throws Exception {
045:                addElement(LF);
046:            }
047:
048:            public void testStructureAddElementCRLF() throws Exception {
049:                addElement(CRLF);
050:            }
051:
052:            public void testStructureAddAttributeLF() throws Exception {
053:                addAttributesToElement(LF);
054:            }
055:
056:            public void testStructureAddAttributeCRLF() throws Exception {
057:                addAttributesToElement(CRLF);
058:            }
059:
060:            public void testStructureBreakOpenElementLF() throws Exception {
061:                breakOpenElement(LF);
062:            }
063:
064:            public void testStructureBreakOpenElementCRLF() throws Exception {
065:                breakOpenElement(CRLF);
066:            }
067:
068:            public void testStructurePreserveCommentInRootLF() throws Exception {
069:                preserveCommentAddExtension(LF);
070:            }
071:
072:            public void testStructurePreserveCommentInRootCRLF()
073:                    throws Exception {
074:                preserveCommentAddExtension(CRLF);
075:            }
076:
077:            public void testStructurePreserveCommentInExtensionLF()
078:                    throws Exception {
079:                preserveContainedCommentAddElement(LF);
080:            }
081:
082:            public void testStructurePreserveCommentInExtensionCRLF()
083:                    throws Exception {
084:                preserveContainedCommentAddElement(CRLF);
085:            }
086:
087:            private void addExtension(String lineDelim) throws Exception {
088:                StringBuffer sb = new StringBuffer();
089:                sb.append(FIRST_INDENT);
090:                sb.append("<extension");
091:                sb.append(lineDelim);
092:                sb.append(FIRST_INDENT);
093:                sb.append(ATTRIBUTE_SHIFT);
094:                sb.append("point=\"org.eclipse.pde\">");
095:                sb.append(lineDelim);
096:                sb.append(FIRST_INDENT);
097:                sb.append("</extension>");
098:                setXMLContents(sb, lineDelim);
099:                load(true);
100:
101:                IPluginExtension ext = fModel.getFactory().createExtension();
102:                ext.setPoint("org.eclipse.pde2");
103:                fModel.getPluginBase().add(ext);
104:
105:                reload();
106:
107:                String newContents = fDocument.get();
108:                sb = new StringBuffer();
109:                sb.append(FIRST_INDENT);
110:                sb.append("<extension");
111:                sb.append(lineDelim);
112:                sb.append(FIRST_INDENT);
113:                sb.append(ATTRIBUTE_SHIFT);
114:                sb.append("point=\"org.eclipse.pde\">");
115:                sb.append(lineDelim);
116:                sb.append(FIRST_INDENT);
117:                sb.append("</extension>");
118:                sb.append(lineDelim);
119:                sb.append(FIRST_INDENT);
120:                sb.append("<extension");
121:                sb.append(lineDelim);
122:                sb.append(FIRST_INDENT);
123:                sb.append(ATTRIBUTE_SHIFT);
124:                sb.append("point=\"org.eclipse.pde2\">");
125:                sb.append(lineDelim);
126:                sb.append(FIRST_INDENT);
127:                sb.append("</extension>");
128:                setXMLContents(sb, lineDelim);
129:                assertEquals(fDocument.get(), newContents);
130:            }
131:
132:            private void addElement(String lineDelim) throws Exception {
133:                StringBuffer sb = new StringBuffer();
134:                sb.append(FIRST_INDENT);
135:                sb.append("<extension");
136:                sb.append(lineDelim);
137:                sb.append(FIRST_INDENT);
138:                sb.append(ATTRIBUTE_SHIFT);
139:                sb.append("point=\"org.eclipse.pde\">");
140:                sb.append(lineDelim);
141:                sb.append(FIRST_INDENT);
142:                sb.append("</extension>");
143:                setXMLContents(sb, lineDelim);
144:                load(true);
145:
146:                IPluginExtension[] extensions = fModel.getPluginBase()
147:                        .getExtensions();
148:                assertEquals(1, extensions.length);
149:
150:                IPluginElement element = fModel.getFactory().createElement(
151:                        extensions[0]);
152:                element.setName("child");
153:                extensions[0].add(element);
154:
155:                reload();
156:
157:                String newContents = fDocument.get();
158:                sb = new StringBuffer();
159:                sb.append(FIRST_INDENT);
160:                sb.append("<extension");
161:                sb.append(lineDelim);
162:                sb.append(FIRST_INDENT);
163:                sb.append(ATTRIBUTE_SHIFT);
164:                sb.append("point=\"org.eclipse.pde\">");
165:                sb.append(lineDelim);
166:                sb.append(FIRST_INDENT);
167:                sb.append(ELEMENT_SHIFT);
168:                sb.append("<child></child>");
169:                sb.append(lineDelim);
170:                sb.append(FIRST_INDENT);
171:                sb.append("</extension>");
172:                setXMLContents(sb, lineDelim);
173:                assertEquals(fDocument.get(), newContents);
174:            }
175:
176:            private void addAttributesToElement(String lineDelim)
177:                    throws Exception {
178:                StringBuffer sb = new StringBuffer();
179:                sb.append(FIRST_INDENT);
180:                sb.append("<extension");
181:                sb.append(lineDelim);
182:                sb.append(FIRST_INDENT);
183:                sb.append(ATTRIBUTE_SHIFT);
184:                sb.append("point=\"org.eclipse.pde\">");
185:                sb.append(lineDelim);
186:                sb.append(FIRST_INDENT);
187:                sb.append(ELEMENT_SHIFT);
188:                sb.append("<child/>");
189:                sb.append(lineDelim);
190:                sb.append(FIRST_INDENT);
191:                sb.append("</extension>");
192:                setXMLContents(sb, lineDelim);
193:                load(true);
194:
195:                IPluginExtension[] extensions = fModel.getPluginBase()
196:                        .getExtensions();
197:                assertEquals(1, extensions.length);
198:
199:                IPluginObject[] children = extensions[0].getChildren();
200:
201:                assertEquals(1, children.length);
202:                assertTrue(children[0] instanceof  IPluginElement);
203:
204:                ((IPluginElement) children[0]).setAttribute("id", "a");
205:                ((IPluginElement) children[0]).setAttribute("name", "test");
206:
207:                reload();
208:
209:                String newContents = fDocument.get();
210:                sb = new StringBuffer();
211:                sb.append(FIRST_INDENT);
212:                sb.append("<extension");
213:                sb.append(lineDelim);
214:                sb.append(FIRST_INDENT);
215:                sb.append(ATTRIBUTE_SHIFT);
216:                sb.append("point=\"org.eclipse.pde\">");
217:                sb.append(lineDelim);
218:                sb.append(FIRST_INDENT);
219:                sb.append(ELEMENT_SHIFT);
220:                sb.append("<child");
221:                sb.append(lineDelim);
222:                sb.append(FIRST_INDENT);
223:                sb.append(ELEMENT_SHIFT);
224:                sb.append(ATTRIBUTE_SHIFT);
225:                sb.append("id=\"a\"");
226:                sb.append(lineDelim);
227:                sb.append(FIRST_INDENT);
228:                sb.append(ELEMENT_SHIFT);
229:                sb.append(ATTRIBUTE_SHIFT);
230:                sb.append("name=\"test\"/>");
231:                sb.append(lineDelim);
232:                sb.append(FIRST_INDENT);
233:                sb.append("</extension>");
234:                setXMLContents(sb, lineDelim);
235:                assertEquals(fDocument.get(), newContents);
236:            }
237:
238:            private void breakOpenElement(String lineDelim) throws Exception {
239:                StringBuffer sb = new StringBuffer();
240:                sb.append(FIRST_INDENT);
241:                sb.append("<extension");
242:                sb.append(lineDelim);
243:                sb.append(FIRST_INDENT);
244:                sb.append(ATTRIBUTE_SHIFT);
245:                sb.append("point=\"org.eclipse.pde\">");
246:                sb.append(lineDelim);
247:                sb.append(FIRST_INDENT);
248:                sb.append(ELEMENT_SHIFT);
249:                sb.append("<child/>");
250:                sb.append(lineDelim);
251:                sb.append(FIRST_INDENT);
252:                sb.append("</extension>");
253:                setXMLContents(sb, lineDelim);
254:                load(true);
255:
256:                IPluginExtension[] extensions = fModel.getPluginBase()
257:                        .getExtensions();
258:                assertEquals(1, extensions.length);
259:
260:                IPluginObject[] children = extensions[0].getChildren();
261:                assertEquals(1, children.length);
262:                assertTrue(children[0] instanceof  IPluginElement);
263:
264:                IPluginElement element = fModel.getFactory().createElement(
265:                        children[0]);
266:                element.setName("subchild");
267:                ((IPluginElement) children[0]).add(element);
268:
269:                reload();
270:
271:                String newContents = fDocument.get();
272:                sb = new StringBuffer();
273:                sb.append(FIRST_INDENT);
274:                sb.append("<extension");
275:                sb.append(lineDelim);
276:                sb.append(FIRST_INDENT);
277:                sb.append(ATTRIBUTE_SHIFT);
278:                sb.append("point=\"org.eclipse.pde\">");
279:                sb.append(lineDelim);
280:                sb.append(FIRST_INDENT);
281:                sb.append(ELEMENT_SHIFT);
282:                sb.append("<child>");
283:                sb.append(lineDelim);
284:                sb.append(FIRST_INDENT);
285:                sb.append(ELEMENT_SHIFT);
286:                sb.append(ELEMENT_SHIFT);
287:                sb.append("<subchild></subchild>");
288:                sb.append(lineDelim);
289:                sb.append(FIRST_INDENT);
290:                sb.append(ELEMENT_SHIFT);
291:                sb.append("</child>");
292:                sb.append(lineDelim);
293:                sb.append(FIRST_INDENT);
294:                sb.append("</extension>");
295:                setXMLContents(sb, lineDelim);
296:                assertEquals(fDocument.get(), newContents);
297:            }
298:
299:            private void preserveCommentAddExtension(String lineDelim)
300:                    throws Exception {
301:                String comment = "<!-- THIS IS A COMMENT -->";
302:                StringBuffer sb = new StringBuffer(comment);
303:                setXMLContents(sb, lineDelim);
304:                load(true);
305:
306:                IPluginExtension ext = fModel.getFactory().createExtension();
307:                ext.setPoint("org.eclipse.pde");
308:                fModel.getPluginBase().add(ext);
309:
310:                reload();
311:
312:                int commentIndex = fDocument.get().indexOf(comment);
313:                assertTrue(commentIndex != -1);
314:                IDocumentElementNode parent = (IDocumentElementNode) fModel
315:                        .getPluginBase();
316:                assertTrue(commentIndex >= parent.getOffset());
317:                assertTrue(commentIndex + comment.length() <= parent
318:                        .getOffset()
319:                        + parent.getLength());
320:            }
321:
322:            private void preserveContainedCommentAddElement(String lineDelim)
323:                    throws Exception {
324:                String comment = "<!-- THIS IS A COMMENT INSIDE THE EXTENSION -->";
325:                StringBuffer sb = new StringBuffer();
326:                sb.append("<extension point=\"org.eclipse.pde\">");
327:                sb.append(lineDelim);
328:                sb.append(comment);
329:                sb.append(lineDelim);
330:                sb.append("</extension>");
331:                setXMLContents(sb, lineDelim);
332:                load(true);
333:
334:                IPluginExtension[] extensions = fModel.getPluginBase()
335:                        .getExtensions();
336:                assertEquals(1, extensions.length);
337:
338:                IPluginElement element = fModel.getFactory().createElement(
339:                        extensions[0]);
340:                element.setName("element");
341:                extensions[0].add(element);
342:
343:                reload();
344:
345:                int commentIndex = fDocument.get().indexOf(comment);
346:                assertTrue(commentIndex != -1);
347:                IDocumentElementNode parent = (IDocumentElementNode) fModel
348:                        .getPluginBase();
349:                assertTrue(commentIndex >= parent.getOffset());
350:                assertTrue(commentIndex + comment.length() <= parent
351:                        .getOffset()
352:                        + parent.getLength());
353:            }
354:        }
w_w__w.___j___a_va_2__s__.__c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.