summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-05-29 14:04:38 -0400
committerJames Moger <james.moger@gitblit.com>2011-05-29 14:04:38 -0400
commitdb653ae29c54163c7ca2dd6d2b5063d4623c3a8c (patch)
tree79374dca46b41a133fc99a54c3705cc79dc7f34b /tests
parentec97f716023c0bbd6a9e11cbe7144973cf1c103d (diff)
downloadgitblit-db653ae29c54163c7ca2dd6d2b5063d4623c3a8c.tar.gz
gitblit-db653ae29c54163c7ca2dd6d2b5063d4623c3a8c.zip
Unit testing.
Diffstat (limited to 'tests')
-rw-r--r--tests/com/gitblit/tests/ByteFormatTest.java10
-rw-r--r--tests/com/gitblit/tests/DiffUtilsTest.java100
-rw-r--r--tests/com/gitblit/tests/GitBlitSuite.java1
-rw-r--r--tests/com/gitblit/tests/GitBlitTest.java13
-rw-r--r--tests/com/gitblit/tests/JGitUtilsTest.java15
-rw-r--r--tests/com/gitblit/tests/StringUtilsTest.java9
6 files changed, 122 insertions, 26 deletions
diff --git a/tests/com/gitblit/tests/ByteFormatTest.java b/tests/com/gitblit/tests/ByteFormatTest.java
index e969c4dc..462c2f07 100644
--- a/tests/com/gitblit/tests/ByteFormatTest.java
+++ b/tests/com/gitblit/tests/ByteFormatTest.java
@@ -24,10 +24,10 @@ public class ByteFormatTest extends TestCase {
public void testByteFormat() throws Exception {
ByteFormat format = new ByteFormat();
assertTrue(format.format(10).equals("10 b"));
- assertTrue(format.format(1024*10).equals("10.0 KB"));
- assertTrue(format.format(1024*1000).equals("1,000.0 KB"));
- assertTrue(format.format(2*1024*1000).equals("2.0 MB"));
- assertTrue(format.format(1024*1024*1000).equals("1,000.0 MB"));
- assertTrue(format.format(2*1024*1024*1000).equals("2.0 GB"));
+ assertTrue(format.format(1024 * 10).equals("10.0 KB"));
+ assertTrue(format.format(1024 * 1000).equals("1,000.0 KB"));
+ assertTrue(format.format(2 * 1024 * 1000).equals("2.0 MB"));
+ assertTrue(format.format(1024 * 1024 * 1000).equals("1,000.0 MB"));
+ assertTrue(format.format(2 * 1024 * 1024 * 1000).equals("2.0 GB"));
}
}
diff --git a/tests/com/gitblit/tests/DiffUtilsTest.java b/tests/com/gitblit/tests/DiffUtilsTest.java
new file mode 100644
index 00000000..34cb8533
--- /dev/null
+++ b/tests/com/gitblit/tests/DiffUtilsTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2011 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 junit.framework.TestCase;
+
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+
+import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.JGitUtils;
+import com.gitblit.utils.JGitUtils.DiffOutputType;
+
+public class DiffUtilsTest extends TestCase {
+
+ public void testParentCommitDiff() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN);
+ repository.close();
+ assertTrue(diff != null && diff.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(diff.indexOf(expected) > -1);
+ }
+
+ public void testArbitraryCommitDiff() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit baseCommit = JGitUtils.getCommit(repository,
+ "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffOutputType.PLAIN);
+ repository.close();
+ assertTrue(diff != null && diff.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(diff.indexOf(expected) > -1);
+ }
+
+ public void testPlainFileDiff() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffOutputType.PLAIN);
+ repository.close();
+ assertTrue(diff != null && diff.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(diff.indexOf(expected) > -1);
+ }
+
+ public void testFilePatch() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
+ repository.close();
+ assertTrue(patch != null && patch.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(patch.indexOf(expected) > -1);
+ }
+
+ public void testArbitraryFilePatch() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit baseCommit = JGitUtils.getCommit(repository,
+ "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
+ repository.close();
+ assertTrue(patch != null && patch.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(patch.indexOf(expected) > -1);
+ }
+
+ public void testArbitraryCommitPatch() throws Exception {
+ Repository repository = GitBlitSuite.getHelloworldRepository();
+ RevCommit baseCommit = JGitUtils.getCommit(repository,
+ "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
+ RevCommit commit = JGitUtils.getCommit(repository,
+ "1d0c2933a4ae69c362f76797d42d6bd182d05176");
+ String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
+ repository.close();
+ assertTrue(patch != null && patch.length() > 0);
+ String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
+ assertTrue(patch.indexOf(expected) > -1);
+ }
+}
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java
index d6064b10..d9963646 100644
--- a/tests/com/gitblit/tests/GitBlitSuite.java
+++ b/tests/com/gitblit/tests/GitBlitSuite.java
@@ -43,6 +43,7 @@ public class GitBlitSuite extends TestSetup {
suite.addTestSuite(StringUtilsTest.class);
suite.addTestSuite(ByteFormatTest.class);
suite.addTestSuite(JGitUtilsTest.class);
+ suite.addTestSuite(DiffUtilsTest.class);
suite.addTestSuite(GitBlitTest.class);
return new GitBlitSuite(suite);
}
diff --git a/tests/com/gitblit/tests/GitBlitTest.java b/tests/com/gitblit/tests/GitBlitTest.java
index 69880d92..853ca39a 100644
--- a/tests/com/gitblit/tests/GitBlitTest.java
+++ b/tests/com/gitblit/tests/GitBlitTest.java
@@ -28,12 +28,17 @@ public class GitBlitTest extends TestCase {
public void testRepositoryModel() throws Exception {
List<String> repositories = GitBlit.self().getRepositoryList();
assertTrue("Repository list is empty!", repositories.size() > 0);
- assertTrue("Missing Helloworld repository!", repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
- RepositoryModel model = GitBlit.self().getRepositoryModel(GitBlitSuite.getHelloworldRepository().getDirectory().getName());
+ assertTrue(
+ "Missing Helloworld repository!",
+ repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
+ .getName()));
+ RepositoryModel model = GitBlit.self().getRepositoryModel(
+ GitBlitSuite.getHelloworldRepository().getDirectory().getName());
assertTrue("Helloworld model is null!", model != null);
- assertTrue(model.toString().equals(GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
+ assertTrue(model.toString().equals(
+ GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
}
-
+
public void testUserModel() throws Exception {
List<String> users = GitBlit.self().getAllUsernames();
assertTrue("No users found!", users.size() > 0);
diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java
index 39a4a36b..d17ab5df 100644
--- a/tests/com/gitblit/tests/JGitUtilsTest.java
+++ b/tests/com/gitblit/tests/JGitUtilsTest.java
@@ -34,9 +34,7 @@ import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.RefModel;
import com.gitblit.models.TicketModel;
import com.gitblit.models.TicketModel.Comment;
-import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.JGitUtils.DiffOutputType;
public class JGitUtilsTest extends TestCase {
@@ -65,10 +63,12 @@ public class JGitUtilsTest extends TestCase {
public void testFirstCommit() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit commit = JGitUtils.getFirstCommit(repository, null);
+ Date firstChange = JGitUtils.getFirstChange(repository, null);
repository.close();
assertTrue("Could not get first commit!", commit != null);
assertTrue("Incorrect first commit!",
commit.getName().equals("f554664a346629dc2b839f7292d06bad2db4aece"));
+ assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
}
public void testRefs() throws Exception {
@@ -137,17 +137,6 @@ public class JGitUtilsTest extends TestCase {
}
}
- public void testCommitDiff() throws Exception {
- Repository repository = GitBlitSuite.getHelloworldRepository();
- RevCommit commit = JGitUtils.getCommit(repository,
- "1d0c2933a4ae69c362f76797d42d6bd182d05176");
- String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN);
- repository.close();
- assertTrue("Failed to generate diff!", diff != null && diff.length() > 0);
- String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
- assertTrue("Diff content mismatch!", diff.indexOf(expected) > -1);
- }
-
public void testZip() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
File zipFile = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
diff --git a/tests/com/gitblit/tests/StringUtilsTest.java b/tests/com/gitblit/tests/StringUtilsTest.java
index 24033b22..49938ae4 100644
--- a/tests/com/gitblit/tests/StringUtilsTest.java
+++ b/tests/com/gitblit/tests/StringUtilsTest.java
@@ -35,7 +35,7 @@ public class StringUtilsTest extends TestCase {
String output = "this<br/>is<br/>a<br/>test<br/><br/>of<br/><br/>line<br/><br/>breaking";
assertTrue(StringUtils.breakLinesForHtml(input).equals(output));
}
-
+
public void testEscapeForHtml() throws Exception {
String input = "& < > \" \t";
String output_nochange = "&amp; &lt; &gt; &quot; \t";
@@ -64,11 +64,12 @@ public class StringUtilsTest extends TestCase {
assertTrue(StringUtils.leftPad(input, input.length(), ' ').equals(input));
assertTrue(StringUtils.rightPad(input, input.length(), ' ').equals(input));
}
-
+
public void testSHA1() throws Exception {
- assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals("bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
+ assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(
+ "bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
}
-
+
public void testRootPath() throws Exception {
String input = "/nested/path/to/repository";
String output = "/nested/path/to";