From: James Moger Date: Sun, 1 Jan 2012 18:32:37 +0000 (-0500) Subject: Added unit test for blockpush.groovy X-Git-Tag: v0.8.0~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ff148dd3af7afa81736c0f8600912fa88099a6b9;p=gitblit.git Added unit test for blockpush.groovy --- diff --git a/tests/com/gitblit/tests/GroovyScriptTest.java b/tests/com/gitblit/tests/GroovyScriptTest.java index 308160d4..31587362 100644 --- a/tests/com/gitblit/tests/GroovyScriptTest.java +++ b/tests/com/gitblit/tests/GroovyScriptTest.java @@ -25,6 +25,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -73,20 +74,40 @@ public class GroovyScriptTest { .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); - test("sendmail.groovy", gitblit, logger, commands); + RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git"); + repository.mailingLists.add("list@helloworld.git"); + + test("sendmail.groovy", gitblit, logger, commands, repository); assertEquals(1, logger.messages.size()); assertEquals(1, gitblit.messages.size()); MockMail m = gitblit.messages.get(0); assertEquals(5, m.toAddresses.size()); assertTrue(m.message.contains("BIT")); } + + @Test + public void testBlockPush() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + commands.add(new ReceiveCommand(ObjectId + .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + try { + test("blockpush.groovy", gitblit, logger, commands, repository); + assertTrue("blockpush should have failed!", false); + } catch (GitBlitException e) { + assertTrue(e.getMessage().contains("failed")); + } + } private void test(String script, MockGitblit gitblit, MockLogger logger, - List commands) throws Exception { + List commands, RepositoryModel repository) throws Exception { UserModel user = new UserModel("mock"); - RepositoryModel repository = GitBlit.self().getRepositoryModel("helloworld.git"); - repository.mailingLists.add("list@helloworld.git"); String gitblitUrl = GitBlitSuite.url;