]> source.dussan.org Git - gitblit.git/commitdiff
Unit testing. Documentation.
authorJames Moger <james.moger@gitblit.com>
Wed, 28 Dec 2011 21:19:29 +0000 (16:19 -0500)
committerJames Moger <james.moger@gitblit.com>
Wed, 28 Dec 2011 21:19:29 +0000 (16:19 -0500)
docs/05_roadmap.mkd
tests/com/gitblit/tests/GitBlitSuite.java
tests/com/gitblit/tests/GroovyScriptTest.java [new file with mode: 0644]

index bb7aaad98fe970a32e8d25d1d692c47ee0e5e17e..c1581551cbd7fa39627e5d62af18948e5ced5984 100644 (file)
@@ -8,6 +8,7 @@ This list is volatile.
 * Eclipse: create plugin to enumerate repositories and delegate cloning to EGit\r
 * Manager: support federation RPCs\r
 * Manager: redesign ref indicators in log, search, and activity views to support multiple local branches, remote branches, and tags\r
+* Gitblit: Lucene integration with multi-repository search (issue 16)\r
 \r
 ### TODO (medium priority)\r
 \r
@@ -20,7 +21,6 @@ This list is volatile.
     * optional scheduled pulls\r
     * optional automatic push to origin/remotes?\r
     * optional manual push to origin/remotes?\r
-* Gitblit: Lucene integration with multi-repository search (issue 16)\r
 * Gitblit: Repository regex substitutions should be stored in .git/.config, not gitblit.properties\r
 * Gitblit: Consider allowing git:// protocol using JGit\r
     * new setting *git.allowGitProtocol* to enable/disable git:// protocol\r
@@ -29,17 +29,14 @@ This list is volatile.
     * clone-restricted repositories would prohibit git:// access\r
     * view-restricted repositories would prohibit git:// access\r
 \r
-### TODO (low priority)\r
-\r
-* Gitblit: Blame coloring by author (issue 2)\r
-* Gitblit: View binary files in blob page (issue 6)\r
-\r
 ### IDEAS\r
 \r
+* Gitblit: diff should highlight inserted/removed fragment compared to original line\r
 * Gitblit: implement branch permission controls as Groovy pre-receive script.  \r
 *Maintain permissions text file similar to a gitolite configuration file or svn authz file.*\r
-* Gitblit: consider user-subscribed email notifications for a repository branch as a built-in feature.  \r
-*There is a sample Groovy post-receive hook script which can send emails.*\r
+* Gitblit: consider user-subscribed email notifications for a repository branch.  \r
 * Gitblit: aggregate RSS feeds by tag or subfolder\r
 * Gitblit: Consider creating more Git model objects and exposing them via the JSON RPC interface to allow inspection/retrieval of Git commits, Git trees, etc from Gitblit.\r
+* Gitblit: Blame coloring by author (issue 2)\r
+* Gitblit: View binary files in blob page (issue 6)\r
 * Gitblit: Stronger ticgit integration (issue 8)\r
index 1d90b15715a05a1efe1758c452439dfbc34bd515..f094a857312fa9a9491c12f9b773a2a43bd54d05 100644 (file)
@@ -51,7 +51,7 @@ import com.gitblit.utils.JGitUtils;
                JsonUtilsTest.class, ByteFormatTest.class, ObjectCacheTest.class, UserServiceTest.class,\r
                MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,\r
                DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class, GitBlitTest.class,\r
