1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.statsvn.input;
21  
22  import java.util.Date;
23  import java.util.HashMap;
24  
25  import junit.framework.TestCase;
26  import net.sf.statcvs.model.Revision;
27  import net.sf.statcvs.model.VersionedFile;
28  
29  /**
30   * Tests for {@link FileBuilder}
31   * 
32   * @todo Add tests for all revision types
33   * 
34   * @author Richard Cyganiak <richard@cyganiak.de>
35   * @version $Id: FileBuilderTest.java,v 1.6 2005/03/29 22:45:06 cyganiak Exp $
36   */
37  public class FileBuilderTest extends TestCase {
38  	private FileBuilder fb;
39  
40  	private final DummyBuilder builder;
41  
42  	private final Date date1 = new Date(100000000);
43  
44  	private final Date date2 = new Date(200000000);
45  
46  	private final RevisionData rev1;
47  
48  	private final RevisionData rev1dead;
49  
50  	private final RevisionData rev1branch;
51  
52  	public FileBuilderTest(final String arg0) {
53  		super(arg0);
54  		builder = new DummyBuilder();
55  		rev1 = new RevisionData();
56  		rev1.setDate(date1);
57  		rev1.setRevisionNumber("1");
58  		rev1.setLoginName("author1");
59  		rev1.setComment("comment");
60  		rev1.setStateExp(true);
61  		rev1.setStateAdded(true);
62  		rev1dead = new RevisionData();
63  		rev1dead.setDate(date1);
64  		rev1dead.setRevisionNumber("1");
65  		rev1dead.setLoginName("author1");
66  		rev1dead.setComment("comment");
67  		rev1dead.setStateDead(true);
68  		rev1branch = new RevisionData();
69  		rev1branch.setDate(date2);
70  		rev1branch.setRevisionNumber("1121");
71  		rev1branch.setLoginName("author1");
72  		rev1branch.setComment("comment");
73  		rev1branch.setStateExp(true);
74  		rev1branch.setLines(100, 0);
75  	}
76  
77  	/*
78  	 * @see TestCase#setUp()
79  	 */
80  	protected void setUp() throws Exception {
81  		super.setUp();
82  	}
83  
84  	public void testCreation() throws Exception {
85  		initBuilder("file", false);
86  		fb.createFile(date1);
87  	}
88  
89  	public void testNotInLogTimespan() throws Exception {
90  		initBuilder("nolinecount", false);
91  		assertNull(fb.createFile(null));
92  	}
93  
94  	public void testSimple() throws Exception {
95  		initBuilder("file", false);
96  		fb.addRevisionData(rev1);
97  		final VersionedFile file = fb.createFile(date1);
98  		assertNotNull(file);
99  		assertEquals("file", file.getFilenameWithPath());
100 		assertEquals(builder.getDirectory("file"), file.getDirectory());
101 		assertEquals(1, file.getRevisions().size());
102 	}
103 
104 	public void testFileWithoutRevs() throws Exception {
105 		initBuilder("file", false);
106 		final VersionedFile file = fb.createFile(date1);
107 		assertNotNull(file);
108 		assertEquals(1, file.getRevisions().size());
109 		assertTrue(file.getInitialRevision().isBeginOfLog());
110 		assertEquals(100, file.getInitialRevision().getLines());
111 		assertEquals(new Date(date1.getTime() - 60000), file.getInitialRevision().getDate());
112 	}
113 
114 	public void testOneRev() throws Exception {
115 		initBuilder("file", false);
116 		fb.addRevisionData(rev1);
117 		final VersionedFile file = fb.createFile(date1);
118 		assertEquals(1, file.getRevisions().size());
119 		final Revision rev = file.getInitialRevision();
120 		assertEquals(date1, rev.getDate());
121 		assertEquals("1", rev.getRevisionNumber());
122 		assertEquals(builder.getAuthor("author1"), rev.getAuthor());
123 		assertEquals("comment", rev.getComment());
124 		assertEquals(100, rev.getLines());
125 		assertTrue(rev.isInitialRevision());
126 	}
127 
128 	// not relevant for SVN
129 	//	/**
130 	//	 * A file added only on a subbranch and not merged
131 	//	 * into the trunk must be ignored.
132 	//	 * @throws Exception
133 	//	 */
134 	//	public void testAddOnSubbranch() throws Exception {
135 	//		initBuilder("nolinecount", false);
136 	//		fb.addRevisionData(rev1dead);
137 	//		fb.addRevisionData(rev1branch);
138 	//		VersionedFile file = fb.createFile(date1);
139 	//		assertNull(file);
140 	//	}
141 
142 	//  not relevant for SVN    
143 	//	public void testIgnoreRevisionsOnBranches() throws Exception {
144 	//		initBuilder("file", false);
145 	//		fb.addRevisionData(rev1);
146 	//		fb.addRevisionData(rev1branch);
147 	//		VersionedFile file = fb.createFile(date1);
148 	//		assertEquals(1, file.getRevisions().size());
149 	//		assertEquals("1.1", file.getInitialRevision().getRevisionNumber());
150 	//	}
151 
152 	private void initBuilder(final String filename, final boolean isBinary) {
153 		fb = new FileBuilder(builder, filename, isBinary, new HashMap(), new HashMap());
154 	}
155 }