James Moger
2012-10-01 eb1405f736f2f98e14215774dd53eea9b9a77017
commit | author | age
2a7306 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.tests;
17
7e8873 18 import static org.junit.Assert.assertEquals;
JM 19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertTrue;
23
2a7306 24 import java.io.File;
JM 25 import java.io.FileOutputStream;
2f1c77 26 import java.text.SimpleDateFormat;
a125cf 27 import java.util.Arrays;
2a7306 28 import java.util.Date;
JM 29 import java.util.List;
a125cf 30 import java.util.Map;
2a7306 31
a125cf 32 import org.eclipse.jgit.diff.DiffEntry.ChangeType;
2a7306 33 import org.eclipse.jgit.lib.Constants;
a125cf 34 import org.eclipse.jgit.lib.FileMode;
JM 35 import org.eclipse.jgit.lib.ObjectId;
36 import org.eclipse.jgit.lib.PersonIdent;
2a7306 37 import org.eclipse.jgit.lib.Repository;
168566 38 import org.eclipse.jgit.lib.RepositoryCache.FileKey;
2a7306 39 import org.eclipse.jgit.revwalk.RevCommit;
ae9e15 40 import org.eclipse.jgit.revwalk.RevTree;
168566 41 import org.eclipse.jgit.util.FS;
a2709d 42 import org.eclipse.jgit.util.FileUtils;
7e8873 43 import org.junit.Test;
2a7306 44
7e8873 45 import com.gitblit.Constants.SearchType;
f1720c 46 import com.gitblit.GitBlit;
a125cf 47 import com.gitblit.Keys;
4ab184 48 import com.gitblit.models.GitNote;
a125cf 49 import com.gitblit.models.PathModel;
1f9dae 50 import com.gitblit.models.PathModel.PathChangeModel;
JM 51 import com.gitblit.models.RefModel;
2a7306 52 import com.gitblit.utils.JGitUtils;
4ab184 53 import com.gitblit.utils.StringUtils;
2a7306 54
7e8873 55 public class JGitUtilsTest {
a125cf 56
7e8873 57     @Test
a125cf 58     public void testDisplayName() throws Exception {
7e8873 59         assertEquals("Napoleon Bonaparte",
JM 60                 JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")));
61         assertEquals("<someone@somewhere.com>",
62                 JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")));
63         assertEquals("Napoleon Bonaparte <someone@somewhere.com>",
64                 JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte",
65                         "someone@somewhere.com")));
a125cf 66     }
2a7306 67
7e8873 68     @Test
2a7306 69     public void testFindRepositories() {
0adceb 70         List<String> list = JGitUtils.getRepositoryList(null, false, true, -1, null);
7e8873 71         assertEquals(0, list.size());
0adceb 72         list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1, null));
7e8873 73         assertEquals(0, list.size());
0adceb 74         list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null));
2a7306 75         assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);
JM 76     }
77
7e8873 78     @Test
0adceb 79     public void testFindExclusions() {
JM 80         List<String> list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null);
81         assertTrue("Missing jgit repository?!", list.contains("test/jgit.git"));
82
83         list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/jgit\\.git"));
84         assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
85
86         list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/*"));
87         assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
88
bb55f5 89         list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList(".*jgit.*"));
0adceb 90         assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
JM 91         assertFalse("Repository exclusion failed!", list.contains("working/jgit"));
92         assertFalse("Repository exclusion failed!", list.contains("working/jgit2"));
93
94     }
95
96     @Test
2a7306 97     public void testOpenRepository() throws Exception {
JM 98         Repository repository = GitBlitSuite.getHelloworldRepository();
99         repository.close();
7e8873 100         assertNotNull("Could not find repository!", repository);
2a7306 101     }
JM 102
7e8873 103     @Test
2a7306 104     public void testFirstCommit() throws Exception {
7e8873 105         assertEquals(new Date(0), JGitUtils.getFirstChange(null, null));
a125cf 106
2a7306 107         Repository repository = GitBlitSuite.getHelloworldRepository();
JM 108         RevCommit commit = JGitUtils.getFirstCommit(repository, null);
db653a 109         Date firstChange = JGitUtils.getFirstChange(repository, null);
2a7306 110         repository.close();
7e8873 111         assertNotNull("Could not get first commit!", commit);
JM 112         assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
113                 commit.getName());
db653a 114         assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
f1720c 115     }
a125cf 116
7e8873 117     @Test
f1720c 118     public void testLastCommit() throws Exception {
4fea45 119         assertEquals(new Date(0), JGitUtils.getLastChange(null));
a125cf 120
f1720c 121         Repository repository = GitBlitSuite.getHelloworldRepository();
JM 122         assertTrue(JGitUtils.getCommit(repository, null) != null);
4fea45 123         Date date = JGitUtils.getLastChange(repository);
f1720c 124         repository.close();
7e8873 125         assertNotNull("Could not get last repository change date!", date);
f1720c 126     }
JM 127
7e8873 128     @Test
f1720c 129     public void testCreateRepository() throws Exception {
JM 130         String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
008322 131         for (String repositoryName : repositories) {
f1720c 132             Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
168566 133                     repositoryName);
008322 134             File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
JM 135                     FS.DETECTED);
7e8873 136             assertNotNull(repository);
f1720c 137             assertFalse(JGitUtils.hasCommits(repository));
7e8873 138             assertNull(JGitUtils.getFirstCommit(repository, null));
JM 139             assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
140                     .getTime());
4fea45 141             assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
7e8873 142             assertNull(JGitUtils.getCommit(repository, null));
f1720c 143             repository.close();
JM 144             assertTrue(GitBlit.self().deleteRepository(repositoryName));
145         }
2a7306 146     }
JM 147
7e8873 148     @Test
28d6b2 149     public void testRefs() throws Exception {
4ab184 150         Repository repository = GitBlitSuite.getJGitRepository();
JM 151         Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
a125cf 152         repository.close();
JM 153         assertTrue(map.size() > 0);
4ab184 154         for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {
JM 155             List<RefModel> list = entry.getValue();
156             for (RefModel ref : list) {
157                 if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
7e8873 158                     assertEquals("refs/tags/spearce-gpg-pub", ref.toString());
JM 159                     assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId()
160                             .getName());
161                     assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());
4ab184 162                     assertTrue(ref.getShortMessage().startsWith("GPG key"));
008322 163                     assertTrue(ref.getFullMessage().startsWith("GPG key"));
7e8873 164                     assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());
4ab184 165                 } else if (ref.displayName.equals("refs/tags/v0.12.1")) {
JM 166                     assertTrue(ref.isAnnotatedTag());
167                 }
168             }
169         }
a125cf 170     }
JM 171
7e8873 172     @Test
a125cf 173     public void testBranches() throws Exception {
168566 174         Repository repository = GitBlitSuite.getJGitRepository();
85c2e6 175         assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
5cc4f2 176         for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
28d6b2 177             assertTrue(model.getName().startsWith(Constants.R_HEADS));
JM 178             assertTrue(model.equals(model));
179             assertFalse(model.equals(""));
4ab184 180             assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
28d6b2 181                     + model.getName().hashCode());
4ab184 182             assertTrue(model.getShortMessage().equals(model.getShortMessage()));
28d6b2 183         }
5cc4f2 184         for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) {
28d6b2 185             assertTrue(model.getName().startsWith(Constants.R_REMOTES));
JM 186             assertTrue(model.equals(model));
187             assertFalse(model.equals(""));
4ab184 188             assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
28d6b2 189                     + model.getName().hashCode());
4ab184 190             assertTrue(model.getShortMessage().equals(model.getShortMessage()));
28d6b2 191         }
168566 192         assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
a125cf 193         repository.close();
JM 194     }
195
7e8873 196     @Test
a125cf 197     public void testTags() throws Exception {
168566 198         Repository repository = GitBlitSuite.getJGitRepository();
85c2e6 199         assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);
5cc4f2 200         for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
168566 201             if (model.getObjectId().getName().equals("d28091fb2977077471138fe97da1440e0e8ae0da")) {
28d6b2 202                 assertTrue("Not an annotated tag!", model.isAnnotatedTag());
JM 203             }
204             assertTrue(model.getName().startsWith(Constants.R_TAGS));
205             assertTrue(model.equals(model));
206             assertFalse(model.equals(""));
4ab184 207             assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
28d6b2 208                     + model.getName().hashCode());
4ab184 209         }
JM 210         repository.close();
008322 211
d3065f 212         repository = GitBlitSuite.getGitectiveRepository();
5cc4f2 213         for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
d3065f 214             if (model.getObjectId().getName().equals("035254295a9bba11f72b1f9d6791a6b957abee7b")) {
4ab184 215                 assertFalse(model.isAnnotatedTag());
d3065f 216                 assertTrue(model.getAuthorIdent().getEmailAddress().equals("kevinsawicki@gmail.com"));
JM 217                 assertEquals("Add scm and issue tracker elements to pom.xml\n", model.getFullMessage());
4ab184 218             }
28d6b2 219         }
JM 220         repository.close();
221     }
222
7e8873 223     @Test
a125cf 224     public void testCommitNotes() throws Exception {
4ab184 225         Repository repository = GitBlitSuite.getJGitRepository();
JM 226         RevCommit commit = JGitUtils.getCommit(repository,
227                 "690c268c793bfc218982130fbfc25870f292295e");
228         List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
229         repository.close();
230         assertTrue(list.size() > 0);
7e8873 231         assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef
JM 232                 .getReferencedObjectId().getName());
2a7306 233     }
90b8d7 234     
JM 235     @Test
236     public void testRelinkHEAD() throws Exception {
237         Repository repository = GitBlitSuite.getJGitRepository();
238         // confirm HEAD is master
239         String currentRef = JGitUtils.getHEADRef(repository);
240         assertEquals("refs/heads/master", currentRef);
241         List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository);
242         assertTrue(availableHeads.size() > 0);
243         
244         // set HEAD to stable-1.2
245         JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2");
246         currentRef = JGitUtils.getHEADRef(repository);
247         assertEquals("refs/heads/stable-1.2", currentRef);
248
249         // restore HEAD to master
250         JGitUtils.setHEADtoRef(repository, "refs/heads/master");
251         currentRef = JGitUtils.getHEADRef(repository);
252         assertEquals("refs/heads/master", currentRef);
253         
254         repository.close();
255     }
2a7306 256
7e8873 257     @Test
f96d32 258     public void testRelinkBranch() throws Exception {
JM 259         Repository repository = GitBlitSuite.getJGitRepository();
260         
261         // create/set the branch
262         JGitUtils.setBranchRef(repository, "refs/heads/reftest", "3b358ce514ec655d3ff67de1430994d8428cdb04");
263         assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")).size());
264         assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")));
265         
266         // reset the branch
267         JGitUtils.setBranchRef(repository, "refs/heads/reftest", "755dfdb40948f5c1ec79e06bde3b0a78c352f27f");
268         assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")));
269         assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")).size());
270
271         // delete the branch
272         assertTrue(JGitUtils.deleteBranchRef(repository, "refs/heads/reftest"));
273         repository.close();
274     }
275
276     @Test
a2709d 277     public void testCreateOrphanedBranch() throws Exception {
671c19 278         Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");
a2709d 279         assertTrue(JGitUtils.createOrphanBranch(repository,
7b0895 280                 "x" + Long.toHexString(System.currentTimeMillis()).toUpperCase(), null));
JM 281          FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
a2709d 282     }
JM 283
7e8873 284     @Test
a125cf 285     public void testStringContent() throws Exception {
2a7306 286         Repository repository = GitBlitSuite.getHelloworldRepository();
ae9e15 287         String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
2a7306 288         RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
4ab184 289         String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
JM 290         String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
291
292         // manually construct a blob, calculate the hash, lookup the hash in git
293         StringBuilder sb = new StringBuilder();
294         sb.append("blob ").append(contentA.length()).append('\0');
295         sb.append(contentA);
296         String sha1 = StringUtils.getSHA1(sb.toString());
297         String contentD = JGitUtils.getStringContent(repository, sha1);
2a7306 298         repository.close();
a125cf 299         assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
JM 300         assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
301         assertTrue(contentA.equals(contentB));
7e8873 302         assertNull(contentC);
4ab184 303         assertTrue(contentA.equals(contentD));
2a7306 304     }
JM 305
7e8873 306     @Test
2a7306 307     public void testFilesInCommit() throws Exception {
JM 308         Repository repository = GitBlitSuite.getHelloworldRepository();
309         RevCommit commit = JGitUtils.getCommit(repository,
310                 "1d0c2933a4ae69c362f76797d42d6bd182d05176");
311         List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
a125cf 312
JM 313         commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
314         List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
315
316         commit = JGitUtils.getFirstCommit(repository, null);
317         List<PathChangeModel> additions = JGitUtils.getFilesInCommit(repository, commit);
318
319         List<PathChangeModel> latestChanges = JGitUtils.getFilesInCommit(repository, null);
320
2a7306 321         repository.close();
JM 322         assertTrue("No changed paths found!", paths.size() == 1);
28d6b2 323         for (PathChangeModel path : paths) {
JM 324             assertTrue("PathChangeModel hashcode incorrect!",
325                     path.hashCode() == (path.commitId.hashCode() + path.path.hashCode()));
326             assertTrue("PathChangeModel equals itself failed!", path.equals(path));
327             assertFalse("PathChangeModel equals string failed!", path.equals(""));
328         }
7e8873 329         assertEquals(ChangeType.DELETE, deletions.get(0).changeType);
JM 330         assertEquals(ChangeType.ADD, additions.get(0).changeType);
a125cf 331         assertTrue(latestChanges.size() > 0);
JM 332     }
333
7e8873 334     @Test
a125cf 335     public void testFilesInPath() throws Exception {
7e8873 336         assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());
a125cf 337         Repository repository = GitBlitSuite.getHelloworldRepository();
JM 338         List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);
339         repository.close();
340         assertTrue(files.size() > 10);
341     }
342
7e8873 343     @Test
a125cf 344     public void testDocuments() throws Exception {
JM 345         Repository repository = GitBlitSuite.getTicgitRepository();
346         List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);
347         List<PathModel> markdownDocs = JGitUtils.getDocuments(repository, extensions);
348         List<PathModel> markdownDocs2 = JGitUtils.getDocuments(repository,
349                 Arrays.asList(new String[] { ".mkd", ".md" }));
350         List<PathModel> allFiles = JGitUtils.getDocuments(repository, null);
351         repository.close();
352         assertTrue(markdownDocs.size() > 0);
353         assertTrue(markdownDocs2.size() > 0);
354         assertTrue(allFiles.size() > markdownDocs.size());
355     }
356
7e8873 357     @Test
a125cf 358     public void testFileModes() throws Exception {
7e8873 359         assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));
JM 360         assertEquals("-rw-r--r--",
361                 JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));
362         assertEquals("-rwxr-xr-x",
363                 JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
364         assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
45f5f2 365         assertEquals("submodule", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
7e8873 366         assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
a125cf 367     }
JM 368
7e8873 369     @Test
a125cf 370     public void testRevlog() throws Exception {
85c2e6 371         assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
a125cf 372         List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
2f1c77 373         assertEquals(0, commits.size());
a125cf 374
JM 375         Repository repository = GitBlitSuite.getHelloworldRepository();
376         // get most recent 10 commits
377         commits = JGitUtils.getRevLog(repository, 10);
2f1c77 378         assertEquals(10, commits.size());
a125cf 379
JM 380         // test paging and offset by getting the 10th most recent commit
381         RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);
2f1c77 382         assertEquals(lastCommit, commits.get(9));
a125cf 383
JM 384         // grab the two most recent commits to java.java
385         commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
2f1c77 386         assertEquals(2, commits.size());
7e8873 387
2f1c77 388         // grab the commits since 2008-07-15
7e8873 389         commits = JGitUtils.getRevLog(repository, null,
JM 390                 new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
2f1c77 391         assertEquals(12, commits.size());
a125cf 392         repository.close();
JM 393     }
394
7e8873 395     @Test
f47590 396     public void testRevLogRange() throws Exception {
JM 397         Repository repository = GitBlitSuite.getHelloworldRepository();
398         List<RevCommit> commits = JGitUtils.getRevLog(repository,
399                 "fbd14fa6d1a01d4aefa1fca725792683800fc67e",
400                 "85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
401         repository.close();
402         assertEquals(14, commits.size());
403     }
404
405     @Test
a125cf 406     public void testSearchTypes() throws Exception {
7e8873 407         assertEquals(SearchType.COMMIT, SearchType.forName("commit"));
JM 408         assertEquals(SearchType.COMMITTER, SearchType.forName("committer"));
409         assertEquals(SearchType.AUTHOR, SearchType.forName("author"));
410         assertEquals(SearchType.COMMIT, SearchType.forName("unknown"));
a125cf 411
7e8873 412         assertEquals("commit", SearchType.COMMIT.toString());
JM 413         assertEquals("committer", SearchType.COMMITTER.toString());
414         assertEquals("author", SearchType.AUTHOR.toString());
a125cf 415     }
JM 416
7e8873 417     @Test
a125cf 418     public void testSearchRevlogs() throws Exception {
7e8873 419         assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());
JM 420         List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0,
a125cf 421                 3);
7e8873 422         assertEquals(0, results.size());
a125cf 423
JM 424         // test commit message search
425         Repository repository = GitBlitSuite.getHelloworldRepository();
7e8873 426         results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);
JM 427         assertEquals(3, results.size());
a125cf 428
JM 429         // test author search
7e8873 430         results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);
JM 431         assertEquals(1, results.size());
a125cf 432
JM 433         // test committer search
7e8873 434         results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);
JM 435         assertEquals(10, results.size());
a125cf 436
JM 437         // test paging and offset
7e8873 438         RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER,
a125cf 439                 9, 1).get(0);
7e8873 440         assertEquals(results.get(9), commit);
a125cf 441
JM 442         repository.close();
2a7306 443     }
JM 444
7e8873 445     @Test
2a7306 446     public void testZip() throws Exception {
a125cf 447         assertFalse(JGitUtils.zip(null, null, null, null));
2a7306 448         Repository repository = GitBlitSuite.getHelloworldRepository();
a125cf 449         File zipFileA = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
JM 450         FileOutputStream fosA = new FileOutputStream(zipFileA);
451         boolean successA = JGitUtils.zip(repository, null, Constants.HEAD, fosA);
452         fosA.close();
453
454         File zipFileB = new File(GitBlitSuite.REPOSITORIES, "helloworld-java.zip");
455         FileOutputStream fosB = new FileOutputStream(zipFileB);
456         boolean successB = JGitUtils.zip(repository, "java.java", Constants.HEAD, fosB);
457         fosB.close();
458
2a7306 459         repository.close();
a125cf 460         assertTrue("Failed to generate zip file!", successA);
JM 461         assertTrue(zipFileA.length() > 0);
462         zipFileA.delete();
463
464         assertTrue("Failed to generate zip file!", successB);
465         assertTrue(zipFileB.length() > 0);
466         zipFileB.delete();
2a7306 467     }
a2709d 468
2a7306 469 }