*/\r
package com.gitblit.tests;\r
\r
+import java.io.IOException;\r
import java.util.Date;\r
import java.util.HashMap;\r
import java.util.List;\r
String password = GitBlitSuite.password;\r
String token = "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c";\r
\r
+ //test data\r
+ static final String testUser = "test";\r
+ static final String testUserPwd = "whocares";\r
+ static final String testTeam = "testteam";\r
+ static final String testTeamRepository = "helloworld.git";\r
+\r
private static final AtomicBoolean started = new AtomicBoolean(false);\r
\r
@BeforeClass\r
\r
@AfterClass\r
public static void stopGitblit() throws Exception {\r
+ //clean up test user and team if left over\r
+ deleteTestUser();\r
+ deleteTestTeam();\r
+\r
if (started.get()) {\r
GitBlitSuite.stopGitblit();\r
}\r
}\r
\r
+ private static void deleteTestUser() throws IOException {\r
+ UserModel user = new UserModel(testUser);\r
+ user.password = testUserPwd;\r
+ RpcUtils.deleteUser(user, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray()); \r
+ }\r
+\r
+ private static void deleteTestTeam() throws IOException {\r
+ TeamModel team = new TeamModel(testTeam);\r
+ team.addRepositoryPermission(testTeamRepository);\r
+ RpcUtils.deleteTeam(team, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());\r
+ }\r
+\r
@Test\r
public void testProposal() throws Exception {\r
// create dummy repository data\r
\r
@Test\r
public void testPullUsers() throws Exception {\r
+ //clean up test user and team left over from previous run, if any\r
+ deleteTestUser();\r
+ deleteTestTeam();\r
+\r
List<UserModel> users = FederationUtils.getUsers(getRegistration());\r
assertNotNull(users);\r
- // admin is excluded\r
- assertEquals(0, users.size());\r
+ // admin is excluded, hence there should be no other users in the list\r
+ assertEquals("Gitblit server still contains " + users + " user account(s).", 0, users.size());\r
\r
- UserModel newUser = new UserModel("test");\r
- newUser.password = "whocares";\r
+ UserModel newUser = new UserModel(testUser);\r
+ newUser.password = testUserPwd;\r
assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray()));\r
\r
- TeamModel team = new TeamModel("testteam");\r
- team.addUser("test");\r
- team.addRepositoryPermission("helloworld.git");\r
+ TeamModel team = new TeamModel(testTeam);\r
+ team.addUser(testUser);\r
+ team.addRepositoryPermission(testTeamRepository);\r
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));\r
\r
users = FederationUtils.getUsers(getRegistration());\r
assertEquals(1, users.size());\r
\r
newUser = users.get(0);\r
- assertTrue(newUser.isTeamMember("testteam"));\r
+ assertTrue(newUser.isTeamMember(testTeam));\r
\r
assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray()));\r
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray()));\r
\r
@Test\r
public void testPullTeams() throws Exception {\r
- TeamModel team = new TeamModel("testteam");\r
- team.addUser("test");\r
- team.addRepositoryPermission("helloworld.git");\r
+ //clean up test team left over from previous run, if any\r
+ deleteTestTeam();\r
+\r
+ TeamModel team = new TeamModel(testTeam);\r
+ team.addUser(testUser);\r
+ team.addRepositoryPermission(testTeamRepository);\r
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray()));\r
\r
List<TeamModel> teams = FederationUtils.getTeams(getRegistration());\r
\r
@BeforeClass\r
public static void startGitblit() throws Exception {\r
+ //"refchecks" folder is used in this test class;\r
+ //need be deleted before Gitblit server instance is started\r
+ GitBlitSuite.deleteRefChecksFolder();\r
started.set(GitBlitSuite.startGitblit());\r
\r
delete(getUser());\r
public static void deleteWorkingFolders() throws Exception {\r
if (ticgitFolder.exists()) {\r
GitBlitSuite.close(ticgitFolder);\r
- FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE);\r
+ FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
if (ticgit2Folder.exists()) {\r
GitBlitSuite.close(ticgit2Folder);\r
- FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);\r
+ FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
if (jgitFolder.exists()) {\r
GitBlitSuite.close(jgitFolder);\r
- FileUtils.delete(jgitFolder, FileUtils.RECURSIVE);\r
+ FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
if (jgit2Folder.exists()) {\r
GitBlitSuite.close(jgit2Folder);\r
- FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE);\r
+ FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
}\r
\r
// fork from original to a temporary bare repo\r
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");\r
if (verification.exists()) {\r
- FileUtils.delete(verification, FileUtils.RECURSIVE);\r
+ FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));\r
// fork from original to a temporary bare repo\r
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git");\r
if (verification.exists()) {\r
- FileUtils.delete(verification, FileUtils.RECURSIVE);\r
+ FileUtils.delete(verification, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));\r
// fork from original to a temporary bare repo\r
File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);\r
if (refChecks.exists()) {\r
- FileUtils.delete(refChecks, FileUtils.RECURSIVE);\r
+ FileUtils.delete(refChecks, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
CloneCommand clone = Git.cloneRepository();\r
clone.setURI(url + "/" + originName);\r
// clone temp bare repo to working copy\r
File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);\r
if (local.exists()) {\r
- FileUtils.delete(local, FileUtils.RECURSIVE);\r
+ FileUtils.delete(local, FileUtils.RECURSIVE | FileUtils.RETRY);\r
}\r
clone = Git.cloneRepository();\r
clone.setURI(MessageFormat.format("{0}/{1}", url, model.name));\r
public void testAuthenticationManager()
{
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);
assertEquals("user1", user.username);
- user = auth.authenticate("user2", "pass2".toCharArray(), null);
+ user = auth.authenticate("user2", "#externalAccount".toCharArray(), null);
assertNotNull(user);
assertEquals("user2", user.username);
\r
import java.text.SimpleDateFormat;\r
import java.util.Date;\r
-import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
import java.util.Map;\r
\r
import org.junit.Test;\r
\r
@Test\r
public void testSerialization() {\r
- Map<String, String> map = new HashMap<String, String>();\r
+ Map<String, String> map = new LinkedHashMap<String, String>();\r
+ //LinkedHashMap preserves the order of insertion\r
map.put("a", "alligator");\r
map.put("b", "bear");\r
map.put("c", "caterpillar");\r
map.put("e", "eagle");\r
String json = JsonUtils.toJsonString(map);\r
assertEquals(\r
- "{\"d\":\"dingo\",\"e\":\"eagle\",\"b\":\"bear\",\"c\":\"caterpillar\",\"a\":\"alligator\"}",\r
+ "{\"a\":\"alligator\",\"b\":\"bear\",\"c\":\"caterpillar\",\"d\":\"dingo\",\"e\":\"eagle\"}",\r
json);\r
Map<String, String> map2 = JsonUtils.fromJsonString(json,\r
new TypeToken<Map<String, String>>() {\r
Date date = new Date();\r
String name = "myJson";\r
}\r
-}
\ No newline at end of file
+}\r
+++ /dev/null
-/*\r
- * Copyright 2013 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.tests;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.List;\r
-\r
-import org.eclipse.jgit.lib.Repository;\r
-import org.eclipse.jgit.lib.RepositoryCache.FileKey;\r
-import org.eclipse.jgit.storage.file.FileRepositoryBuilder;\r
-import org.eclipse.jgit.util.FS;\r
-import org.junit.Test;\r
-\r
-import com.gitblit.models.RefLogEntry;\r
-import com.gitblit.utils.RefLogUtils;\r
-\r
-public class PushLogTest extends GitblitUnitTest {\r
-\r
- @Test\r
- public void testPushLog() throws IOException {\r
- String name = "~james/helloworld.git";\r
- File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);\r
- Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();\r
- List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository);\r
- GitBlitSuite.close(repository);\r
- }\r
-}
\ No newline at end of file
\r
@AfterClass\r
public static void stopGitblit() throws Exception {\r
+ //clean up the "A-Team" if left over\r
+ TeamModel aTeam = new TeamModel("A-Team");\r
+ aTeam.addRepositoryPermission("helloworld.git");\r
+ RpcUtils.deleteTeam(aTeam, GitBlitSuite.url, GitBlitSuite.account, GitBlitSuite.password.toCharArray());\r
+\r
if (started.get()) {\r
GitBlitSuite.stopGitblit();\r
}\r
\r
@Test\r
public void testTeamAdministration() throws IOException {\r
+ //clean up the "A-Team" left over from previous run, if any\r
+ TeamModel aTeam = new TeamModel("A-Team");\r
+ aTeam.addRepositoryPermission("helloworld.git");\r
+ RpcUtils.deleteTeam(aTeam, url, account, password.toCharArray());\r
+\r
List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray());\r
- assertEquals(1, teams.size());\r
+ //should be just the admins team\r
+ assertEquals("In addition to 'admins', too many left-over team(s) in Gitblit server: " + teams, 1, teams.size());\r
\r
// Create the A-Team\r
- TeamModel aTeam = new TeamModel("A-Team");\r
+ aTeam = new TeamModel("A-Team");\r
aTeam.users.add("admin");\r
aTeam.addRepositoryPermission("helloworld.git");\r
assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray()));\r
*/
public class TicketReferenceTest extends GitblitUnitTest {
+ static final String repoName = "TicketReferenceTest.git";
static File workingCopy = new File(GitBlitSuite.REPOSITORIES, "working/TicketReferenceTest.git-wc");
static ITicketService ticketService;
@BeforeClass
public static void configure() throws Exception {
- File repositoryName = new File("TicketReferenceTest.git");;
+ File repositoryName = new File(repoName);
GitBlitSuite.close(repositoryName);
if (repositoryName.exists()) {
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)) {
gitblit().deleteRepositoryModel(repo);
@AfterClass
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);
+
+ //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
import java.util.List;\r
import java.util.Map;\r
\r
-import org.apache.commons.io.FileUtils;\r
import org.bouncycastle.util.Arrays;\r
+import org.eclipse.jgit.util.FileUtils;\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
protected IStoredSettings getSettings(boolean deleteAll) throws Exception {\r
File dir = new File(GitBlitSuite.REPOSITORIES, getRepository().name);\r
if (deleteAll) {\r
- FileUtils.deleteDirectory(dir);\r
+ if (dir.exists()) {\r
+ FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);\r
+ }\r
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, getRepository().name).close();\r
}\r
\r
package com.gitblit.tests;
import java.io.File;
-import java.util.Date;
+import java.io.IOException;
import java.util.HashMap;
-import java.util.List;
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.AfterClass;
import org.junit.Before;
import org.junit.Test;
import com.gitblit.manager.RepositoryManager;
import com.gitblit.manager.RuntimeManager;
import com.gitblit.manager.UserManager;
-import com.gitblit.models.Mailing;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel;
-import com.gitblit.models.TicketModel.Attachment;
import com.gitblit.models.TicketModel.Change;
import com.gitblit.models.TicketModel.Field;
-import com.gitblit.models.TicketModel.Patchset;
import com.gitblit.models.TicketModel.Priority;
import com.gitblit.models.TicketModel.Severity;
-import com.gitblit.models.TicketModel.Status;
import com.gitblit.models.TicketModel.Type;
import com.gitblit.tests.mock.MemorySettings;
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.TicketLabel;
-import com.gitblit.tickets.TicketMilestone;
-import com.gitblit.tickets.TicketNotifier;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.XssFilter;
import com.gitblit.utils.XssFilter.AllowXssFilter;
public class UITicketTest extends GitblitUnitTest {
private ITicketService service;
- final String repoName = "UITicketTest.git";
+ static final String repoName = "UITicketTest.git";
final RepositoryModel repo = new RepositoryModel(repoName, null, null, null);
protected ITicketService getService(boolean deleteAll) throws Exception {
protected IStoredSettings getSettings(boolean deleteAll) throws Exception {
File dir = new File(GitBlitSuite.REPOSITORIES, repoName);
if (deleteAll) {
- FileUtils.deleteDirectory(dir);
+ if (dir.exists()) {
+ FileUtils.delete(dir, FileUtils.RECURSIVE | FileUtils.RETRY);
+ }
JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repoName).close();
}
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
public void setup() throws Exception {
service = getService(true);
return change;
}
-}
\ No newline at end of file
+}