1 package org.apache.maven.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import junit.framework.TestCase;
20 import org.apache.maven.scm.command.changelog.ChangeLogSet;
21 import org.apache.maven.scm.ChangeSet;
22 import org.apache.maven.scm.ChangeFile;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.InputStream;
27 import java.util.List;
28 import java.util.Calendar;
29
30 /**
31 * @author Edwin Punzalan
32 */
33 public class ChangeLogTest
34 extends TestCase
35 {
36 public void testReadFile()
37 throws Exception
38 {
39 List changedLogs = readChangeLogXml( "min-changelog.xml" );
40
41 assertNotNull( "Test changedSets were parsed", changedLogs );
42
43 assertEquals( "Test number of changelog entries", 2, changedLogs.size() );
44
45 ChangeLogSet changelogSets = (ChangeLogSet) changedLogs.get( 0 );
46
47 assertEquals( "Test number of revisions on changelog 1", 2, changelogSets.getChangeSets().size() );
48
49 ChangeSet changeSet = (ChangeSet) changelogSets.getChangeSets().get( 0 );
50
51
52 Calendar cal = Calendar.getInstance();
53
54 cal.set( 1977, 7, 6, 5, 30, 0);
55
56 cal.set( Calendar.MILLISECOND, 0);
57
58
59 assertEquals( "Test changelog 1 set 1 date/time", cal.getTime().getTime(), changeSet.getDate().getTime() );
60
61 assertEquals( "Test changelog 1 set 1 author", "Edwin Punzalan", changeSet.getAuthor() );
62
63 assertEquals( "Test changelog 1 set 1 msg", "First commit msg", changeSet.getComment() );
64
65 assertEquals( "Test changelog 1 set 1 files", 1, changeSet.getFiles().size() );
66
67 ChangeFile changeFile = (ChangeFile) changeSet.getFiles().get( 0 );
68
69 assertEquals( "Test changelog 1 set 1 file 1 filename", "/path/to/file.extension", changeFile.getName() );
70
71 assertEquals( "Test changelog 1 set 1 file 1 revision", "1", changeFile.getRevision() );
72
73
74 changeSet = (ChangeSet) changelogSets.getChangeSets().get( 1 );
75
76 cal.set( 2005, 1, 24, 21, 30, 0 );
77
78 assertEquals( "Test changelog 1 set 2 date/time", cal.getTime().getTime(), changeSet.getDate().getTime() );
79
80 assertEquals( "Test changelog 1 set 2 author", "Edwin Punzalan", changeSet.getAuthor() );
81
82 assertEquals( "Test changelog 1 set 2 msg", "Second commit msg", changeSet.getComment() );
83
84 assertEquals( "Test changelog 1 set 2 files", 2, changeSet.getFiles().size() );
85
86 changeFile = (ChangeFile) changeSet.getFiles().get( 0 );
87
88 assertEquals( "Test changelog 1 set 2 file 1 filename", "/path/to/file.extension", changeFile.getName() );
89
90 assertEquals( "Test changelog 1 set 2 file 1 revision", "2", changeFile.getRevision() );
91
92 changeFile = (ChangeFile) changeSet.getFiles().get( 1 );
93
94 assertEquals( "Test changelog 1 set 2 file 2 filename", "/path/to/file2.extension", changeFile.getName() );
95
96 assertEquals( "Test changelog 1 set 2 file 2 revision", "2", changeFile.getRevision() );
97
98
99
100 changelogSets = (ChangeLogSet) changedLogs.get( 1 );
101
102 assertEquals( "Test number of revisions on changelog 2", 2, changelogSets.getChangeSets().size() );
103
104 changeSet = (ChangeSet) changelogSets.getChangeSets().get( 0 );
105
106 cal.set( 2005, 1, 25, 22, 45, 0 );
107
108 assertEquals( "Test changelog 2 set 1 date/time", cal.getTime().getTime(), changeSet.getDate().getTime() );
109
110 assertEquals( "Test changelog 2 set 1 author", "Keogh Edrich Punzalan", changeSet.getAuthor() );
111
112 assertEquals( "Test changelog 2 set 1 msg", "Third commit msg", changeSet.getComment() );
113
114 assertEquals( "Test changelog 2 set 1 files", 1, changeSet.getFiles().size() );
115
116 changeFile = (ChangeFile) changeSet.getFiles().get( 0 );
117
118 assertEquals( "Test changelog 2 set 1 file 1 filename", "/path/to/file.extension", changeFile.getName() );
119
120 assertEquals( "Test changelog 2 set 1 file 1 revision", "3", changeFile.getRevision() );
121
122
123 changeSet = (ChangeSet) changelogSets.getChangeSets().get( 1 );
124
125 cal.set( 2100, 1, 25, 5, 30, 0 );
126
127 assertEquals( "Test changelog 2 set 2 date/time", cal.getTime().getTime(), changeSet.getDate().getTime() );
128
129 assertEquals( "Test changelog 2 set 2 author", "Keogh Edrich Punzalan", changeSet.getAuthor() );
130
131 assertEquals( "Test changelog 2 set 2 msg", "Last commit msg", changeSet.getComment() );
132
133 assertEquals( "Test changelog 2 set 2 files", 2, changeSet.getFiles().size() );
134
135 changeFile = (ChangeFile) changeSet.getFiles().get( 0 );
136
137 assertEquals( "Test changelog 2 set 2 file 1 filename", "/path/to/file.extension", changeFile.getName() );
138
139 assertEquals( "Test changelog 2 set 2 file 1 revision", "4", changeFile.getRevision() );
140
141 changeFile = (ChangeFile) changeSet.getFiles().get( 1 );
142
143 assertEquals( "Test changelog 2 set 2 file 2 filename", "/path/to/file2.extension", changeFile.getName() );
144
145 assertEquals( "Test changelog 2 set 2 file 2 revision", "4", changeFile.getRevision() );
146 }
147
148 private List readChangeLogXml( String filename )
149 throws Exception
150 {
151 File inputFile = new File( getBasedir(), "src/test/changelog-xml/" + filename );
152 InputStream in = new FileInputStream( inputFile );
153
154 return ChangeLog.loadChangedSets( in );
155 }
156
157 private String getBasedir()
158 {
159 return System.getProperty( "basedir" );
160 }
161 }