1   package org.apache.maven.svnlib;
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.text.SimpleDateFormat;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Locale;
26  import java.util.TimeZone;
27  
28  import junit.framework.TestCase;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.maven.changelog.ChangeLogEntry;
33  
34  /**
35   * Test cases for {@link SvnChangeLogParser}.
36   * 
37   * @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
38   * @version $Id: SvnChangeLogParserTest.java 293395 2005-10-03 17:14:54Z
39   *          ltheussl $
40   */
41  public class SvnChangeLogParserTest extends TestCase {
42  
43  	private static final Log LOGGER = LogFactory
44  			.getLog(SvnChangeLogParserTest.class);
45  
46  	/** Date formatter */
47  	private static final SimpleDateFormat DATE = new SimpleDateFormat(
48  			"EEE MMM dd HH:mm:ss z yyyy", Locale.US);
49  
50  	/** The {@link SvnChangeLogParser} used for testing */
51  	private SvnChangeLogParser parser;
52  
53  	/** File with test results to check against */
54  	private String testFile;
55  
56  	/**
57  	 * Create a test with the given name.
58  	 * 
59  	 * @param testName
60  	 *            the name of the test.
61  	 */
62  	public SvnChangeLogParserTest(String testName) {
63  		super(testName);
64  	}
65  
66  	/**
67  	 * Initialize per test data.
68  	 * 
69  	 * @throws Exception
70  	 *             when there is an unexpected problem.
71  	 */
72  	public void setUp() throws Exception {
73  		String baseDir = System.getProperty("basedir");
74  		assertNotNull("The system property basedir was not defined.", baseDir);
75  		testFile = baseDir + "/src/test-resources/svnlib/svnlog.txt";
76  		parser = new SvnChangeLogParser();
77  	}
78  
79  	/**
80  	 * Test the subversion parser.
81  	 * 
82  	 * @throws Exception
83  	 *             when there is an unexpected problem
84  	 */
85  	public void testParse() throws Exception {
86  		FileInputStream fis = new FileInputStream(testFile);
87  		List entries = new ArrayList(parser.parse(fis));
88  
89  		assertEquals("Wrong number of entries returned", 14, entries.size());
90  
91  		ChangeLogEntry entry = (ChangeLogEntry) entries.get(0);
92  		assertEquals("Entry 0 was parsed incorrectly", "kaz\n"
93  				+ DATE.parse("Mon Aug 26 20:33:26 -0400 2002") + "\n"
94  				+ "[/poolserver/trunk/build.xml, 16, "
95  				+ "/poolserver/trunk/project.properties, 16]\n"
96  				+ "Minor formatting changes.\n\n", entry.toString());
97  		/* check author with space was parsed correctly */
98  		entry = (ChangeLogEntry) entries.get(1);
99  		assertEquals("Entry 0 was parsed incorrectly", "kaz toto", entry
100 				.getAuthor());
101 
102 		entry = (ChangeLogEntry) entries.get(7);
103 		assertEquals("Entry 6 was parsed incorrectly", "(no author)\n"
104 				+ DATE.parse("Fri Aug 23 11:11:52 -0400 2002") + "\n"
105 				+ "[/poolserver/trunk/build.xml, 9]\n"
106 				+ "Testing script out again ...\n\n", entry.toString());
107 
108 		entry = (ChangeLogEntry) entries.get(9);
109 		assertEquals(
110 				"Entry 8 was parsed incorrectly",
111 				"pete\n"
112 						+ DATE.parse("Fri Aug 23 11:03:39 -0400 2002")
113 						+ "\n"
114 						+ "[/poolserver/trunk/build.xml, 7]\n"
115 						+ "Reformatted the indentation (really just an excuse to test out\n"
116 						+ "subversion).\n\n", entry.toString());
117 
118 		entry = (ChangeLogEntry) entries.get(13);
119 		assertEquals("Entry 12 was parsed incorrectly", "DOMAIN\\user\n"
120 				+ DATE.parse("Wed Aug 21 00:20:25 -0400 2002") + "\n"
121 				+ "[/poolserver/trunk/build.xml, 1]\n"
122 				+ "Cleaned up some whitespace.\n\n", entry.toString());
123 	}
124 }