Ver código fonte

Merge branch 'chirontt-external_repos_zipped' into master.

tags/r1.9.0
Florian Zschocke 5 anos atrás
pai
commit
e57a8461c0

+ 5
- 0
build.xml Ver arquivo

--> -->
<target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests"> <target name="test" depends="compile" description="compiles Gitblit from source and runs unit tests">
<!-- Generate the HelloworldKeys class from the hello-world.properties file -->
<mx:keys propertiesfile="${basedir}/src/test/data/hello-world.properties"
outputclass="com.gitblit.tests.HelloworldKeys"
todir="${basedir}/src/test/java" />
<!-- Compile unit tests --> <!-- Compile unit tests -->
<mx:javac scope="test" /> <mx:javac scope="test" />

+ 1
- 0
src/test/data/.gitignore Ver arquivo

/*.git/

BIN
src/test/data/ambition.git.zip Ver arquivo


BIN
src/test/data/gitective.git.zip Ver arquivo


BIN
src/test/data/hello-world.git.zip Ver arquivo


+ 9
- 0
src/test/data/hello-world.properties Ver arquivo

commit.first=192cdede1cc81da7b393aeb7aba9f88998b04713
commit.second=8caad51
commit.fifth=55f6796044dc51f0bb9301f07920f0fb64c3d12c
commit.fifteen=5ebfaca
commit.added=192cded
commit.changed=b2c50ce
commit.deleted=8613bee10bde27a0fbaca66447cdc3f0f9483365
users.byEmail=9
users.byName=8

BIN
src/test/data/ticgit.git.zip Ver arquivo


+ 1
- 0
src/test/java/com/gitblit/tests/.gitignore Ver arquivo

/HelloworldKeys.java

+ 11
- 11
src/test/java/com/gitblit/tests/DiffUtilsTest.java Ver arquivo

public void testParentCommitDiff() throws Exception { public void testParentCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testArbitraryCommitDiff() throws Exception { public void testArbitraryCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testPlainFileDiff() throws Exception { public void testPlainFileDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content; String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close(); repository.close();
assertTrue(diff != null && diff.length() > 0); assertTrue(diff != null && diff.length() > 0);
public void testFilePatch() throws Exception { public void testFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java"); String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testArbitraryFilePatch() throws Exception { public void testArbitraryFilePatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java"); String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testArbitraryCommitPatch() throws Exception { public void testArbitraryCommitPatch() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, RevCommit baseCommit = JGitUtils.getCommit(repository,
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first));
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null); String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
repository.close(); repository.close();
assertTrue(patch != null && patch.length() > 0); assertTrue(patch != null && patch.length() > 0);
public void testBlame() throws Exception { public void testBlame() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java", List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second));
repository.close(); repository.close();
assertTrue(lines.size() > 0); assertTrue(lines.size() > 0);
assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
assertEquals(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first), lines.get(0).commitId);
} }
} }

+ 41
- 11
src/test/java/com/gitblit/tests/FederationTests.java Ver arquivo

*/ */
package com.gitblit.tests; package com.gitblit.tests;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
String password = GitBlitSuite.password; String password = GitBlitSuite.password;
String token = "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c"; String token = "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c";
//test data
static final String testUser = "test";
static final String testUserPwd = "whocares";
static final String testTeam = "testteam";
static final String testTeamRepository = "helloworld.git";
private static final AtomicBoolean started = new AtomicBoolean(false); private static final AtomicBoolean started = new AtomicBoolean(false);
@BeforeClass @BeforeClass
@AfterClass @AfterClass
public static void stopGitblit() throws Exception { public static void stopGitblit() throws Exception {
//clean up test user and team if left over
deleteTestUser();
deleteTestTeam();
if (started.get()) { if (started.get()) {
GitBlitSuite.stopGitblit(); GitBlitSuite.stopGitblit();
} }
} }
private static void deleteTestUser() throws IOException {
UserModel user = new UserModel(testUser);
user.password = testUserPwd;
RpcUtils.deleteUser(user, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
}
private static void deleteTestTeam() throws IOException {
TeamModel team = new TeamModel(testTeam);
team.addRepositoryPermission(testTeamRepository);
RpcUtils.deleteTeam(team, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
}
@Test @Test
public void testProposal() throws Exception { public void testProposal() throws Exception {
// create dummy repository data // create dummy repository data
@Test @Test
public void testPullUsers() throws Exception { public void testPullUsers() throws Exception {
//clean up test user and team left over from previous run, if any
deleteTestUser();
deleteTestTeam();
List<UserModel> users = FederationUtils.getUsers(getRegistration()); List<UserModel> users = FederationUtils.getUsers(getRegistration());
assertNotNull(users); assertNotNull(users);
// admin is excluded
assertEquals(0, users.size());
// admin is excluded, hence there should be no other users in the list
assertEquals("Gitblit server still contains " + users + " user account(s).", 0, users.size());
UserModel newUser = new UserModel("test");
newUser.password = "whocares";
UserModel newUser = new UserModel(testUser);
newUser.password = testUserPwd;
assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray())); assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray()));
TeamModel team = new TeamModel("testteam");
team.addUser("test");
team.addRepositoryPermission("helloworld.git");
TeamModel team = new TeamModel(testTeam);
team.addUser(testUser);
team.addRepositoryPermission(testTeamRepository);
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray())); assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
users = FederationUtils.getUsers(getRegistration()); users = FederationUtils.getUsers(getRegistration());
assertEquals(1, users.size()); assertEquals(1, users.size());
newUser = users.get(0); newUser = users.get(0);
assertTrue(newUser.isTeamMember("testteam"));
assertTrue(newUser.isTeamMember(testTeam));
assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray())); assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray()));
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray())); assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray()));
@Test @Test
public void testPullTeams() throws Exception { public void testPullTeams() throws Exception {
TeamModel team = new TeamModel("testteam");
team.addUser("test");
team.addRepositoryPermission("helloworld.git");
//clean up test team left over from previous run, if any
deleteTestTeam();
TeamModel team = new TeamModel(testTeam);
team.addUser(testUser);
team.addRepositoryPermission(testTeamRepository);
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray())); assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));
List<TeamModel> teams = FederationUtils.getTeams(getRegistration()); List<TeamModel> teams = FederationUtils.getTeams(getRegistration());

