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