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