Source Code Cross Referenced for ContextualDiffProviderTest.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » diff » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.diff 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ecyrd.jspwiki.diff;
002:
003:        import java.io.IOException;
004:        import java.util.Properties;
005:
006:        import junit.framework.Test;
007:        import junit.framework.TestCase;
008:        import junit.framework.TestSuite;
009:
010:        import org.apache.log4j.PropertyConfigurator;
011:
012:        import com.ecyrd.jspwiki.*;
013:
014:        public class ContextualDiffProviderTest extends TestCase {
015:            /**
016:             * Sets up some shorthand notation for writing test cases.
017:             * <p>
018:             * The quick |^Brown Fox^-Blue Monster-| jumped over |^the^| moon.
019:             * <p>
020:             * Get it?
021:             */
022:            private void specializedNotation(ContextualDiffProvider diff) {
023:                diff.m_changeEndHtml = "|";
024:                diff.m_changeStartHtml = "|";
025:
026:                diff.m_deletionEndHtml = "-";
027:                diff.m_deletionStartHtml = "-";
028:
029:                diff.m_diffEnd = "";
030:                diff.m_diffStart = "";
031:
032:                diff.m_elidedHeadIndicatorHtml = "...";
033:                diff.m_elidedTailIndicatorHtml = "...";
034:
035:                diff.m_emitChangeNextPreviousHyperlinks = false;
036:
037:                diff.m_insertionEndHtml = "^";
038:                diff.m_insertionStartHtml = "^";
039:
040:                diff.m_lineBreakHtml = "";
041:                diff.m_alternatingSpaceHtml = "_";
042:            }
043:
044:            public void testNoChanges() throws IOException, WikiException {
045:                diffTest(null, "", "", "");
046:                diffTest(null, "A", "A", "A");
047:                diffTest(null, "A B", "A B", "A B");
048:
049:                diffTest(null, "      ", "      ", " _ _ _");
050:                diffTest(null, "A B  C", "A B  C", "A B _C");
051:                diffTest(null, "A B   C", "A B   C", "A B _ C");
052:            }
053:
054:            public void testSimpleInsertions() throws IOException,
055:                    WikiException {
056:                // Ah, the white space trailing an insertion is tacked onto the insertion, this is fair, the
057:                // alternative would be to greedily take the leading whitespace before the insertion as part
058:                // of it instead, and that doesn't make any more or less sense. just remember this behaviour
059:                // when writing tests.
060:
061:                // Simple inserts...
062:                diffTest(null, "A C", "A B C", "A |^B ^|C");
063:                diffTest(null, "A D", "A B C D", "A |^B C ^|D");
064:
065:                // Simple inserts with spaces...
066:                diffTest(null, "A C", "A B  C", "A |^B _^|C");
067:                diffTest(null, "A C", "A B   C", "A |^B _ ^|C");
068:                diffTest(null, "A C", "A B    C", "A |^B _ _^|C");
069:
070:                // Just inserted spaces...
071:                diffTest(null, "A B", "A  B", "A |^_^|B");
072:                diffTest(null, "A B", "A   B", "A |^_ ^|B");
073:                diffTest(null, "A B", "A    B", "A |^_ _^|B");
074:                diffTest(null, "A B", "A     B", "A |^_ _ ^|B");
075:            }
076:
077:            public void testSimpleDeletions() throws IOException, WikiException {
078:                // Simple deletes...
079:                diffTest(null, "A B C", "A C", "A |-B -|C");
080:                diffTest(null, "A B C D", "A D", "A |-B C -|D");
081:
082:                // Simple deletes with spaces...
083:                diffTest(null, "A B  C", "A C", "A |-B _-|C");
084:                diffTest(null, "A B   C", "A C", "A |-B _ -|C");
085:
086:                // Just deleted spaces...
087:                diffTest(null, "A  B", "A B", "A |-_-|B");
088:                diffTest(null, "A   B", "A B", "A |-_ -|B");
089:                diffTest(null, "A    B", "A B", "A |-_ _-|B");
090:            }
091:
092:            public void testContextLimits() throws IOException, WikiException {
093:                // No change
094:                diffTest("1", "A B C D E F G H I", "A B C D E F G H I", "A...");
095:                //TODO Hmm, should the diff provider instead return the string, "No Changes"?
096:
097:                // Bad property value, should default to huge context limit and return entire string.
098:                diffTest("foobar", "A B C D E F G H I", "A B C D F G H I",
099:                        "A B C D |-E -|F G H I");
100:
101:                // One simple deletion, limit context to 2...
102:                diffTest("2", "A B C D E F G H I", "A B C D F G H I",
103:                        "...D |-E -|F ...");
104:
105:                // Deletion of first element, limit context to 2...
106:                diffTest("2", "A B C D E", "B C D E", "|-A -|B ...");
107:
108:                // Deletion of last element, limit context to 2...
109:                diffTest("2", "A B C D E", "A B C D ", "...D |-E-|");
110:
111:                // Two simple deletions, limit context to 2...
112:                diffTest("2", "A B C D E F G H I J K L M N O P",
113:                        "A B C E F G H I J K M N O P",
114:                        "...C |-D -|E ......K |-L -|M ...");
115:
116:            }
117:
118:            public void testMultiples() throws IOException, WikiException {
119:                diffTest(null, "A F", "A B C D E F", "A |^B C D E ^|F");
120:                diffTest(null, "A B C D E F", "A F", "A |-B C D E -|F");
121:
122:            }
123:
124:            public void testSimpleChanges() throws IOException, WikiException {
125:                // *changes* are actually an insert and a delete in the output...
126:
127:                //single change
128:                diffTest(null, "A B C", "A b C", "A |^b^-B-| C");
129:
130:                //non-consequtive changes...
131:                diffTest(null, "A B C D E", "A b C d E",
132:                        "A |^b^-B-| C |^d^-D-| E");
133:
134:            }
135:
136:            // FIXME: This test fails; must be enabled again asap.
137:            /*
138:            public void testKnownProblemCases() throws NoRequiredPropertyException, IOException
139:            {
140:                //These all fail...
141:                
142:                //make two consequtive changes
143:                diffTest(null, "A B C D", "A b c D", "A |^b c^-B C-| D");
144:                //acually returns ->                 "A |^b^-B-| |^c^-C-| D"
145:
146:                //collapse adjacent elements...
147:                diffTest(null, "A B C D", "A BC D", "A |^BC^-B C-| D");
148:                //acually returns ->                "A |^BC^-B-| |-C -|D"
149:                
150:                
151:                //These failures are all due to how we process the diff results, we need to collapse 
152:                //adjacent edits into one...
153:                
154:            }
155:             */
156:
157:            private void diffTest(String contextLimit, String oldText,
158:                    String newText, String expectedDiff) throws IOException,
159:                    WikiException {
160:                ContextualDiffProvider diff = new ContextualDiffProvider();
161:
162:                specializedNotation(diff);
163:
164:                Properties props = new Properties();
165:                if (null != contextLimit)
166:                    props
167:                            .put(
168:                                    ContextualDiffProvider.PROP_UNCHANGED_CONTEXT_LIMIT,
169:                                    contextLimit);
170:
171:                diff.initialize(null, props);
172:
173:                props.load(TestEngine.findTestProperties());
174:                PropertyConfigurator.configure(props);
175:                TestEngine engine = new TestEngine(props);
176:
177:                WikiContext ctx = new WikiContext(engine, new WikiPage(engine,
178:                        "Dummy"));
179:                String actualDiff = diff.makeDiffHtml(ctx, oldText, newText);
180:
181:                assertEquals(expectedDiff, actualDiff);
182:            }
183:
184:            public static Test suite() {
185:                return new TestSuite(ContextualDiffProviderTest.class);
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.