1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.git.script; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import org.apache.commons.io.FileUtils; |
26 |
|
import org.eclipse.jgit.api.Git; |
27 |
|
import org.eclipse.jgit.lib.PersonIdent; |
28 |
|
import org.eclipse.jgit.lib.Repository; |
29 |
|
import org.gitective.core.CommitFinder; |
30 |
|
import org.gitective.core.filter.commit.CommitCountFilter; |
31 |
|
import org.gitective.core.stat.UserCommitActivity; |
32 |
|
import org.junit.*; |
33 |
|
import org.xwiki.environment.Environment; |
34 |
|
import org.xwiki.environment.internal.StandardEnvironment; |
35 |
|
import org.xwiki.git.GitHelper; |
36 |
|
import org.xwiki.script.service.ScriptService; |
37 |
|
import org.xwiki.test.ComponentManagerRule; |
38 |
|
import org.xwiki.test.annotation.AllComponents; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@AllComponents |
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 3 |
Complexity Density: 0.12 |
|
47 |
|
public class GitScriptServiceTest |
48 |
|
{ |
49 |
|
private static final String TEST_REPO_ORIG = "test-repo-orig"; |
50 |
|
|
51 |
|
private static final String TEST_REPO_CLONED = "test-repo-cloned"; |
52 |
|
|
53 |
|
@Rule |
54 |
|
public ComponentManagerRule componentManager = new ComponentManagerRule(); |
55 |
|
|
56 |
|
private File testRepository; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
58 |
2 |
@Before... |
59 |
|
public void setupRepository() throws Exception |
60 |
|
{ |
61 |
|
|
62 |
2 |
StandardEnvironment environment = this.componentManager.getInstance(Environment.class); |
63 |
2 |
environment.setPermanentDirectory(environment.getTemporaryDirectory()); |
64 |
2 |
GitHelper gitHelper = new GitHelper(environment); |
65 |
|
|
66 |
|
|
67 |
2 |
FileUtils.deleteDirectory(gitHelper.getRepositoryFile(TEST_REPO_ORIG)); |
68 |
2 |
FileUtils.deleteDirectory(gitHelper.getRepositoryFile(TEST_REPO_CLONED)); |
69 |
|
|
70 |
|
|
71 |
2 |
this.testRepository = gitHelper.createGitTestRepository(TEST_REPO_ORIG).getDirectory(); |
72 |
|
|
73 |
|
|
74 |
2 |
gitHelper.add(testRepository, "test.txt", "test content", new PersonIdent("test author", "author@doe.com"), |
75 |
|
new PersonIdent("test committer", "committer@doe.com"), "first commit"); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
public void getRepositoryAndFindAuthors() throws Exception |
80 |
|
{ |
81 |
1 |
GitScriptService service = this.componentManager.getInstance(ScriptService.class, "git"); |
82 |
1 |
Repository repository = service.getRepository(this.testRepository.getAbsolutePath(), TEST_REPO_CLONED); |
83 |
1 |
Assert.assertEquals(true, new Git(repository).pull().call().isSuccessful()); |
84 |
|
|
85 |
1 |
CommitFinder finder = new CommitFinder(repository); |
86 |
1 |
CommitCountFilter count = new CommitCountFilter(); |
87 |
1 |
finder.setMatcher(count); |
88 |
1 |
finder.find(); |
89 |
|
|
90 |
1 |
Assert.assertEquals(1, count.getCount()); |
91 |
|
|
92 |
1 |
Set<PersonIdent> authors = service.findAuthors(repository); |
93 |
1 |
Assert.assertEquals(1, authors.size()); |
94 |
1 |
Assert.assertEquals("test author", authors.iterator().next().getName()); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void getCountCommits() throws Exception |
99 |
|
{ |
100 |
1 |
GitScriptService service = this.componentManager.getInstance(ScriptService.class, "git"); |
101 |
1 |
Repository repository = service.getRepository(this.testRepository.getAbsolutePath(), TEST_REPO_CLONED); |
102 |
1 |
Assert.assertEquals(true, new Git(repository).pull().call().isSuccessful()); |
103 |
|
|
104 |
1 |
UserCommitActivity[] commits = service.countAuthorCommits(1, repository); |
105 |
|
|
106 |
1 |
Assert.assertEquals(1, commits.length); |
107 |
|
|
108 |
1 |
Assert.assertEquals(1, commits[0].getCount()); |
109 |
|
|
110 |
1 |
Assert.assertEquals("test author", commits[0].getName()); |
111 |
1 |
Assert.assertEquals("author@doe.com", commits[0].getEmail()); |
112 |
|
} |
113 |
|
} |