1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.git.script

File GitScriptServiceTest.java

 

Code metrics

0
26
3
1
113
65
3
0.12
8.67
3
1

Classes

Class Line # Actions
GitScriptServiceTest 47 26 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link org.xwiki.git.script.GitScriptService}.
42    *
43    * @version $Id: 7c02b9025d4da51cab7497ec4c1b05d10dd86d17 $
44    * @since 4.2M1
45    */
46    @AllComponents
 
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   
 
58  2 toggle @Before
59    public void setupRepository() throws Exception
60    {
61    // Configure permanent directory to be the temporary directory
62  2 StandardEnvironment environment = this.componentManager.getInstance(Environment.class);
63  2 environment.setPermanentDirectory(environment.getTemporaryDirectory());
64  2 GitHelper gitHelper = new GitHelper(environment);
65   
66    // Delete repositories
67  2 FileUtils.deleteDirectory(gitHelper.getRepositoryFile(TEST_REPO_ORIG));
68  2 FileUtils.deleteDirectory(gitHelper.getRepositoryFile(TEST_REPO_CLONED));
69   
70    // Create a Git repository for the test
71  2 this.testRepository = gitHelper.createGitTestRepository(TEST_REPO_ORIG).getDirectory();
72   
73    // Add a file so that we can test querying the test repository for more fun!
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   
 
78  1 toggle @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   
 
97  1 toggle @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    // 1 author
106  1 Assert.assertEquals(1, commits.length);
107    // 1 commit
108  1 Assert.assertEquals(1, commits[0].getCount());
109    // Verify user name and emai
110  1 Assert.assertEquals("test author", commits[0].getName());
111  1 Assert.assertEquals("author@doe.com", commits[0].getEmail());
112    }
113    }