+ 89
- 5
src/test/java/com/gitblit/tests/GitBlitSuite.java Ver arquivo

package com.gitblit.tests; package com.gitblit.tests;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import com.gitblit.FileSettings;
import com.gitblit.GitBlitException; import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer; import com.gitblit.GitBlitServer;
import com.gitblit.manager.IRepositoryManager; import com.gitblit.manager.IRepositoryManager;
public static final File USERSCONF = new File("src/test/config/test-users.conf"); public static final File USERSCONF = new File("src/test/config/test-users.conf");
private static final File AMBITION_REPO_SOURCE = new File("src/test/data/ambition.git");
private static final File TICGIT_REPO_SOURCE = new File("src/test/data/ticgit.git");
private static final File GITECTIVE_REPO_SOURCE = new File("src/test/data/gitective.git");
private static final File HELLOWORLD_REPO_SOURCE = new File("src/test/data/hello-world.git");
private static final File HELLOWORLD_REPO_PROPERTIES = new File("src/test/data/hello-world.properties");
public static final FileSettings helloworldSettings = new FileSettings(HELLOWORLD_REPO_PROPERTIES.getAbsolutePath());
static int port = 8280; static int port = 8280;
static int gitPort = 8300; static int gitPort = 8300;
static int shutdownPort = 8281; static int shutdownPort = 8281;
Thread.sleep(5000); Thread.sleep(5000);
} }
public static void deleteRefChecksFolder() throws IOException {
File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks");
if (refChecks.exists()) {
FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
}
}
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
//"refchecks" folder is used in GitServletTest;
//need be deleted before Gitblit server instance is started
deleteRefChecksFolder();
startGitblit(); startGitblit();
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) { if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
cloneOrFetch("ticgit.git", "https://github.com/schacon/ticgit.git");
if (!HELLOWORLD_REPO_SOURCE.exists()) {
unzipRepository(HELLOWORLD_REPO_SOURCE.getPath() + ".zip", HELLOWORLD_REPO_SOURCE.getParentFile());
}
if (!TICGIT_REPO_SOURCE.exists()) {
unzipRepository(TICGIT_REPO_SOURCE.getPath() + ".zip", TICGIT_REPO_SOURCE.getParentFile());
}
if (!AMBITION_REPO_SOURCE.exists()) {
unzipRepository(AMBITION_REPO_SOURCE.getPath() + ".zip", AMBITION_REPO_SOURCE.getParentFile());
}
if (!GITECTIVE_REPO_SOURCE.exists()) {
unzipRepository(GITECTIVE_REPO_SOURCE.getPath() + ".zip", GITECTIVE_REPO_SOURCE.getParentFile());
}
cloneOrFetch("helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("ticgit.git", TICGIT_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git"); cloneOrFetch("test/jgit.git", "https://github.com/eclipse/jgit.git");
cloneOrFetch("test/helloworld.git", "https://github.com/git/hello-world.git");
cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
cloneOrFetch("test/gitective.git", "https://github.com/kevinsawicki/gitective.git");
cloneOrFetch("test/helloworld.git", HELLOWORLD_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/ambition.git", AMBITION_REPO_SOURCE.getAbsolutePath());
cloneOrFetch("test/gitective.git", GITECTIVE_REPO_SOURCE.getAbsolutePath());
showRemoteBranches("ticgit.git"); showRemoteBranches("ticgit.git");
automaticallyTagBranchTips("ticgit.git"); automaticallyTagBranchTips("ticgit.git");
r.close(); r.close();
} }
} }
private static void unzipRepository(String zippedRepo, File destDir) throws IOException {
System.out.print("Unzipping " + zippedRepo + "... ");
if (!destDir.exists()) {
destDir.mkdir();
}
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(new FileInputStream(zippedRepo));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
File newFile = newFile(destDir, zipEntry);
if (zipEntry.isDirectory()) {
newFile.mkdirs();
}
else {
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
System.out.println("done.");
}
private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
//guards against writing files to the file system outside of the target folder
//to prevent Zip Slip exploit
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
return destFile;
}
} }

