Browse Source

Added unit test for blockpush.groovy

tags/v0.8.0
James Moger 12 years ago
parent
commit
ff148dd3af
1 changed files with 25 additions and 4 deletions
  1. 25
    4
      tests/com/gitblit/tests/GroovyScriptTest.java

+ 25
- 4
tests/com/gitblit/tests/GroovyScriptTest.java View File

@@ -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<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
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<ReceiveCommand> commands) throws Exception {
List<ReceiveCommand> 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;

Loading…
Cancel
Save