]> source.dussan.org Git - gitblit.git/commitdiff
Fix for various test failures.
authorchirontt <chirontt@chirontt.org>
Sun, 28 Apr 2019 19:51:21 +0000 (15:51 -0400)
committerFlorian Zschocke <florian.zschocke@devolo.de>
Fri, 7 Jun 2019 11:57:47 +0000 (13:57 +0200)
Most of failures were due to temporary test repos, users and/or teams
being left behind after the test run, and these left-over stuff in
$baseFolder/data/git caused assertion errors in many tests in subsequent
test runs. This fix tries to delete those left-over stuff at the end of
each test, mainly in their @Afterclass code blocks.

PushLogTest.java is deleted as it doesn't work, and has been superseded
with better tests in various protocol test suites (GitServletTest,
GitDaemonTest, SshDaemonTest, etc.)

src/test/java/com/gitblit/tests/FederationTests.java
src/test/java/com/gitblit/tests/GitServletTest.java
src/test/java/com/gitblit/tests/HtpasswdAuthenticationTest.java
src/test/java/com/gitblit/tests/JsonUtilsTest.java
src/test/java/com/gitblit/tests/PushLogTest.java [deleted file]
src/test/java/com/gitblit/tests/RpcTests.java
src/test/java/com/gitblit/tests/TicketReferenceTest.java
src/test/java/com/gitblit/tests/TicketServiceTest.java
src/test/java/com/gitblit/tests/UITicketTest.java

index 144fe3da8682784599f9a2127e344b6d35a4089c..36ea56c38f999c4c9286185e08075eca2799376d 100644 (file)
@@ -15,6 +15,7 @@
  */\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
@@ -45,6 +46,12 @@ public class FederationTests extends GitblitUnitTest {
        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
@@ -54,11 +61,27 @@ public class FederationTests extends GitblitUnitTest {
 \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
@@ -121,18 +144,22 @@ public class FederationTests extends GitblitUnitTest {
 \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
@@ -140,7 +167,7 @@ public class FederationTests extends GitblitUnitTest {
                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
@@ -148,9 +175,12 @@ public class FederationTests extends GitblitUnitTest {
 \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
index 705684a3180ed1302f53d4ae5a6b94d4437b8370..f9a1bec4833b870cb84014ce389a749f7c23768e 100644 (file)
@@ -89,6 +89,9 @@ public class GitServletTest extends GitblitUnitTest {
 \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
@@ -107,19 +110,19 @@ public class GitServletTest extends GitblitUnitTest {
        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
@@ -400,7 +403,7 @@ public class GitServletTest extends GitblitUnitTest {
                // 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
@@ -485,7 +488,7 @@ public class GitServletTest extends GitblitUnitTest {
                // 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
@@ -630,7 +633,7 @@ public class GitServletTest extends GitblitUnitTest {
                // 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
@@ -663,7 +666,7 @@ public class GitServletTest extends GitblitUnitTest {
                // 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
index 26a49b24a32abfcd473467bea1dac3ca9f705a88..40379f7d595c134435ad2d5c318403d85aea3700 100644 (file)
@@ -200,11 +200,11 @@ public class HtpasswdAuthenticationTest extends GitblitUnitTest {
     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);
 
index 1cd31b8b7e6f9eaadc5d2f46c53dcfe74255f6f4..b9cfc7a6cebe56f8a8dd0b471583ef64b89b37d2 100644 (file)
@@ -17,7 +17,7 @@ package com.gitblit.tests;
 \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
@@ -29,7 +29,8 @@ public class JsonUtilsTest extends GitblitUnitTest {
 \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
@@ -37,7 +38,7 @@ public class JsonUtilsTest extends GitblitUnitTest {
                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
@@ -56,4 +57,4 @@ public class JsonUtilsTest extends GitblitUnitTest {
                Date date = new Date();\r
                String name = "myJson";\r
        }\r
-}
\ No newline at end of file
+}\r
diff --git a/src/test/java/com/gitblit/tests/PushLogTest.java b/src/test/java/com/gitblit/tests/PushLogTest.java
deleted file mode 100644 (file)
index be097cc..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*\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
index 51b4671bafaf14f226d44fcba6fd74663a2e1f1b..4c79465644784bbfcf3416ee90c521d5980074e5 100644 (file)
@@ -68,6 +68,11 @@ public class RpcTests extends GitblitUnitTest {
 \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
@@ -265,11 +270,17 @@ public class RpcTests extends GitblitUnitTest {
 \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
index 59e00c5306c73c4a6da103404db064e274d2f7ce..827ba59dc9c0d50276da6e15ff4d0ceead787c74 100644 (file)
@@ -57,6 +57,7 @@ import com.gitblit.tickets.ITicketService;
  */
 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;
@@ -73,13 +74,13 @@ public class TicketReferenceTest extends GitblitUnitTest {
        
        @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);
@@ -141,7 +142,23 @@ public class TicketReferenceTest extends GitblitUnitTest {
        
        @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
index c654383d9d172d3472221b3406381eb66facd8c5..c0d93531d23532612489e43c0899fefbcc69bb1e 100644 (file)
@@ -21,8 +21,8 @@ import java.util.HashMap;
 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
@@ -65,7 +65,9 @@ public abstract class TicketServiceTest extends GitblitUnitTest {
        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
index e89c32fcf153ce255efa049f0a57a17f933a470c..266bee40abf9d8d6812971294ab555199663b090 100644 (file)
 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;
 
@@ -40,26 +38,16 @@ import com.gitblit.manager.PluginManager;
 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;
@@ -70,7 +58,7 @@ 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 {
@@ -99,7 +87,9 @@ public class UITicketTest extends GitblitUnitTest {
        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();
                }
                
@@ -114,6 +104,15 @@ public class UITicketTest extends GitblitUnitTest {
                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);
@@ -148,4 +147,4 @@ public class UITicketTest extends GitblitUnitTest {
                return change;
        }
 
-}
\ No newline at end of file
+}