-               FederationTests.class, RpcTests.class, GitServletTest.class })\r
+               FederationTests.class, RpcTests.class, GitServletTest.class, GroovyScriptTest.class })\r
 public class GitBlitSuite {\r
 \r
        public static final File REPOSITORIES = new File("git");\r
diff --git a/tests/com/gitblit/tests/GroovyScriptTest.java b/tests/com/gitblit/tests/GroovyScriptTest.java
new file mode 100644 (file)
index 0000000..308160d
--- /dev/null
@@ -0,0 +1,172 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import groovy.lang.Binding;\r
+import groovy.util.GroovyScriptEngine;\r
+\r
+import java.io.File;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+import java.util.List;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+\r
+import org.eclipse.jgit.lib.ObjectId;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.transport.ReceiveCommand;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.GitBlitException;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.TeamModel;\r
+import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+/**\r
+ * Test class for Groovy scripts. Mostly this is to facilitate development.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class GroovyScriptTest {\r
+\r
+       private static final AtomicBoolean started = new AtomicBoolean(false);\r
+\r
+       @BeforeClass\r
+       public static void startGitblit() throws Exception {\r
+               started.set(GitBlitSuite.startGitblit());\r
+       }\r
+\r
+       @AfterClass\r
+       public static void stopGitblit() throws Exception {\r
+               if (started.get()) {\r
+                       GitBlitSuite.stopGitblit();\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void testSendMail() 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
+               test("sendmail.groovy", gitblit, logger, commands);\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
+       private void test(String script, MockGitblit gitblit, MockLogger logger,\r
+                       List<ReceiveCommand> commands) 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
+               File groovyDir = GitBlit.getGroovyScriptsFolder();\r
+               GroovyScriptEngine gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());\r
+\r
+               Binding binding = new Binding();\r
+               binding.setVariable("gitblit", gitblit);\r
+               binding.setVariable("repository", repository);\r
+               binding.setVariable("user", user);\r
+               binding.setVariable("commands", commands);\r
+               binding.setVariable("url", gitblitUrl);\r
+               binding.setVariable("logger", logger);\r
+\r
+               Object result = gse.run(script, binding);\r
+               if (result instanceof Boolean) {\r
+                       if (!((Boolean) result)) {\r
+                               throw new GitBlitException(MessageFormat.format(\r
+                                               "Groovy script {0} has failed!  Hook scripts aborted.", script));\r
+                       }\r
+               }\r
+       }\r
+\r
+       class MockGitblit {\r
+               List<MockMail> messages = new ArrayList<MockMail>();\r
+\r
+               public Repository getRepository(String name) throws Exception {\r
+                       return GitBlitSuite.getHelloworldRepository();\r
+               }\r
+\r
+               public List<String> getStrings(String key) {\r
+                       return Arrays.asList("alpha@aaa.com", "beta@bee.com", "gamma@see.com");\r
+               }\r
+\r
+               public List<String> getRepositoryTeams(RepositoryModel repository) {\r
+                       return Arrays.asList("testteam");\r
+               }\r
+\r
+               public TeamModel getTeamModel(String name) {\r
+                       TeamModel model = new TeamModel(name);\r
+                       model.mailingLists.add("list@" + name + ".com");\r
+                       return model;\r
+               }\r
+\r
+               public String getString(String key, String dv) {\r
+                       return dv;\r
+               }\r
+\r
+               public boolean getBoolean(String key, boolean dv) {\r
+                       return dv;\r
+               }\r
+\r
+               public void sendMail(String subject, String message, Collection<String> toAddresses) {\r
+                       messages.add(new MockMail(subject, message, toAddresses));\r
+               }\r
+       }\r
+\r
+       class MockLogger {\r
+               List<String> messages = new ArrayList<String>();\r
+\r
+               public void info(String message) {\r
+                       messages.add(message);\r
+               }\r
+       }\r
+\r
+       class MockMail {\r
+               final Collection<String> toAddresses;\r
+               final String subject;\r
+               final String message;\r
+\r
+               MockMail(String subject, String message, Collection<String> toAddresses) {\r
+                       this.subject = subject;\r
+                       this.message = message;\r
+                       this.toAddresses = toAddresses;\r
+               }\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return StringUtils.flattenStrings(toAddresses, ", ") + "\n\n" + subject + "\n\n"\r
+                                       + message;\r
+               }\r
+       }\r
+}
\ No newline at end of file