summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-28 15:08:28 (EDT)
committer Chris Aniszczyk2011-04-28 17:17:03 (EDT)
commitc726c6d01584e5f91fde3c32c8f791a002f6ff13 (patch)
tree54ba34c5c9f9249d12b74794ee69c34355f9b77e
parent5247f096fb12dbafdecaad7d1f6f4792b9640ff9 (diff)
downloadegit-c726c6d01584e5f91fde3c32c8f791a002f6ff13.zip
egit-c726c6d01584e5f91fde3c32c8f791a002f6ff13.tar.gz
egit-c726c6d01584e5f91fde3c32c8f791a002f6ff13.tar.bz2
Add unit tests of CommitSearchQuery classrefs/changes/86/3286/2
Change-Id: If75b4af83a55e6d27a5c2f3222cb5800deb6e9c6 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/search/CommitSearchQueryTest.java188
1 files changed, 188 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/search/CommitSearchQueryTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/search/CommitSearchQueryTest.java
new file mode 100644
index 0000000..5da4e9d
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/search/CommitSearchQueryTest.java
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.search;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Locale;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
+import org.eclipse.egit.ui.internal.search.CommitSearchQuery;
+import org.eclipse.egit.ui.internal.search.CommitSearchResult;
+import org.eclipse.egit.ui.internal.search.CommitSearchSettings;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.search.ui.ISearchResult;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Unit tests of {@link CommitSearchQuery}
+ */
+public class CommitSearchQueryTest extends LocalRepositoryTestCase {
+
+ private static Repository repository;
+
+ private static RevCommit commit;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ File repoFile = createProjectAndCommitToRepository();
+ assertNotNull(repoFile);
+ repository = Activator.getDefault().getRepositoryCache()
+ .lookupRepository(repoFile);
+ assertNotNull(repository);
+
+ RevWalk walk = new RevWalk(repository);
+ try {
+ commit = walk.parseCommit(repository.resolve(Constants.HEAD));
+ assertNotNull(commit);
+ } finally {
+ walk.release();
+ }
+ }
+
+ private CommitSearchSettings createSettings() {
+ CommitSearchSettings settings = new CommitSearchSettings();
+ settings.addRepository(repository.getDirectory().getAbsolutePath());
+ settings.setMatchTree(false);
+ settings.setMatchAuthor(false);
+ settings.setMatchCommit(false);
+ settings.setMatchCommitter(false);
+ settings.setMatchParents(false);
+ settings.setMatchMessage(false);
+ settings.setCaseSensitive(true);
+ settings.setRegExSearch(false);
+ return settings;
+ }
+
+ private void validateResult(RevCommit expectedCommit,
+ Repository expectedRepository, ISearchResult result) {
+ assertNotNull(result);
+ assertTrue(result instanceof CommitSearchResult);
+ CommitSearchResult commitResult = (CommitSearchResult) result;
+ assertEquals(1, commitResult.getMatchCount());
+ Object[] elements = commitResult.getElements();
+ assertNotNull(elements);
+ assertEquals(1, elements.length);
+ assertTrue(elements[0] instanceof RepositoryCommit);
+ RepositoryCommit repoCommit = (RepositoryCommit) elements[0];
+ assertEquals(expectedRepository.getDirectory(), repoCommit
+ .getRepository().getDirectory());
+ assertEquals(expectedCommit, repoCommit.getRevCommit());
+ }
+
+ private void validateEmpty(ISearchResult result) {
+ assertNotNull(result);
+ assertTrue(result instanceof CommitSearchResult);
+ CommitSearchResult commitResult = (CommitSearchResult) result;
+ assertEquals(0, commitResult.getMatchCount());
+ Object[] elements = commitResult.getElements();
+ assertNotNull(elements);
+ assertEquals(0, elements.length);
+ }
+
+ @Test
+ public void testQuery() {
+ CommitSearchQuery query = new CommitSearchQuery(createSettings());
+ assertTrue(query.canRerun());
+ assertTrue(query.canRunInBackground());
+ assertNotNull(query.getLabel());
+ assertTrue(query.getLabel().length() > 0);
+ }
+
+ @Test
+ public void testMatchCommit() throws Exception {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchCommit(true);
+ settings.setTextPattern(commit.name());
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateResult(commit, repository, query.getSearchResult());
+ }
+
+ @Test
+ public void testEmptyMatches() {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchCommit(true);
+ settings.setTextPattern("badcommitid");
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateEmpty(query.getSearchResult());
+ }
+
+ @Test
+ public void testCaseInsensitive() {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchCommit(true);
+ settings.setCaseSensitive(true);
+ settings.setTextPattern(commit.name().toUpperCase(Locale.US));
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateEmpty(query.getSearchResult());
+ settings.setCaseSensitive(false);
+ status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateResult(commit, repository, query.getSearchResult());
+ }
+
+ @Test
+ public void testMatchTree() throws Exception {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchTree(true);
+ settings.setTextPattern(commit.getTree().name());
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateResult(commit, repository, query.getSearchResult());
+ }
+
+ @Test
+ public void testMatchParent() throws Exception {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchParents(true);
+ settings.setTextPattern(commit.getParent(0).name());
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateResult(commit, repository, query.getSearchResult());
+ }
+
+ @Test
+ public void testMatchMessage() {
+ CommitSearchSettings settings = createSettings();
+ settings.setMatchMessage(true);
+ settings.setTextPattern(commit.getFullMessage());
+ CommitSearchQuery query = new CommitSearchQuery(settings);
+ IStatus status = query.run(new NullProgressMonitor());
+ assertNotNull(status);
+ assertTrue(status.isOK());
+ validateResult(commit, repository, query.getSearchResult());
+ }
+}