From ff148dd3af7afa81736c0f8600912fa88099a6b9 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sun, 1 Jan 2012 13:32:37 -0500 Subject: [PATCH] Added unit test for blockpush.groovy --- tests/com/gitblit/tests/GroovyScriptTest.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) 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; -- 2.39.5