+ 11
- 8
src/test/java/com/gitblit/tests/GitServletTest.java Ver arquivo

@BeforeClass @BeforeClass
public static void startGitblit() throws Exception { public static void startGitblit() throws Exception {
//"refchecks" folder is used in this test class;
//need be deleted before Gitblit server instance is started
GitBlitSuite.deleteRefChecksFolder();
started.set(GitBlitSuite.startGitblit()); started.set(GitBlitSuite.startGitblit());
delete(getUser()); delete(getUser());
public static void deleteWorkingFolders() throws Exception { public static void deleteWorkingFolders() throws Exception {
if (ticgitFolder.exists()) { if (ticgitFolder.exists()) {
GitBlitSuite.close(ticgitFolder); GitBlitSuite.close(ticgitFolder);
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE);
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
if (ticgit2Folder.exists()) { if (ticgit2Folder.exists()) {
GitBlitSuite.close(ticgit2Folder); GitBlitSuite.close(ticgit2Folder);
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
if (jgitFolder.exists()) { if (jgitFolder.exists()) {
GitBlitSuite.close(jgitFolder); GitBlitSuite.close(jgitFolder);
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE);
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
if (jgit2Folder.exists()) { if (jgit2Folder.exists()) {
GitBlitSuite.close(jgit2Folder); GitBlitSuite.close(jgit2Folder);
FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE);
FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
} }
// fork from original to a temporary bare repo // fork from original to a temporary bare repo
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git"); File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");
if (verification.exists()) { if (verification.exists()) {
FileUtils.delete(verification, FileUtils.RECURSIVE);
FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
CloneCommand clone = Git.cloneRepository(); CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
// fork from original to a temporary bare repo // fork from original to a temporary bare repo
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git"); File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");
if (verification.exists()) { if (verification.exists()) {
FileUtils.delete(verification, FileUtils.RECURSIVE);
FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
CloneCommand clone = Git.cloneRepository(); CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
// fork from original to a temporary bare repo // fork from original to a temporary bare repo
File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName); File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);
if (refChecks.exists()) { if (refChecks.exists()) {
FileUtils.delete(refChecks, FileUtils.RECURSIVE);
FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
CloneCommand clone = Git.cloneRepository(); CloneCommand clone = Git.cloneRepository();
clone.setURI(url + "/" + originName); clone.setURI(url + "/" + originName);
// clone temp bare repo to working copy // clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, workingCopy); File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);
if (local.exists()) { if (local.exists()) {
FileUtils.delete(local, FileUtils.RECURSIVE);
FileUtils.delete(local, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
clone = Git.cloneRepository(); clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/{1}", url, model.name)); clone.setURI(MessageFormat.format("{0}/{1}", url, model.name));

+ 23
- 23
src/test/java/com/gitblit/tests/GroovyScriptTest.java Ver arquivo

MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.customFields = new HashMap<String,String>(); repository.customFields = new HashMap<String,String>();
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git"); repository.mailingLists.add("list@helloworld.git");
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master2"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master2"));
RepositoryModel repository = repositories().getRepositoryModel("helloworld.git"); RepositoryModel repository = repositories().getRepositoryModel("helloworld.git");
repository.mailingLists.add("list@helloworld.git"); repository.mailingLists.add("list@helloworld.git");
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/tags/v1.0"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId ReceiveCommand command = new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/master"); "refs/heads/master");
commands.add(command); commands.add(command);
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/heads/other")); "refs/heads/other"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
ReceiveCommand command = new ReceiveCommand(ObjectId ReceiveCommand command = new ReceiveCommand(ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(),
"refs/tags/v1.0"); "refs/tags/v1.0");
commands.add(command); commands.add(command);
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
MockClientLogger clientLogger = new MockClientLogger(); MockClientLogger clientLogger = new MockClientLogger();
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
commands.add(new ReceiveCommand(ObjectId commands.add(new ReceiveCommand(ObjectId
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId
.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());

+ 2
- 2
src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java Ver arquivo

public void testAuthenticationManager() public void testAuthenticationManager()
{ {
MS.put(KEY_SUPPORT_PLAINTEXT_PWD, "true"); MS.put(KEY_SUPPORT_PLAINTEXT_PWD, "true");
UserModel user = auth.authenticate("user1", "pass1".toCharArray(), null);
UserModel user = auth.authenticate("user1", "#externalAccount".toCharArray(), null);
assertNotNull(user); assertNotNull(user);
assertEquals("user1", user.username); assertEquals("user1", user.username);


user = auth.authenticate("user2", "pass2".toCharArray(), null);
user = auth.authenticate("user2", "#externalAccount".toCharArray(), null);
assertNotNull(user); assertNotNull(user);
assertEquals("user2", user.username); assertEquals("user2", user.username);



+ 6
- 5
src/test/java/com/gitblit/tests/JGitUtilsTest.java Ver arquivo

Date firstChange = JGitUtils.getFirstChange(repository, null); Date firstChange = JGitUtils.getFirstChange(repository, null);
repository.close(); repository.close();
assertNotNull("Could not get first commit!", commit); assertNotNull("Could not get first commit!", commit);
assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
assertEquals("Incorrect first commit!",
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.first),
commit.getName()); commit.getName());
assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L))); assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
} }
public void testFilesInCommit() throws Exception { public void testFilesInCommit() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getCommit(repository, RevCommit commit = JGitUtils.getCommit(repository,
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit); List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
commit = JGitUtils.getCommit(repository, GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted));
List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit); List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
commit = JGitUtils.getFirstCommit(repository, null); commit = JGitUtils.getFirstCommit(repository, null);
public void testRevLogRange() throws Exception { public void testRevLogRange() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository(); Repository repository = GitBlitSuite.getHelloworldRepository();
List<RevCommit> commits = JGitUtils.getRevLog(repository, List<RevCommit> commits = JGitUtils.getRevLog(repository,
"fbd14fa6d1a01d4aefa1fca725792683800fc67e",
"85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.second),
GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifteen));
repository.close(); repository.close();
assertEquals(14, commits.size()); assertEquals(14, commits.size());
} }

+ 5
- 4
src/test/java/com/gitblit/tests/JsonUtilsTest.java Ver arquivo

import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
@Test @Test
public void testSerialization() { public void testSerialization() {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new LinkedHashMap<String, String>();
//LinkedHashMap preserves the order of insertion
map.put("a", "alligator"); map.put("a", "alligator");
map.put("b", "bear"); map.put("b", "bear");
map.put("c", "caterpillar"); map.put("c", "caterpillar");
map.put("e", "eagle"); map.put("e", "eagle");
String json = JsonUtils.toJsonString(map); String json = JsonUtils.toJsonString(map);
assertEquals( assertEquals(
"{\"d\":\"dingo\",\"e\":\"eagle\",\"b\":\"bear\",\"c\":\"caterpillar\",\"a\":\"alligator\"}",
"{\"a\":\"alligator\",\"b\":\"bear\",\"c\":\"caterpillar\",\"d\":\"dingo\",\"e\":\"eagle\"}",
json); json);
Map<String, String> map2 = JsonUtils.fromJsonString(json, Map<String, String> map2 = JsonUtils.fromJsonString(json,
new TypeToken<Map<String, String>>() { new TypeToken<Map<String, String>>() {
Date date = new Date(); Date date = new Date();
String name = "myJson"; String name = "myJson";
} }
}
}

+ 2
- 2
src/test/java/com/gitblit/tests/MetricUtilsTest.java Ver arquivo

List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true); List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);
List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false); List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);
repository.close(); repository.close();
assertEquals("No author metrics found!", 9, byEmail.size());
assertEquals("No author metrics found!", 8, byName.size());
assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byEmail, -1), byEmail.size());
assertEquals("No author metrics found!", GitBlitSuite.helloworldSettings.getInteger(HelloworldKeys.users.byName, -1), byName.size());
} }
} }

