summaryrefslogtreecommitdiffstats
path: root/tests/com
diff options
context:
space:
mode:
Diffstat (limited to 'tests/com')
-rw-r--r--tests/com/gitblit/tests/GitBlitSuite.java8
-rw-r--r--tests/com/gitblit/tests/IssuesTest.java256
-rw-r--r--tests/com/gitblit/tests/LuceneUtilsTest.java118
3 files changed, 381 insertions, 1 deletions
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java
index 71947e14..8fac212c 100644
--- a/tests/com/gitblit/tests/GitBlitSuite.java
+++ b/tests/com/gitblit/tests/GitBlitSuite.java
@@ -52,7 +52,7 @@ import com.gitblit.utils.JGitUtils;
ObjectCacheTest.class, UserServiceTest.class, MarkdownUtilsTest.class, JGitUtilsTest.class,
SyndicationUtilsTest.class, DiffUtilsTest.class, MetricUtilsTest.class,
TicgitUtilsTest.class, GitBlitTest.class, FederationTests.class, RpcTests.class,
- GitServletTest.class, GroovyScriptTest.class })
+ GitServletTest.class, GroovyScriptTest.class, LuceneUtilsTest.class, IssuesTest.class })
public class GitBlitSuite {
public static final File REPOSITORIES = new File("git");
@@ -90,6 +90,10 @@ public class GitBlitSuite {
return new FileRepository(new File(REPOSITORIES, "test/theoretical-physics.git"));
}
+ public static Repository getIssuesTestRepository() throws Exception {
+ return new FileRepository(new File(REPOSITORIES, "gb-issues.git"));
+ }
+
public static boolean startGitblit() throws Exception {
if (started.get()) {
// already started
@@ -134,6 +138,8 @@ public class GitBlitSuite {
cloneOrFetch("test/ambition.git", "https://github.com/defunkt/ambition.git");
cloneOrFetch("test/theoretical-physics.git", "https://github.com/certik/theoretical-physics.git");
+ JGitUtils.createRepository(REPOSITORIES, "gb-issues.git").close();
+
enableTickets("ticgit.git");
enableDocs("ticgit.git");
showRemoteBranches("ticgit.git");
diff --git a/tests/com/gitblit/tests/IssuesTest.java b/tests/com/gitblit/tests/IssuesTest.java
new file mode 100644
index 00000000..a5d487d8
--- /dev/null
+++ b/tests/com/gitblit/tests/IssuesTest.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.bouncycastle.util.Arrays;
+import org.eclipse.jgit.lib.Repository;
+import org.junit.Test;
+
+import com.gitblit.models.IssueModel;
+import com.gitblit.models.IssueModel.Attachment;
+import com.gitblit.models.IssueModel.Change;
+import com.gitblit.models.IssueModel.Field;
+import com.gitblit.models.IssueModel.Priority;
+import com.gitblit.models.IssueModel.Status;
+import com.gitblit.models.SearchResult;
+import com.gitblit.utils.IssueUtils;
+import com.gitblit.utils.IssueUtils.IssueFilter;
+import com.gitblit.utils.LuceneUtils;
+
+/**
+ * Tests the mechanics of distributed issue management on the gb-issues branch.
+ *
+ * @author James Moger
+ *
+ */
+public class IssuesTest {
+
+ @Test
+ public void testCreation() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ // create and insert the issue
+ Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));
+ IssueModel issue = IssueUtils.createIssue(repository, c1);
+ assertNotNull(issue.id);
+
+ // retrieve issue and compare
+ IssueModel constructed = IssueUtils.getIssue(repository, issue.id);
+ compare(issue, constructed);
+
+ assertEquals(1, constructed.changes.size());
+ }
+
+ @Test
+ public void testUpdates() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ // C1: create the issue
+ Change c1 = newChange("testUpdates() " + Long.toHexString(System.currentTimeMillis()));
+ IssueModel issue = IssueUtils.createIssue(repository, c1);
+ assertNotNull(issue.id);
+
+ IssueModel constructed = IssueUtils.getIssue(repository, issue.id);
+ compare(issue, constructed);
+
+ // C2: set owner
+ Change c2 = new Change("C2");
+ c2.comment("I'll fix this");
+ c2.setField(Field.Owner, c2.author);
+ assertTrue(IssueUtils.updateIssue(repository, issue.id, c2));
+ constructed = IssueUtils.getIssue(repository, issue.id);
+ assertEquals(2, constructed.changes.size());
+ assertEquals(c2.author, constructed.owner);
+
+ // C3: add a note
+ Change c3 = new Change("C3");
+ c3.comment("yeah, this is working");
+ assertTrue(IssueUtils.updateIssue(repository, issue.id, c3));
+ constructed = IssueUtils.getIssue(repository, issue.id);
+ assertEquals(3, constructed.changes.size());
+
+ // C4: add attachment
+ Change c4 = new Change("C4");
+ Attachment a = newAttachment();
+ c4.addAttachment(a);
+ assertTrue(IssueUtils.updateIssue(repository, issue.id, c4));
+
+ Attachment a1 = IssueUtils.getIssueAttachment(repository, issue.id, a.name);
+ assertEquals(a.content.length, a1.content.length);
+ assertTrue(Arrays.areEqual(a.content, a1.content));
+
+ // C5: close the issue
+ Change c5 = new Change("C5");
+ c5.comment("closing issue");
+ c5.setField(Field.Status, Status.Fixed);
+ assertTrue(IssueUtils.updateIssue(repository, issue.id, c5));
+
+ // retrieve issue again
+ constructed = IssueUtils.getIssue(repository, issue.id);
+
+ assertEquals(5, constructed.changes.size());
+ assertTrue(constructed.status.isClosed());
+
+ repository.close();
+ }
+
+ @Test
+ public void testQuery() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ List<IssueModel> allIssues = IssueUtils.getIssues(repository, null);
+
+ List<IssueModel> openIssues = IssueUtils.getIssues(repository, new IssueFilter() {
+ @Override
+ public boolean accept(IssueModel issue) {
+ return !issue.status.isClosed();
+ }
+ });
+
+ List<IssueModel> closedIssues = IssueUtils.getIssues(repository, new IssueFilter() {
+ @Override
+ public boolean accept(IssueModel issue) {
+ return issue.status.isClosed();
+ }
+ });
+
+ repository.close();
+ assertTrue(allIssues.size() > 0);
+ assertEquals(1, openIssues.size());
+ assertEquals(1, closedIssues.size());
+ }
+
+ @Test
+ public void testLuceneIndexAndQuery() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ LuceneUtils.deleteIndex(repository);
+ List<IssueModel> allIssues = IssueUtils.getIssues(repository, null);
+ assertTrue(allIssues.size() > 0);
+ for (IssueModel issue : allIssues) {
+ LuceneUtils.index(repository, issue, false);
+ }
+ List<SearchResult> hits = LuceneUtils.search("working", 10, repository);
+ assertTrue(hits.size() > 0);
+
+ // reindex an issue
+ IssueModel issue = allIssues.get(0);
+ Change change = new Change("reindex");
+ change.comment("this is a test of reindexing an issue");
+ IssueUtils.updateIssue(repository, issue.id, change);
+ issue = IssueUtils.getIssue(repository, issue.id);
+ LuceneUtils.index(repository, issue, true);
+
+ LuceneUtils.close();
+ repository.close();
+ }
+
+ @Test
+ public void testLuceneQuery() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ List<SearchResult> hits = LuceneUtils.search("working", 10, repository);
+ LuceneUtils.close();
+ repository.close();
+ assertTrue(hits.size() > 0);
+ }
+
+
+ @Test
+ public void testDelete() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ List<IssueModel> allIssues = IssueUtils.getIssues(repository, null);
+ // delete all issues
+ for (IssueModel issue : allIssues) {
+ assertTrue(IssueUtils.deleteIssue(repository, issue.id, "D"));
+ }
+ repository.close();
+ }
+
+ @Test
+ public void testChangeComment() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ // C1: create the issue
+ Change c1 = newChange("testChangeComment() " + Long.toHexString(System.currentTimeMillis()));
+ IssueModel issue = IssueUtils.createIssue(repository, c1);
+ assertNotNull(issue.id);
+ assertTrue(issue.changes.get(0).hasComment());
+
+ assertTrue(IssueUtils.changeComment(repository, issue, c1, "E1", "I changed the comment"));
+ issue = IssueUtils.getIssue(repository, issue.id);
+ assertTrue(issue.changes.get(0).hasComment());
+ assertEquals("I changed the comment", issue.changes.get(0).comment.text);
+
+ assertTrue(IssueUtils.deleteIssue(repository, issue.id, "D"));
+
+ repository.close();
+ }
+
+ @Test
+ public void testDeleteComment() throws Exception {
+ Repository repository = GitBlitSuite.getIssuesTestRepository();
+ // C1: create the issue
+ Change c1 = newChange("testDeleteComment() " + Long.toHexString(System.currentTimeMillis()));
+ IssueModel issue = IssueUtils.createIssue(repository, c1);
+ assertNotNull(issue.id);
+ assertTrue(issue.changes.get(0).hasComment());
+
+ assertTrue(IssueUtils.deleteComment(repository, issue, c1, "D1"));
+ issue = IssueUtils.getIssue(repository, issue.id);
+ assertEquals(1, issue.changes.size());
+ assertFalse(issue.changes.get(0).hasComment());
+
+ issue = IssueUtils.getIssue(repository, issue.id, false);
+ assertEquals(2, issue.changes.size());
+ assertTrue(issue.changes.get(0).hasComment());
+ assertFalse(issue.changes.get(1).hasComment());
+
+ assertTrue(IssueUtils.deleteIssue(repository, issue.id, "D"));
+
+ repository.close();
+ }
+
+ private Change newChange(String summary) {
+ Change change = new Change("C1");
+ change.setField(Field.Summary, summary);
+ change.setField(Field.Description, "this is my description");
+ change.setField(Field.Priority, Priority.High);
+ change.setField(Field.Labels, "helpdesk");
+ change.comment("my comment");
+ return change;
+ }
+
+ private Attachment newAttachment() {
+ Attachment attachment = new Attachment(Long.toHexString(System.currentTimeMillis())
+ + ".txt");
+ attachment.content = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
+ 0x4a };
+ return attachment;
+ }
+
+ private void compare(IssueModel issue, IssueModel constructed) {
+ assertEquals(issue.id, constructed.id);
+ assertEquals(issue.reporter, constructed.reporter);
+ assertEquals(issue.owner, constructed.owner);
+ assertEquals(issue.summary, constructed.summary);
+ assertEquals(issue.description, constructed.description);
+ assertEquals(issue.created, constructed.created);
+
+ assertTrue(issue.hasLabel("helpdesk"));
+ }
+} \ No newline at end of file
diff --git a/tests/com/gitblit/tests/LuceneUtilsTest.java b/tests/com/gitblit/tests/LuceneUtilsTest.java
new file mode 100644
index 00000000..a5446218
--- /dev/null
+++ b/tests/com/gitblit/tests/LuceneUtilsTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.eclipse.jgit.lib.Repository;
+import org.junit.Test;
+
+import com.gitblit.models.SearchResult;
+import com.gitblit.utils.LuceneUtils;
+
+/**
+ * Tests Lucene indexing and querying.
+ *
+ * @author James Moger
+ *
+ */
+public class LuceneUtilsTest {
+
+ @Test
+ public void testFullIndex() throws Exception {
+ // reindex helloworld
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ LuceneUtils.index(repository);
+ repository.close();
+
+ // reindex theoretical physics
+ repository = GitBlitSuite.getTheoreticalPhysicsRepository();
+ LuceneUtils.index(repository);
+ repository.close();
+
+ // reindex bluez-gnome
+ repository = GitBlitSuite.getBluezGnomeRepository();
+ LuceneUtils.index(repository);
+ repository.close();
+
+ LuceneUtils.close();
+ }
+
+ @Test
+ public void testQuery() throws Exception {
+ // 2 occurrences on the master branch
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ List<SearchResult> results = LuceneUtils.search("ada", 10, repository);
+ assertEquals(2, results.size());
+
+ // author test
+ results = LuceneUtils.search("author: tinogomes", 10, repository);
+ assertEquals(2, results.size());
+
+ repository.close();
+ // blob test
+ results = LuceneUtils.search("type: blob AND \"import std.stdio\"", 10, repository);
+ assertEquals(1, results.size());
+ assertEquals("d.D", results.get(0).id);
+
+ // 1 occurrence on the gh-pages branch
+ repository = GitBlitSuite.getTheoreticalPhysicsRepository();
+ results = LuceneUtils.search("\"add the .nojekyll file\"", 10, repository);
+ assertEquals(1, results.size());
+ assertEquals("Ondrej Certik", results.get(0).author);
+ assertEquals("2648c0c98f2101180715b4d432fc58d0e21a51d7", results.get(0).id);
+
+ // tag test
+ results = LuceneUtils.search("\"qft split\"", 10, repository);
+ assertEquals(1, results.size());
+ assertEquals("Ondrej Certik", results.get(0).author);
+ assertEquals("57c4f26f157ece24b02f4f10f5f68db1d2ce7ff5", results.get(0).id);
+ assertEquals("[1st-edition]", results.get(0).labels.toString());
+
+ results = LuceneUtils.search("type:blob AND \"src/intro.rst\"", 10, repository);
+ assertEquals(4, results.size());
+
+ // hash id tests
+ results = LuceneUtils.search("id:57c4f26f157ece24b02f4f10f5f68db1d2ce7ff5", 10, repository);
+ assertEquals(1, results.size());
+
+ results = LuceneUtils.search("id:57c4f26f157*", 10, repository);
+ assertEquals(1, results.size());
+
+ repository.close();
+
+ // annotated tag test
+ repository = GitBlitSuite.getBluezGnomeRepository();
+ results = LuceneUtils.search("\"release 1.8\"", 10, repository);
+ assertEquals(1, results.size());
+ assertEquals("[1.8]", results.get(0).labels.toString());
+
+ repository.close();
+
+ LuceneUtils.close();
+ }
+
+ @Test
+ public void testMultiSearch() throws Exception {
+ List<SearchResult> results = LuceneUtils.search("test", 10,
+ GitBlitSuite.getHelloworldRepository(),
+ GitBlitSuite.getBluezGnomeRepository());
+ LuceneUtils.close();
+ assertEquals(10, results.size());
+ }
+} \ No newline at end of file