1 package org.apache.maven.mkslib;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import org.apache.maven.changelog.ChangeLog;
25 import org.apache.maven.changelog.ChangeLogEntry;
26
27 import java.io.FileInputStream;
28 import java.io.IOException;
29
30 import java.util.Collection;
31 import java.util.Date;
32 import java.util.Iterator;
33 import java.util.Locale;
34
35 /**
36 * This class test the mks parser with an inputstream.
37 *
38 * @author dion (writes CvsChangeLogParserTest)
39 * @author <a href="mailto:c.jerolimov@tarent.de">Christoph Jerolimov</a>
40 * @version $Id: MksChangeLogParserTest.java 532339 2007-04-25 12:28:56Z ltheussl $
41 */
42 public class MksChangeLogParserTest extends TestCase
43 {
44 /** the {link ChangeLog} used for testing */
45 private ChangeLog changeLog;
46
47 /** the {@link MksChangeLogParser} used for testing */
48 private MksChangeLogParser instance;
49
50 /** file with test results to check against */
51 private String testFile;
52
53 /**
54 * Create a test with the given name
55 * @param testName the name of the test
56 */
57 public MksChangeLogParserTest( String testName )
58 {
59 super( testName );
60 }
61
62 /**
63 * Initialize per test data
64 * @throws Exception when there is an unexpected problem
65 */
66 public void setUp() throws Exception
67 {
68
69
70 Locale.setDefault(Locale.GERMAN);
71 String baseDir = System.getProperty( "basedir" );
72 if (baseDir == null)
73 baseDir = "/home/christoph/workspace/changelog";
74
75 assertNotNull( "The system property basedir was not defined.", baseDir );
76 testFile = baseDir + "/src/test-resources/mkslib/mkslog.txt";
77
78 System.out.println(new Date());
79
80 changeLog = new ChangeLog();
81 changeLog.setType("date");
82 changeLog.setMarkerStart("2006-01-15");
83 changeLog.setMarkerEnd("2006-01-31");
84
85 instance = new MksChangeLogParser();
86 instance.init( changeLog );
87 }
88
89 /**
90 * Test the mks parser.
91 * @throws IOException when there is an unexpected problem
92 */
93 public void testParser()
94 throws IOException
95 {
96 FileInputStream fis = new FileInputStream( testFile );
97 Collection entries = instance.parse( fis );
98
99 assertEquals( "Wrong number of entries returned", 3, entries.size() );
100
101 ChangeLogEntry entry = null;
102
103 for ( Iterator i = entries.iterator(); i.hasNext(); )
104 {
105 entry = (ChangeLogEntry) i.next();
106 assertEquals( "Wrong author parsed", "AUTHOR", entry.getAuthor() );
107 System.out.println( entry );
108 assertTrue( "ChangeLogEntry erroneously picked up",
109 entry.toString().indexOf( "ChangeLogEntry.java" ) == -1 );
110 }
111 }
112 }