1   package org.apache.maven.perforcelib;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.io.FileInputStream;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import junit.framework.TestCase;
26  import org.apache.maven.changelog.ChangeLogEntry;
27  import org.apache.maven.changelog.ChangeLog;
28  
29  /**
30   * Test cases for {@link PerforceChangeLogParser}
31   * @author <a href="mailto:jim@crossleys.org">Jim Crossley</a>
32   * @version $Id: 
33   */
34  public class PerforceChangeLogParserTest extends TestCase
35  {
36      /** The {@link PerforceChangeLogParser} used for testing */
37      private PerforceChangeLogParser parser;
38  
39      /** File with test results to check against */
40      private String testFile;
41  
42      /**
43       * Create a test with the given name.
44       *
45       * @param testName the name of the test.
46       */
47      public PerforceChangeLogParserTest(String testName)
48      {
49          super(testName);
50      }
51  
52      /**
53       * Initialize per test data.
54       *
55       * @throws Exception when there is an unexpected problem.
56       */
57      public void setUp() throws Exception
58      {
59          String baseDir = System.getProperty("basedir");
60          assertNotNull("The system property basedir was not defined.", baseDir);
61          testFile = baseDir + "/src/test-resources/perforcelib/perforcelog.txt";
62          parser = new PerforceChangeLogParser();
63          ChangeLog changeLog = new ChangeLog();
64          changeLog.setRepositoryConnection ("scm:perforce://depot/test/...");
65          parser.init (changeLog);
66      }
67  
68      /**
69       * Test the Perforce parser.
70       *
71       * @throws Exception when there is an unexpected problem
72       */
73      public void testParse() throws Exception
74      {
75          FileInputStream fis = new FileInputStream(testFile);
76          List entries = new ArrayList(parser.parse(fis));
77  
78          assertEquals("Wrong number of entries returned", 7, entries.size());
79  
80          ChangeLogEntry entry = (ChangeLogEntry) entries.get(0);
81          assertEquals("Entry 0 was parsed incorrectly", 
82                       "\t<changelog-entry>\n" +
83                       "\t\t<date>2003-10-15</date>\n" +
84                       "\t\t<time>13:38:40</time>\n" +
85                       "\t\t<author><![CDATA[jim]]></author>\n" +
86                       "\t\t<file>\n" +
87                       "\t\t\t<name>junk/linefeed.txt</name>\n" +
88                       "\t\t\t<revision>3</revision>\n" +
89                       "\t\t</file>\n" +
90                       "\t\t<msg><![CDATA[	Where's my change #\n" +
91                       "]]></msg>\n" +
92                       "\t</changelog-entry>\n",
93                       entry.toXML());
94  
95          entry = (ChangeLogEntry) entries.get(3);
96          assertEquals("Entry 3 was parsed incorrectly", 
97                       "\t<changelog-entry>\n" +
98                       "\t\t<date>2003-10-01</date>\n" +
99                       "\t\t<time>16:24:20</time>\n" +
100                      "\t\t<author><![CDATA[jim]]></author>\n" +
101                      "\t\t<file>\n" +
102                      "\t\t\t<name>demo/demo.c</name>\n" +
103                      "\t\t\t<revision>4</revision>\n" +
104                      "\t\t</file>\n" +
105                      "\t\t<msg><![CDATA[	Backing out my test changes\n" +
106                      "\t\n" +
107                      "\tUpdating a description\n" +
108                      "]]></msg>\n" +
109                      "\t</changelog-entry>\n",
110                      entry.toXML());
111 
112         entry = (ChangeLogEntry) entries.get(6);
113         assertEquals("Entry 6 was parsed incorrectly", 
114                      "\t<changelog-entry>\n" +
115                      "\t\t<date>2003-08-07</date>\n" +
116                      "\t\t<time>17:21:57</time>\n" +
117                      "\t\t<author><![CDATA[mcronin]]></author>\n" +
118                      "\t\t<file>\n" +
119                      "\t\t\t<name>demo/demo.c</name>\n" +
120                      "\t\t\t<revision>1</revision>\n" +
121                      "\t\t</file>\n" +
122                      "\t\t<file>\n" +
123                      "\t\t\t<name>demo/dictcalls.txt</name>\n" +
124                      "\t\t\t<revision>1</revision>\n" +
125                      "\t\t</file>\n" +
126                      "\t\t<file>\n" +
127                      "\t\t\t<name>demo/dictwords.txt</name>\n" +
128                      "\t\t\t<revision>1</revision>\n" +
129                      "\t\t</file>\n" +
130                      "\t\t<msg><![CDATA[	demonstration of Perforce on Windows, Unix and VMS.\n" +
131                      "]]></msg>\n" +
132                      "\t</changelog-entry>\n",
133                      entry.toXML());
134     }
135 }