/
RhodeCodeTest.java
120 lines (103 loc) · 5.02 KB
/
RhodeCodeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package hudson.plugins.git.browser;
import hudson.model.Run;
import hudson.plugins.git.GitChangeLogParser;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitChangeSet.Path;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Test;
import org.xml.sax.SAXException;
public class RhodeCodeTest {
private static final String RHODECODE_URL = "https://SERVER/r/PROJECT";
private final RhodeCode rhodecode = new RhodeCode(RHODECODE_URL);
/**
* Test method for {@link hudson.plugins.git.browser.RhodeCode#getUrl()}.
* @throws MalformedURLException
*/
@Test
public void testGetUrl() throws IOException {
assertEquals(String.valueOf(rhodecode.getUrl()), RHODECODE_URL + "/");
}
/**
* Test method for {@link hudson.plugins.git.browser.RhodeCode#getUrl()}.
* @throws MalformedURLException
*/
@Test
public void testGetUrlForRepoWithTrailingSlash() throws IOException {
assertEquals(String.valueOf(new RhodeCode(RHODECODE_URL + "/").getUrl()), RHODECODE_URL + "/");
}
/**
* Test method for {@link hudson.plugins.git.browser.RhodeCode#getChangeSetLink(hudson.plugins.git.GitChangeSet)}.
* @throws SAXException
* @throws IOException
*/
@Test
public void testGetChangeSetLinkGitChangeSet() throws IOException, SAXException {
final URL changeSetLink = rhodecode.getChangeSetLink(createChangeSet("rawchangelog"));
assertEquals(RHODECODE_URL + "/changeset/396fc230a3db05c427737aa5c2eb7856ba72b05d", changeSetLink.toString());
}
/**
* Test method for {@link hudson.plugins.git.browser.RhodeCode#getDiffLink(hudson.plugins.git.GitChangeSet.Path)}.
* @throws SAXException
* @throws IOException
*/
@Test
public void testGetDiffLinkPath() throws IOException, SAXException {
final HashMap<String, Path> pathMap = createPathMap("rawchangelog");
final Path modified1 = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
assertEquals(RHODECODE_URL + "/diff/src/main/java/hudson/plugins/git/browser/GithubWeb.java?diff2=f28f125f4cc3e5f6a32daee6a26f36f7b788b8ff&diff1=396fc230a3db05c427737aa5c2eb7856ba72b05d&diff=diff+to+revision", rhodecode.getDiffLink(modified1).toString());
// For added files returns a link to the commit.
final Path added = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
assertEquals(RHODECODE_URL + "/diff/src/main/java/hudson/plugins/git/browser/GithubWeb.java?diff2=f28f125f4cc3e5f6a32daee6a26f36f7b788b8ff&diff1=396fc230a3db05c427737aa5c2eb7856ba72b05d&diff=diff+to+revision", rhodecode.getDiffLink(added).toString());
}
/**
* Test method for {@link hudson.plugins.git.browser.GithubWeb#getFileLink(hudson.plugins.git.GitChangeSet.Path)}.
* @throws SAXException
* @throws IOException
*/
@Test
public void testGetFileLinkPath() throws IOException, SAXException {
final HashMap<String,Path> pathMap = createPathMap("rawchangelog");
final Path path = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
final URL fileLink = rhodecode.getFileLink(path);
assertEquals(RHODECODE_URL + "/files/396fc230a3db05c427737aa5c2eb7856ba72b05d/src/main/java/hudson/plugins/git/browser/GithubWeb.java", String.valueOf(fileLink));
}
/**
* Test method for {@link hudson.plugins.git.browser.GithubWeb#getFileLink(hudson.plugins.git.GitChangeSet.Path)}.
* @throws SAXException
* @throws IOException
*/
@Test
public void testGetFileLinkPathForDeletedFile() throws IOException, SAXException {
final HashMap<String,Path> pathMap = createPathMap("rawchangelog-with-deleted-file");
final Path path = pathMap.get("bar");
final URL fileLink = rhodecode.getFileLink(path);
assertEquals(RHODECODE_URL + "/files/b547aa10c3f06710c6fdfcdb2a9149c81662923b/bar", String.valueOf(fileLink));
}
private GitChangeSet createChangeSet(String rawchangelogpath) throws IOException, SAXException {
final File rawchangelog = new File(RhodeCodeTest.class.getResource(rawchangelogpath).getFile());
final GitChangeLogParser logParser = new GitChangeLogParser(false);
final List<GitChangeSet> changeSetList = logParser.parse((Run) null, null, rawchangelog).getLogs();
return changeSetList.get(0);
}
/**
* @param changelog
* @return
* @throws IOException
* @throws SAXException
*/
private HashMap<String, Path> createPathMap(final String changelog) throws IOException, SAXException {
final HashMap<String, Path> pathMap = new HashMap<String, Path>();
final Collection<Path> changeSet = createChangeSet(changelog).getPaths();
for (final Path path : changeSet) {
pathMap.put(path.getPath(), path);
}
return pathMap;
}
}