+ 0
- 41
src/test/java/com/gitblit/tests/PushLogTest.java Ver arquivo

/*
* Copyright 2013 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.tests;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
import org.junit.Test;
import com.gitblit.models.RefLogEntry;
import com.gitblit.utils.RefLogUtils;
public class PushLogTest extends GitblitUnitTest {
@Test
public void testPushLog() throws IOException {
String name = "~james/helloworld.git";
File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository);
GitBlitSuite.close(repository);
}
}

+ 13
- 2
src/test/java/com/gitblit/tests/RpcTests.java Ver arquivo

@AfterClass @AfterClass
public static void stopGitblit() throws Exception { public static void stopGitblit() throws Exception {
//clean up the "A-Team" if left over
TeamModel aTeam = new TeamModel("A-Team");
aTeam.addRepositoryPermission("helloworld.git");
RpcUtils.deleteTeam(aTeam, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
if (started.get()) { if (started.get()) {
GitBlitSuite.stopGitblit(); GitBlitSuite.stopGitblit();
} }
@Test @Test
public void testTeamAdministration() throws IOException { public void testTeamAdministration() throws IOException {
//clean up the "A-Team" left over from previous run, if any
TeamModel aTeam = new TeamModel("A-Team");
aTeam.addRepositoryPermission("helloworld.git");
RpcUtils.deleteTeam(aTeam, url, account, password.toCharArray());
List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray()); List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray());
assertEquals(1, teams.size());
//should be just the admins team
assertEquals("In addition to 'admins', too many left-over team(s) in Gitblit server: " + teams, 1, teams.size());
// Create the A-Team // Create the A-Team
TeamModel aTeam = new TeamModel("A-Team");
aTeam = new TeamModel("A-Team");
aTeam.users.add("admin"); aTeam.users.add("admin");
aTeam.addRepositoryPermission("helloworld.git"); aTeam.addRepositoryPermission("helloworld.git");
assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray())); assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray()));

+ 19
- 2
src/test/java/com/gitblit/tests/TicketReferenceTest.java Ver arquivo

*/ */
public class TicketReferenceTest extends GitblitUnitTest { public class TicketReferenceTest extends GitblitUnitTest {


static final String repoName = "TicketReferenceTest.git";
static File workingCopy = new File(GitBlitSuite.REPOSITORIES, "working/TicketReferenceTest.git-wc"); static File workingCopy = new File(GitBlitSuite.REPOSITORIES, "working/TicketReferenceTest.git-wc");
static ITicketService ticketService; static ITicketService ticketService;
@BeforeClass @BeforeClass
public static void configure() throws Exception { public static void configure() throws Exception {
File repositoryName = new File("TicketReferenceTest.git");;
File repositoryName = new File(repoName);
GitBlitSuite.close(repositoryName); GitBlitSuite.close(repositoryName);
if (repositoryName.exists()) { if (repositoryName.exists()) {
FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY); FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
} }
repo = new RepositoryModel("TicketReferenceTest.git", null, null, null);
repo = new RepositoryModel(repoName, null, null, null);
if (gitblit().hasRepository(repo.name)) { if (gitblit().hasRepository(repo.name)) {
gitblit().deleteRepositoryModel(repo); gitblit().deleteRepositoryModel(repo);
@AfterClass @AfterClass
public static void cleanup() throws Exception { public static void cleanup() throws Exception {
//clean up the test user account if left over
if (gitblit().getUserModel(user.username) != null) {
gitblit().deleteUser(user.username);
}

GitBlitSuite.close(git); GitBlitSuite.close(git);

//clean up the TicketReferenceTest.git repo
File repositoryName = new File(repoName);
GitBlitSuite.close(repositoryName);
if (repositoryName.exists()) {
FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY);
}
RepositoryModel repo = new RepositoryModel(repoName, null, null, null);
if (gitblit().hasRepository(repo.name)) {
gitblit().deleteRepositoryModel(repo);
}
} }
@Test @Test

+ 4
- 2
src/test/java/com/gitblit/tests/TicketServiceTest.java Ver arquivo

import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.bouncycastle.util.Arrays; import org.bouncycastle.util.Arrays;
import org.eclipse.jgit.util.FileUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
protected IStoredSettings getSettings(boolean deleteAll) throws Exception { protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
File dir = new File(GitBlitSuite.REPOSITORIES, getRepository().name); File dir = new File(GitBlitSuite.REPOSITORIES, getRepository().name);
if (deleteAll) { if (deleteAll) {
FileUtils.deleteDirectory(dir);
if (dir.exists()) {
FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, getRepository().name).close(); JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, getRepository().name).close();
} }

+ 17
- 18
src/test/java/com/gitblit/tests/UITicketTest.java Ver arquivo

package com.gitblit.tests; package com.gitblit.tests;


import java.io.File; import java.io.File;
import java.util.Date;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


import org.apache.commons.io.FileUtils;
import org.bouncycastle.util.Arrays;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FileUtils;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;


import com.gitblit.manager.RepositoryManager; import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager; import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager; import com.gitblit.manager.UserManager;
import com.gitblit.models.Mailing;
import com.gitblit.models.RepositoryModel; import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel; import com.gitblit.models.TicketModel;
import com.gitblit.models.TicketModel.Attachment;
import com.gitblit.models.TicketModel.Change; import com.gitblit.models.TicketModel.Change;
import com.gitblit.models.TicketModel.Field; import com.gitblit.models.TicketModel.Field;
import com.gitblit.models.TicketModel.Patchset;
import com.gitblit.models.TicketModel.Priority; import com.gitblit.models.TicketModel.Priority;
import com.gitblit.models.TicketModel.Severity; import com.gitblit.models.TicketModel.Severity;
import com.gitblit.models.TicketModel.Status;
import com.gitblit.models.TicketModel.Type; import com.gitblit.models.TicketModel.Type;
import com.gitblit.tests.mock.MemorySettings; import com.gitblit.tests.mock.MemorySettings;
import com.gitblit.tickets.ITicketService; import com.gitblit.tickets.ITicketService;
import com.gitblit.tickets.ITicketService.TicketFilter;
import com.gitblit.tickets.QueryResult;
import com.gitblit.tickets.TicketIndexer.Lucene;
import com.gitblit.tickets.BranchTicketService; import com.gitblit.tickets.BranchTicketService;
import com.gitblit.tickets.TicketLabel;
import com.gitblit.tickets.TicketMilestone;
import com.gitblit.tickets.TicketNotifier;
import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.XssFilter; import com.gitblit.utils.XssFilter;
import com.gitblit.utils.XssFilter.AllowXssFilter; import com.gitblit.utils.XssFilter.AllowXssFilter;
public class UITicketTest extends GitblitUnitTest { public class UITicketTest extends GitblitUnitTest {


private ITicketService service; private ITicketService service;
final String repoName = "UITicketTest.git";
static final String repoName = "UITicketTest.git";
final RepositoryModel repo = new RepositoryModel(repoName, null, null, null); final RepositoryModel repo = new RepositoryModel(repoName, null, null, null);
protected ITicketService getService(boolean deleteAll) throws Exception { protected ITicketService getService(boolean deleteAll) throws Exception {
protected IStoredSettings getSettings(boolean deleteAll) throws Exception { protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
File dir = new File(GitBlitSuite.REPOSITORIES, repoName); File dir = new File(GitBlitSuite.REPOSITORIES, repoName);
if (deleteAll) { if (deleteAll) {
FileUtils.deleteDirectory(dir);
if (dir.exists()) {
FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repoName).close(); JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repoName).close();
} }
return settings; return settings;
} }


@AfterClass
public static void deleteUITicketTestRepo() throws IOException {
//delete the UITicketTest.git folder, at end of the test
File dir = new File(GitBlitSuite.REPOSITORIES, repoName);
if (dir.exists()) {
FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
}

@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
service = getService(true); service = getService(true);
return change; return change;
} }


}
}

Carregando…
Cancelar
Salvar