summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-07-22 09:37:14 -0400
committerJames Moger <james.moger@gitblit.com>2011-07-22 09:37:14 -0400
commit88598bb2f779b73479512d818c675dea8fa72138 (patch)
tree77e1a8e89da1faa3444f03aefa8a201f77010e9e /tests
parent0d3e3ca5b85d7e81066030a5081ea3a9cbe76607 (diff)
downloadgitblit-88598bb2f779b73479512d818c675dea8fa72138.tar.gz
gitblit-88598bb2f779b73479512d818c675dea8fa72138.zip
Documentation. Unit testing. Checkstyle. Findbugs.
Diffstat (limited to 'tests')
-rw-r--r--tests/com/gitblit/tests/FileUtilsTest.java45
-rw-r--r--tests/com/gitblit/tests/GitBlitSuite.java3
-rw-r--r--tests/com/gitblit/tests/GitBlitTest.java18
-rw-r--r--tests/com/gitblit/tests/MetricUtilsTest.java6
-rw-r--r--tests/com/gitblit/tests/StringUtilsTest.java6
-rw-r--r--tests/com/gitblit/tests/SyndicationUtilsTest.java3
6 files changed, 71 insertions, 10 deletions
diff --git a/tests/com/gitblit/tests/FileUtilsTest.java b/tests/com/gitblit/tests/FileUtilsTest.java
new file mode 100644
index 00000000..4e416cb7
--- /dev/null
+++ b/tests/com/gitblit/tests/FileUtilsTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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 java.io.File;
+
+import com.gitblit.utils.FileUtils;
+
+import junit.framework.TestCase;
+
+public class FileUtilsTest extends TestCase {
+
+ public void testReadContent() throws Exception {
+ File dir = new File(System.getProperty("user.dir"));
+ String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");
+ assertTrue(rawContent.trim().startsWith("Apache License"));
+ }
+
+ public void testFolderSize() throws Exception {
+ assertEquals(-1, FileUtils.folderSize(null));
+ assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));
+
+ File dir = new File(System.getProperty("user.dir"), "distrib");
+ long size = FileUtils.folderSize(dir);
+ assertTrue("size is actually " + size, size >= 470000L);
+
+ File file = new File(System.getProperty("user.dir"), "LICENSE");
+ size = FileUtils.folderSize(file);
+ assertTrue("size is actually " + size, size == 11556L);
+
+ }
+} \ No newline at end of file
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java
index bbf7c4b3..2908383e 100644
--- a/tests/com/gitblit/tests/GitBlitSuite.java
+++ b/tests/com/gitblit/tests/GitBlitSuite.java
@@ -24,8 +24,8 @@ import junit.framework.TestSuite;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepository;
-import com.gitblit.FileUserService;
import com.gitblit.FileSettings;
+import com.gitblit.FileUserService;
import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.models.RepositoryModel;
@@ -40,6 +40,7 @@ public class GitBlitSuite extends TestSetup {
public static Test suite() {
TestSuite suite = new TestSuite();
+ suite.addTestSuite(FileUtilsTest.class);
suite.addTestSuite(TimeUtilsTest.class);
suite.addTestSuite(StringUtilsTest.class);
suite.addTestSuite(ByteFormatTest.class);
diff --git a/tests/com/gitblit/tests/GitBlitTest.java b/tests/com/gitblit/tests/GitBlitTest.java
index 22297683..e278e5ae 100644
--- a/tests/com/gitblit/tests/GitBlitTest.java
+++ b/tests/com/gitblit/tests/GitBlitTest.java
@@ -39,6 +39,8 @@ public class GitBlitTest extends TestCase {
assertTrue("Helloworld model is null!", model != null);
assertTrue(model.toString().equals(
GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
+ assertEquals("" + GitBlit.self().calculateSize(model), GitBlit.self().calculateSize(model),
+ 22004L);
}
public void testUserModel() throws Exception {
@@ -54,6 +56,9 @@ public class GitBlitTest extends TestCase {
assertFalse("Admin can still access repository!", model.canAccessRepository(repository));
model.addRepository(repository);
assertTrue("Admin can't access repository!", model.canAccessRepository(repository));
+ assertEquals(GitBlit.self().getRepositoryModel(model, "pretend"), null);
+ assertNotNull(GitBlit.self().getRepositoryModel(model, repository));
+ assertTrue(GitBlit.self().getRepositoryModels(model).size() > 0);
}
public void testAccessRestrictionTypes() throws Exception {
@@ -85,12 +90,12 @@ public class GitBlitTest extends TestCase {
public void testFileSettings() throws Exception {
FileSettings settings = new FileSettings("distrib/gitblit.properties");
- assertTrue(settings.getBoolean("missing", true) == true);
+ assertTrue(settings.getBoolean("missing", true));
assertTrue(settings.getString("missing", "default").equals("default"));
assertTrue(settings.getInteger("missing", 10) == 10);
assertTrue(settings.getInteger("realm.realmFile", 5) == 5);
- assertTrue(settings.getBoolean("git.enableGitServlet", false) == true);
+ assertTrue(settings.getBoolean("git.enableGitServlet", false));
assertTrue(settings.getString("realm.userService", null).equals("users.properties"));
assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);
List<String> mdExtensions = settings.getStrings("web.markdownExtensions");
@@ -100,16 +105,18 @@ public class GitBlitTest extends TestCase {
List<String> keys = settings.getAllKeys("server");
assertTrue(keys.size() > 0);
assertTrue(keys.contains("server.httpsPort"));
+
+ assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');
}
public void testGitblitSettings() throws Exception {
// These are already tested by above test method.
- assertTrue(GitBlit.getBoolean("missing", true) == true);
+ assertTrue(GitBlit.getBoolean("missing", true));
assertTrue(GitBlit.getString("missing", "default").equals("default"));
assertTrue(GitBlit.getInteger("missing", 10) == 10);
assertTrue(GitBlit.getInteger("realm.userService", 5) == 5);
- assertTrue(GitBlit.getBoolean("git.enableGitServlet", false) == true);
+ assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));
assertTrue(GitBlit.getString("realm.userService", null).equals("users.properties"));
assertTrue(GitBlit.getInteger("realm.minPasswordLength", 0) == 5);
List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");
@@ -119,6 +126,9 @@ public class GitBlitTest extends TestCase {
List<String> keys = GitBlit.getAllKeys("server");
assertTrue(keys.size() > 0);
assertTrue(keys.contains("server.httpsPort"));
+
+ assertTrue(GitBlit.getChar("web.forwardSlashCharacter", ' ') == '/');
+ assertFalse(GitBlit.isDebugMode());
}
public void testAuthentication() throws Exception {
diff --git a/tests/com/gitblit/tests/MetricUtilsTest.java b/tests/com/gitblit/tests/MetricUtilsTest.java
index c9d007df..bfa34b4b 100644
--- a/tests/com/gitblit/tests/MetricUtilsTest.java
+++ b/tests/com/gitblit/tests/MetricUtilsTest.java
@@ -27,7 +27,11 @@ import com.gitblit.utils.MetricUtils;
public class MetricUtilsTest extends TestCase {
public void testMetrics() throws Exception {
- Repository repository = GitBlitSuite.getHelloworldRepository();
+ testMetrics(GitBlitSuite.getHelloworldRepository());
+ testMetrics(GitBlitSuite.getBluezGnomeRepository());
+ }
+
+ private void testMetrics(Repository repository) throws Exception {
List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null);
repository.close();
assertTrue("No date metrics found!", metrics.size() > 0);
diff --git a/tests/com/gitblit/tests/StringUtilsTest.java b/tests/com/gitblit/tests/StringUtilsTest.java
index 1bf0de4a..665b9140 100644
--- a/tests/com/gitblit/tests/StringUtilsTest.java
+++ b/tests/com/gitblit/tests/StringUtilsTest.java
@@ -36,7 +36,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 testEncodeUrl() throws Exception {
String input = "test /";
String output = "test%20%2F";
@@ -50,7 +50,7 @@ public class StringUtilsTest extends TestCase {
assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));
assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));
}
-
+
public void testDecodeForHtml() throws Exception {
String input = "&amp; &lt; &gt; &quot;";
String output = "& < > \"";
@@ -82,7 +82,7 @@ public class StringUtilsTest extends TestCase {
assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(
"bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
}
-
+
public void testMD5() throws Exception {
assertTrue(StringUtils.getMD5("blob 16\000what is up, doc?").equals(
"77fb8d95331f0d557472f6776d3aedf6"));
diff --git a/tests/com/gitblit/tests/SyndicationUtilsTest.java b/tests/com/gitblit/tests/SyndicationUtilsTest.java
index ab518041..1fa21fc3 100644
--- a/tests/com/gitblit/tests/SyndicationUtilsTest.java
+++ b/tests/com/gitblit/tests/SyndicationUtilsTest.java
@@ -32,7 +32,8 @@ public class SyndicationUtilsTest extends TestCase {
Repository repository = GitBlitSuite.getHelloworldRepository();
List<RevCommit> commits = JGitUtils.getRevLog(repository, 1);
ByteArrayOutputStream os = new ByteArrayOutputStream();
- SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits, os);
+ SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", commits,
+ os);
String feed = os.toString();
os.close();
assertTrue(feed.length() > 100);