]> source.dussan.org Git - gitblit.git/commitdiff
Added unit test for blockpush.groovy
authorJames Moger <james.moger@gitblit.com>
Sun, 1 Jan 2012 18:32:37 +0000 (13:32 -0500)
committerJames Moger <james.moger@gitblit.com>
Sun, 1 Jan 2012 18:32:37 +0000 (13:32 -0500)
tests/com/gitblit/tests/GroovyScriptTest.java

index 308160d4d0588e763328b251937aa56293474742..315873625b3307a5076c3ac37dd20f76ca2960e5 100644 (file)
@@ -25,6 +25,7 @@ import java.text.MessageFormat;
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.Collection;\r
+import java.util.Date;\r
 import java.util.List;\r
 import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
@@ -73,20 +74,40 @@ public class GroovyScriptTest {
                                .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
                                .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
 \r
-               test("sendmail.groovy", gitblit, logger, commands);\r
+               RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
+               repository.mailingLists.add("list@helloworld.git");\r
+\r
+               test("sendmail.groovy", gitblit, logger, commands, repository);\r
                assertEquals(1, logger.messages.size());\r
                assertEquals(1, gitblit.messages.size());\r
                MockMail m = gitblit.messages.get(0);\r
                assertEquals(5, m.toAddresses.size());\r
                assertTrue(m.message.contains("BIT"));\r
        }\r
+       \r
+       @Test\r
+       public void testBlockPush() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               commands.add(new ReceiveCommand(ObjectId\r
+                               .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               try {\r
+                       test("blockpush.groovy", gitblit, logger, commands, repository);\r
+                       assertTrue("blockpush should have failed!", false);\r
+               } catch (GitBlitException e) {\r
+                       assertTrue(e.getMessage().contains("failed"));\r
+               }\r
+       }\r
 \r
        private void test(String script, MockGitblit gitblit, MockLogger logger,\r
-                       List<ReceiveCommand> commands) throws Exception {\r
+                       List<ReceiveCommand> commands, RepositoryModel repository) throws Exception {\r
 \r
                UserModel user = new UserModel("mock");\r
-               RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git");\r
-               repository.mailingLists.add("list@helloworld.git");\r
 \r
                String gitblitUrl = GitBlitSuite.url;\r
 \r