Source Code Cross Referenced for ArchiveTest.java in  » ERP-CRM-Financial » sakai » org » apache » commons » jrcs » rcs » 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 » ERP CRM Financial » sakai » org.apache.commons.jrcs.rcs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ====================================================================
003:         *
004:         * The Apache Software License, Version 1.1
005:         *
006:         * Copyright (c) 1999-2003 The Apache Software Foundation.
007:         * All rights reserved.
008:         *
009:         * Redistribution and use in source and binary forms, with or without
010:         * modification, are permitted provided that the following conditions
011:         * are met:
012:         *
013:         * 1. Redistributions of source code must retain the above copyright
014:         *    notice, this list of conditions and the following disclaimer.
015:         *
016:         * 2. Redistributions in binary form must reproduce the above copyright
017:         *    notice, this list of conditions and the following disclaimer in
018:         *    the documentation and/or other materials provided with the
019:         *    distribution.
020:         *
021:         * 3. The end-user documentation included with the redistribution, if
022:         *    any, must include the following acknowledgement:
023:         *       "This product includes software developed by the
024:         *        Apache Software Foundation (http://www.apache.org/)."
025:         *    Alternately, this acknowledgement may appear in the software itself,
026:         *    if and wherever such third-party acknowledgements normally appear.
027:         *
028:         * 4. The names "The Jakarta Project", "Commons", and "Apache Software
029:         *    Foundation" must not be used to endorse or promote products derived
030:         *    from this software without prior written permission. For written
031:         *    permission, please contact apache@apache.org.
032:         *
033:         * 5. Products derived from this software may not be called "Apache"
034:         *    nor may "Apache" appear in their names without prior written
035:         *    permission of the Apache Software Foundation.
036:         *
037:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
041:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
042:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
043:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
044:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
045:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
046:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
047:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
048:         * SUCH DAMAGE.
049:         * ====================================================================
050:         *
051:         * This software consists of voluntary contributions made by many
052:         * individuals on behalf of the Apache Software Foundation.  For more
053:         * information on the Apache Software Foundation, please see
054:         * <http://www.apache.org/>.
055:         *
056:         */
057:
058:        package org.apache.commons.jrcs.rcs;
059:
060:        import junit.framework.Test;
061:        import junit.framework.TestCase;
062:        import junit.framework.TestSuite;
063:
064:        import org.apache.commons.jrcs.util.ToString;
065:        import org.apache.commons.jrcs.diff.Diff;
066:        import org.apache.commons.jrcs.diff.DiffException;
067:
068:        public class ArchiveTest extends TestCase {
069:
070:            public ArchiveTest(String testName) {
071:                super (testName);
072:            }
073:
074:            public static Test suite() {
075:                return new TestSuite(ArchiveTest.class);
076:            }
077:
078:            Object[] v1_1 = new String[] { "[1] one", "[2] two", "[3] three",
079:                    "[4] four", "[5] five", "[6] six", };
080:            Object[] v1_2 = new String[] { "[1] one", "[2] two", "[3] three",
081:                    "[3.1]", // inserted this
082:                    "[4] four", "[5] five"
083:            // deleted [6]
084:            };
085:
086:            String user = System.getProperty("user.name");
087:
088:            // WARNING: there apparently uneeded string concatenations
089:            // are there to prevent CVS from mangling our test data.
090:
091:            Object[] v1_2_with_keywords = new String[] {
092:                    "",
093:                    "[3] three  $" + "Source: trash #3$",
094:                    "[4] four   $" + "RCSfile:  trash #4$",
095:                    "[5] five   $" + "Revision: trash # 5 $",
096:                    "[7] seven  $" + "Author: trash #7 $",
097:                    "[8] eight  $" + "State: trash 8 $",
098:                    "[9] nine   $Locker:  $",
099:                    "[10] ten   $" + "RCSfile: trash #10 $ " + "$"
100:                            + "Revision: trash #10 $ " + "$"
101:                            + "Author: trash $", "" };
102:
103:            Object[] v1_2_with_expanded_keywords = new String[] {
104:                    "",
105:                    "[3] three  $" + "Source: /a/test/path/test_file,v $",
106:                    "[4] four   $" + "RCSfile: test_file,v $",
107:                    "[5] five   $" + "Revision: 1.2 $",
108:                    "[7] seven  $" + "Author: " + user + " $",
109:                    "[8] eight  $" + "State: Exp $",
110:                    "[9] nine   $Locker:  $",
111:                    "[10] ten   $" + "RCSfile: test_file,v $ " + "$"
112:                            + "Revision: 1.2 $ " + "$" + "Author: " + user
113:                            + " $", "" };
114:
115:            Object[] v1_3 = new String[] { "[1] one changed", "[2] two",
116:                    "[3] three", "[3.1]", "[4] four", "[5] five" };
117:
118:            Object[] v1_20 = new String[] { "[1:1.20] one changed",
119:                    "[3] three", "[3.1]", "[5:1.20] five" };
120:
121:            Object[] v1_2_1_1 = new String[] { "[1] one", "[2] two", "[2.1]",
122:                    "[3] three", "[3.1]", "[4] four changed", "[5] five",
123:                    "[5.1]" };
124:
125:            Object[] v1_2_1_2 = new String[] { "[1:1.2.1.1] one", "[2.1]",
126:                    "[3] three", "[3.1]", "[4] four changed",
127:                    "[5:1.2.1.1] five", "[5.1]" };
128:
129:            Object[] v1_2_8_2 = new String[] { "[1:1.2.8.1] one", "[2.1]",
130:                    "[3] three", "[3.1]", "[4] four changed",
131:                    "[5:1.2.8.1] five", "[5.1]" };
132:
133:            Object[] v1_2_8_4 = new String[] { "[1:1.2.8.1] one", "[2.1]",
134:                    "[3.1:1.2.8.2]", "[4] four changed", "[5:1.2.8.1] five",
135:                    "[5.1]" };
136:
137:            Object[] v1_2_8_5 = new String[] { "[1:1.2.8.5] one" };
138:
139:            Archive archive;
140:
141:            public void setUp() {
142:                archive = new Archive(v1_1, "A simple test file");
143:                archive.setFileName("/a/test/path/test_file,v");
144:            }
145:
146:            public void testEmptyArchive() {
147:                try {
148:                    Object[] rev = new Archive().getRevision();
149:                    if (rev != null)
150:                        fail("empty archive, exception should be thrown");
151:                } catch (Exception e) {
152:                }
153:            }
154:
155:            public void testAdd1_1() throws DiffException, RCSException {
156:                Object[] rev = archive.getRevision();
157:                assertTrue(Diff.compare(v1_1, rev));
158:                assertNull(archive.addRevision(v1_1, "should not be added"));
159:
160:                assertEquals(new Version("1.1"), archive.getRevisionVersion());
161:                assertEquals(new Version("1.1"), archive
162:                        .getRevisionVersion("1."));
163:
164:                assertNull(archive.getRevisionVersion("2"));
165:                assertNull(archive.getRevisionVersion("1.2.1"));
166:
167:                Node[] log = archive.changeLog();
168:                assertNotNull("log is null", log);
169:                assertEquals(1, log.length);
170:                assertEquals("1.1", log[0].version.toString());
171:            }
172:
173:            public void testAdd1_2() throws DiffException, RCSException {
174:                testAdd1_1();
175:                archive.addRevision(v1_2, "Added 3.1, deleted 6");
176:                Object[] rev = archive.getRevision();
177:                assertEquals("1.2", archive.head.version.toString());
178:                assertEquals(ToString.arrayToString(v1_2), ToString
179:                        .arrayToString(rev));
180:                assertNull(archive.addRevision(v1_2, "should not be added"));
181:
182:                assertEquals(new Version("1.2"), archive.getRevisionVersion());
183:                assertEquals(new Version("1.2"), archive
184:                        .getRevisionVersion("1."));
185:
186:                assertNull(archive.getRevisionVersion("2"));
187:                assertNull(archive.getRevisionVersion("1.2.1"));
188:
189:                Node[] log = archive.changeLog();
190:                assertNotNull("log is null", log);
191:                assertEquals(2, log.length);
192:                assertEquals("1.1", log[0].version.toString());
193:                assertEquals("1.2", log[1].version.toString());
194:            }
195:
196:            public void testAdd1_2_with_keywords() throws DiffException,
197:                    RCSException {
198:                testAdd1_1();
199:                archive.addRevision(v1_2_with_keywords,
200:                        "Added revision with keywords");
201:                Object[] rev = archive.getRevision();
202:
203:                assertEquals("1.2", archive.head.version.toString());
204:
205:                assertEquals(ToString
206:                        .arrayToString(v1_2_with_expanded_keywords), ToString
207:                        .arrayToString(rev));
208:                assertNull(archive.addRevision(v1_2_with_expanded_keywords,
209:                        "should not be added"));
210:
211:                assertEquals(new Version("1.2"), archive.getRevisionVersion());
212:                assertEquals(new Version("1.2"), archive
213:                        .getRevisionVersion("1."));
214:
215:                assertNull(archive.getRevisionVersion("2"));
216:                assertNull(archive.getRevisionVersion("1.2.1"));
217:            }
218:
219:            public void testAdd1_3() throws DiffException, RCSException {
220:                testAdd1_2();
221:                archive.addRevision(v1_3, "Changed 1");
222:                Object[] rev = archive.getRevision();
223:                assertTrue(Diff.compare(v1_3, rev));
224:                assertNull(archive.addRevision(v1_3, "should not be added"));
225:
226:                assertEquals(new Version("1.3"), archive.getRevisionVersion());
227:                assertEquals(new Version("1.3"), archive
228:                        .getRevisionVersion("1"));
229:
230:                assertNull(archive.getRevisionVersion("2"));
231:                assertNull(archive.getRevisionVersion("1.2.1"));
232:
233:                Node[] log = archive.changeLog();
234:                assertNotNull("log is null", log);
235:                assertEquals(3, log.length);
236:                assertEquals("1.1", log[0].version.toString());
237:                assertEquals("1.2", log[1].version.toString());
238:                assertEquals("1.3", log[2].version.toString());
239:            }
240:
241:            public void testAdd1_2_1() throws DiffException, RCSException {
242:                testAdd1_3();
243:                archive.addRevision(v1_2_1_1, "1.2.1",
244:                        "Added 2.1, changed 4, added 5.1");
245:                String filestr = archive.toString();
246:                String[] file = (String[]) Diff.stringToArray(filestr);
247:
248:                for (int i = 0; i < sampleFile.length && i < file.length; i++) {
249:                    if (!sampleFile[i].startsWith("date"))
250:                        assertEquals("line " + i, sampleFile[i], file[i]);
251:                }
252:                assertEquals("file size", sampleFile.length, file.length);
253:
254:                Object[] rev = archive.getRevision("1.2.1");
255:                assertTrue("diffs equal", Diff.compare(v1_2_1_1, rev));
256:                assertNull("should not be added", archive.addRevision(v1_2_1_1,
257:                        "1.2.1", "should not be added"));
258:
259:                assertEquals("dot", new Version("1.2.1.1"), archive
260:                        .getRevisionVersion("1.2."));
261:                assertEquals("zero", new Version("1.2.1.1"), archive
262:                        .getRevisionVersion("1.2.0"));
263:
264:                assertEquals(new Version("1.2.1.1"), archive
265:                        .getRevisionVersion("1.2.1"));
266:                assertEquals(new Version("1.2.1.1"), archive
267:                        .getRevisionVersion("1.2.1"));
268:
269:                assertNull(archive.getRevisionVersion("2"));
270:                assertNull(archive.getRevisionVersion("1.3.1"));
271:
272:                assertNull(archive.getRevisionVersion("1.2.1.2"));
273:                assertNull(archive.getRevisionVersion("1.2.2"));
274:
275:                Node[] log = archive.changeLog(new Version("1.2.1"));
276:                assertNotNull("log is null", log);
277:                assertEquals(3, log.length);
278:                assertEquals("1.1", log[0].version.toString());
279:                assertEquals("1.2", log[1].version.toString());
280:                assertEquals("1.2.1.1", log[2].version.toString());
281:
282:                log = archive.changeLog(new Version("1.2.1"),
283:                        new Version("1.2"));
284:                assertNotNull("log is null", log);
285:                assertEquals(2, log.length);
286:                assertEquals("1.2", log[0].version.toString());
287:                assertEquals("1.2.1.1", log[1].version.toString());
288:            }
289:
290:            public void testBranch() throws DiffException, RCSException {
291:                testAdd1_3();
292:                archive.setBranch("1.2.0");
293:                archive.addRevision(v1_2_1_1, "Added 2.1, changed 4");
294:                String file = archive.toString();
295:                Object[] rev = archive.getRevision("1.2.1.1");
296:                assertTrue(Diff.compare(v1_2_1_1, rev));
297:                Version v;
298:                v = archive.addRevision(v1_2_1_2, "1.2.0",
299:                        "Arbitrary revision number");
300:                assertEquals("1.2.1.2", v.toString());
301:
302:                v = archive.addRevision(v1_2_8_2, "1.2.8.2",
303:                        "Arbitrary revision number");
304:                assertEquals("1.2.8.2", v.toString());
305:
306:                try {
307:                    v = archive.addRevision(v1_2_8_4, "1.2.8.1",
308:                            "Added to arbitrary branch");
309:                    fail("could add revision 1.2.8.1 after having added 1.2.8.2");
310:                } catch (InvalidVersionNumberException e) {
311:                }
312:
313:                v = archive.addRevision(v1_2_8_4, "1.2.8.4",
314:                        "Added to arbitrary branch");
315:                assertEquals("1.2.8.4", v.toString());
316:
317:                v = archive.addRevision(v1_2_8_5, "1.2.0",
318:                        "Added to arbitrary branch");
319:                assertEquals("1.2.8.5", v.toString());
320:
321:                assertEquals(new Version("1.2.8.5"), archive
322:                        .getRevisionVersion());
323:                assertEquals(".8", new Version("1.2.8.5"), archive
324:                        .getRevisionVersion("1.2.8"));
325:                assertEquals(new Version("1.2.8.5"), archive
326:                        .getRevisionVersion("1.2."));
327:                assertEquals(new Version("1.2.8.5"), archive
328:                        .getRevisionVersion("1.2.0"));
329:
330:                assertNull(archive.getRevisionVersion("1.2.8.6"));
331:                assertNull(archive.getRevisionVersion("1.2.3"));
332:                assertNull(archive.getRevisionVersion("1.2.9"));
333:
334:                Node[] log = archive.changeLog(new Version("1.2.8"));
335:                assertNotNull("log is null", log);
336:                assertEquals(5, log.length);
337:                assertEquals("1.1", log[0].version.toString());
338:                assertEquals("1.2", log[1].version.toString());
339:                assertEquals("1.2.8.2", log[2].version.toString());
340:                assertEquals("1.2.8.4", log[3].version.toString());
341:                assertEquals("1.2.8.5", log[4].version.toString());
342:
343:                try {
344:                    log = archive.changeLog(new Version("1.2.8"), new Version(
345:                            "1.2.1"));
346:                    fail("found change log between 1.2.8.5 and 1.2.1.2");
347:                } catch (NodeNotFoundException e) {
348:                }
349:
350:            }
351:
352:            public void testInvalidBranch() throws DiffException, RCSException {
353:                testAdd1_1();
354:                try {
355:                    archive.setBranch("1.3.1");
356:                    fail("succeeded with invalid branch");
357:                } catch (InvalidVersionNumberException e) {
358:                }
359:            }
360:
361:            public void testUnicodeEscapes() throws DiffException, RCSException {
362:                Archive archive = new Archive(new String[] { "\\user" },
363:                        "original");
364:                archive.addRevision(new String[] { "user" }, "original");
365:            }
366:
367:            String[] sampleFile = { "head\t1.3;", "access;", "symbols;",
368:                    "locks; strict;", "comment\t@# @;", "", "", "1.3",
369:                    "date\t99.08.24.16.58.59;\tauthor juanca;\tstate Exp;",
370:                    "branches;", "next\t1.2;", "", "1.2",
371:                    "date\t99.08.24.16.57.54;\tauthor juanca;\tstate Exp;",
372:                    "branches", "\t1.2.1.1;", "next\t1.1;", "", "1.1",
373:                    "date\t99.08.24.16.56.51;\tauthor juanca;\tstate Exp;",
374:                    "branches;", "next\t;", "", "1.2.1.1",
375:                    "date\t99.08.24.17.00.30;\tauthor juanca;\tstate Exp;",
376:                    "branches;", "next\t;", "", "", "desc", "@@", "", "",
377:                    "1.3", "log", "@Changed 1", "@", "text",
378:                    "@[1] one changed", "[2] two", "[3] three", "[3.1]",
379:                    "[4] four", "[5] five", "@", "", "",
380:                    "1.2",
381:                    "log",
382:                    "@Added 3.1, deleted 6",
383:                    "@", // 50
384:                    "text", "@d1 1", "a1 1", "[1] one", "@", "", "",
385:                    "1.2.1.1",
386:                    "log",
387:                    "@Added 2.1, changed 4, added 5.1", //60
388:                    "@", "text", "@a2 1", "[2.1]", "d5 1", "a5 1",
389:                    "[4] four changed", "a6 1", "[5.1]",
390:                    "@", // 70
391:                    "", "", "1.1", "log", "@A simple test file", "@", "text",
392:                    "@d4 1", "a6 1", "[6] six", "@" };
393:
394:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.