]> source.dussan.org Git - gitblit.git/commitdiff
Fixed git servlet unit test
authorJames Moger <james.moger@gitblit.com>
Tue, 2 Jul 2013 19:08:28 +0000 (15:08 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 2 Jul 2013 19:08:28 +0000 (15:08 -0400)
src/test/java/com/gitblit/tests/GitServletTest.java

index 7607fbf7985e2d5f96a460747dcebdaf32b837ea..8513c83d731fc432842205aafde3717e6655e55b 100644 (file)
@@ -60,10 +60,24 @@ public class GitServletTest {
        String password = GitBlitSuite.password;\r
 \r
        private static final AtomicBoolean started = new AtomicBoolean(false);\r
+       \r
+       private static UserModel getUser() {\r
+               UserModel user = new UserModel("james");\r
+               user.password = "james";\r
+               return user;\r
+       }\r
+       \r
+       private static void delete(UserModel user) {\r
+               if (GitBlit.self().getUserModel(user.username) != null) {\r
+                       GitBlit.self().deleteUser(user.username);\r
+               }\r
+       }\r
 \r
        @BeforeClass\r
        public static void startGitblit() throws Exception {\r
                started.set(GitBlitSuite.startGitblit());\r
+\r
+               delete(getUser());\r
        }\r
 \r
        @AfterClass\r
@@ -72,6 +86,8 @@ public class GitServletTest {
                        GitBlitSuite.stopGitblit();\r
                        deleteWorkingFolders();\r
                }\r
+               \r
+               delete(getUser());\r
        }\r
        \r
        public static void deleteWorkingFolders() throws Exception {\r
@@ -194,7 +210,8 @@ public class GitServletTest {
                model.accessRestriction = AccessRestrictionType.NONE;\r
                model.authorizationControl = AuthorizationControl.NAMED;\r
                GitBlit.self().updateRepositoryModel(model.name, model, false);\r
-               GitBlit.self().deleteUser(user.username);\r
+               \r
+               delete(user);           \r
        }\r
 \r
        @Test\r
@@ -347,8 +364,7 @@ public class GitServletTest {
 \r
        @Test\r
        public void testCommitterVerification() throws Exception {\r
-               UserModel user = new UserModel("james");\r
-               user.password = "james";\r
+               UserModel user = getUser();\r
 \r
                // account only uses account name to verify\r
                testCommitterVerification(user, user.username, null, true);\r
@@ -375,9 +391,7 @@ public class GitServletTest {
        \r
        private void testCommitterVerification(UserModel user, String displayName, String emailAddress, boolean expectedSuccess) throws Exception {\r
                \r
-               if (GitBlit.self().getUserModel(user.username) != null) {\r
-                       GitBlit.self().deleteUser(user.username);\r
-               }\r
+               delete(user);\r
                \r
                CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);\r
                \r
@@ -483,12 +497,8 @@ public class GitServletTest {
 \r
        private void testRefChange(AccessPermission permission, Status expectedCreate, Status expectedDelete, Status expectedRewind) throws Exception {\r
 \r
-               UserModel user = new UserModel("james");\r
-               user.password = "james";\r
-               \r
-               if (GitBlit.self().getUserModel(user.username) != null) {\r
-                       GitBlit.self().deleteUser(user.username);\r
-               }\r
+               UserModel user = getUser();\r
+               delete(user);\r
                \r
                CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);\r
                \r
@@ -672,7 +682,7 @@ public class GitServletTest {
                // close serving repository\r
                GitBlitSuite.close(refChecks);\r
 \r
-               GitBlit.self().deleteUser(user.username);\r
+               delete(user);\r
        }\r
        \r
        @Test\r
@@ -687,9 +697,7 @@ public class GitServletTest {
                UserModel user = new UserModel("sampleuser");\r
                user.password = user.username;\r
                \r
-               if (GitBlit.self().getUserModel(user.username) != null) {\r
-                       GitBlit.self().deleteUser(user.username);\r
-               }\r
+               delete(user);\r
                \r
                user.canCreate = canCreate;\r
                user.canAdmin = canAdmin;\r
@@ -780,7 +788,7 @@ public class GitServletTest {
                }\r
 \r
                GitBlitSuite.close(git);\r
-               GitBlit.self().deleteUser(user.username);\r
+               delete(user);\r
        }\r
        \r
        @Test\r