]> source.dussan.org Git - gitblit.git/commitdiff
Unit testing overhaul.
authorJames Moger <james.moger@gitblit.com>
Thu, 8 Dec 2011 00:14:34 +0000 (19:14 -0500)
committerJames Moger <james.moger@gitblit.com>
Thu, 8 Dec 2011 00:14:34 +0000 (19:14 -0500)
Migrated to JUnit4-style tests.
Replaced assertTrue with assertEquals where appropriate.
Start Gitblit instance with dedicated unit testing settings file and
user service.
Integrated RPC, Federation, and Git servlet unit tests into suite.

24 files changed:
src/com/gitblit/GitBlitServer.java
test-gitblit.properties [new file with mode: 0644]
test-users.conf [new file with mode: 0644]
tests/com/gitblit/tests/ActivityTest.java
tests/com/gitblit/tests/Base64Test.java
tests/com/gitblit/tests/ByteFormatTest.java
tests/com/gitblit/tests/DiffUtilsTest.java
tests/com/gitblit/tests/FederationTests.java
tests/com/gitblit/tests/FileUtilsTest.java
tests/com/gitblit/tests/GitBlitSuite.java
tests/com/gitblit/tests/GitBlitTest.java
tests/com/gitblit/tests/GitServletTest.java
tests/com/gitblit/tests/JGitUtilsTest.java
tests/com/gitblit/tests/JsonUtilsTest.java
tests/com/gitblit/tests/MailTest.java
tests/com/gitblit/tests/MarkdownUtilsTest.java
tests/com/gitblit/tests/MetricUtilsTest.java
tests/com/gitblit/tests/ObjectCacheTest.java
tests/com/gitblit/tests/RpcTests.java
tests/com/gitblit/tests/StringUtilsTest.java
tests/com/gitblit/tests/SyndicationUtilsTest.java
tests/com/gitblit/tests/TicgitUtilsTest.java
tests/com/gitblit/tests/TimeUtilsTest.java
tests/com/gitblit/tests/UserServiceTest.java

index 5de2265e55cf1a7d608dc426e536e90a98011180..fd9135fd8f8e645e72e1cc19c60cfbfa1ed42701 100644 (file)
@@ -130,6 +130,11 @@ public class GitBlitServer {
         */\r
        private static void start(Params params) {\r
                FileSettings settings = Params.FILESETTINGS;\r
+               if (!StringUtils.isEmpty(params.settingsfile)) {\r
+                       if (new File(params.settingsfile).exists()) {\r
+                               settings = new FileSettings(params.settingsfile);                               \r
+                       }\r
+               }\r
 \r
                logger = LoggerFactory.getLogger(GitBlitServer.class);\r
                logger.info(Constants.BORDER);\r
@@ -462,5 +467,11 @@ public class GitBlitServer {
                @Parameter(names = "--shutdownPort", description = "Port for Shutdown Monitor to listen on. (port <= 0 will disable this monitor)")\r
                public Integer shutdownPort = FILESETTINGS.getInteger(Keys.server.shutdownPort, 8081);\r
 \r
+               /*\r
+                * Setting overrides\r
+                */\r
+               @Parameter(names = { "--settings" }, description = "Path to alternative settings")\r
+               public String settingsfile;\r
+\r
        }\r
 }
\ No newline at end of file
diff --git a/test-gitblit.properties b/test-gitblit.properties
new file mode 100644 (file)
index 0000000..22556a2
--- /dev/null
@@ -0,0 +1,84 @@
+#
+# Gitblit Unit Testing properties
+#
+
+git.repositoriesFolder = git
+git.searchRepositoriesSubfolders = true
+git.enableGitServlet = true
+web.authenticateViewPages = false
+web.authenticateAdminPages = true
+web.allowCookieAuthentication = true
+realm.userService = test-users.conf
+realm.passwordStorage = md5
+realm.minPasswordLength = 5
+web.siteName =
+web.allowAdministration = true
+web.enableRpcServlet = true
+web.enableRpcManagement = true
+web.enableRpcAdministration = true
+web.allowGravatar = true
+web.allowZipDownloads = true
+web.syndicationEntries = 25
+web.showRepositorySizes = true
+web.showFederationRegistrations = false
+web.loginMessage = gitblit
+web.repositoriesMessage = gitblit
+web.useClientTimezone = false
+web.timeFormat = HH:mm
+web.datestampShortFormat = yyyy-MM-dd
+web.datestampLongFormat = EEEE, MMMM d, yyyy
+web.datetimestampLongFormat = EEEE, MMMM d, yyyy h:mm a z
+web.mountParameters = true
+web.forwardSlashCharacter = /
+web.otherUrls = 
+web.repositoryListType = grouped
+web.repositoryRootGroupName = main
+web.repositoryListSwatches = true
+web.diffStyle = gitblit
+web.showEmailAddresses = true
+web.showSearchTypeSelection = false
+web.generateActivityGraph = true
+web.activityDuration = 14
+web.summaryCommitCount = 16
+web.summaryRefsCount = 5
+web.itemsPerPage = 50
+web.prettyPrintExtensions = c cpp cs css htm html java js php pl prefs properties py rb sh sql xml vb
+web.markdownExtensions = md mkd markdown MD MKD
+web.imageExtensions = bmp jpg gif png 
+web.binaryExtensions = jar pdf tar.gz zip
+web.aggressiveHeapManagement = false
+web.debugMode = false
+regex.global = true
+regex.global.bug = \\b(Bug:)(\\s*[#]?|-){0,1}(\\d+)\\b!!!<a href="http://somehost/bug/$3">Bug-Id: $3</a>
+regex.global.changeid = \\b(Change-Id:\\s*)([A-Za-z0-9]*)\\b!!!<a href="http://somehost/changeid/$2">Change-Id: $2</a>
+regex.myrepository.bug = \\b(Bug:)(\\s*[#]?|-){0,1}(\\d+)\\b!!!<a href="http://elsewhere/bug/$3">Bug-Id: $3</a>
+mail.server =
+mail.port = 25
+mail.debug = false
+mail.username =
+mail.password =
+mail.fromAddress = 
+mail.adminAddresses = 
+federation.name = Unit Test
+federation.passphrase = Unit Testing
+federation.allowProposals = false
+federation.proposalsFolder = proposals
+federation.defaultFrequency = 60 mins
+federation.sets = animal mineral vegetable
+federation.example1.url = https://go.gitblit.com
+federation.example1.token = 6f3b8a24bf970f17289b234284c94f43eb42f0e4
+federation.example1.frequency = 120 mins
+federation.example1.folder =
+federation.example1.bare = true 
+federation.example1.mirror = true 
+federation.example1.mergeAccounts = true
+
+server.tempFolder = temp
+server.useNio = true
+server.contextPath = /
+server.httpPort = 0
+server.httpsPort = 8443
+server.httpBindInterface = localhost
+server.httpsBindInterface = localhost
+server.storePassword = gitblit
+server.shutdownPort = 8081
diff --git a/test-users.conf b/test-users.conf
new file mode 100644 (file)
index 0000000..70e9a87
--- /dev/null
@@ -0,0 +1,6 @@
+[user "admin"]
+       password = admin
+       role = "#admin"
+       role = "#notfederated"
+[team "admins"]
+       user = admin
index b7e5f7a1dc333657a47956384adbe2b279ae1bf6..2271326032cb41aa15b2d12143c72339da2ab96b 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+\r
 import java.io.IOException;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.models.GravatarProfile;\r
 import com.gitblit.utils.ActivityUtils;\r
 \r
-public class ActivityTest extends TestCase {\r
+public class ActivityTest {\r
 \r
+       @Test\r
        public void testGravatarProfile() throws IOException {          \r
                GravatarProfile profile = ActivityUtils.getGravatarProfile("beau@dentedreality.com.au");\r
                assertEquals("beau", profile.preferredUsername);\r
index 31277362959c311c207e1cf5e0faf6983749458c..2962c36fd24ec23c59ccb30142e77130259e24ae 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import junit.framework.TestCase;\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.Base64;\r
 \r
-public class Base64Test extends TestCase {\r
+public class Base64Test {\r
 \r
+       @Test\r
        public void testBase64() {\r
-               String source = "this is a test";               \r
+               String source = "this is a test";\r
                String base64 = Base64.encodeBytes(source.getBytes());\r
                assertEquals("dGhpcyBpcyBhIHRlc3Q=", base64);\r
                String decoded = new String(Base64.decode(base64));\r
index 43fee350b4d0254c832182fcd9f755b1131aa802..d59055e7b13c03a9cbabe7bf62484e5c198c3967 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import junit.framework.TestCase;\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.ByteFormat;\r
 \r
-public class ByteFormatTest extends TestCase {\r
+public class ByteFormatTest {\r
 \r
+       @Test\r
        public void testByteFormat() throws Exception {\r
                ByteFormat format = new ByteFormat();\r
-               assertTrue(format.format(10).equals("10 b"));\r
-               assertTrue(format.format(1024 * 10).equals("10 KB"));\r
-               assertTrue(format.format(1024 * 1000).equals("1,000 KB"));\r
-               assertTrue(format.format(2 * 1024 * 1000).equals("2.0 MB"));\r
-               assertTrue(format.format(1024 * 1024 * 1000).equals("1,000.0 MB"));\r
-               assertTrue(format.format(2 * 1024 * 1024 * 1000).equals("2.0 GB"));\r
+               assertEquals("10 b", format.format(10));\r
+               assertEquals("10 KB", format.format(1024 * 10));\r
+               assertEquals("1,000 KB", format.format(1024 * 1000));\r
+               assertEquals("2.0 MB", format.format(2 * 1024 * 1000));\r
+               assertEquals("1,000.0 MB", format.format(1024 * 1024 * 1000));\r
+               assertEquals("2.0 GB", format.format(2 * 1024 * 1024 * 1000));\r
        }\r
 }\r
index ff6f2328db331af8ab19b4e49fd6d4f3e65fd236..53eff3132f4f32d547a3d4aee6825c8ca9908719 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import java.util.List;\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
-import junit.framework.TestCase;\r
+import java.util.List;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.models.AnnotatedLine;\r
 import com.gitblit.utils.DiffUtils;\r
 import com.gitblit.utils.DiffUtils.DiffOutputType;\r
 import com.gitblit.utils.JGitUtils;\r
 \r
-public class DiffUtilsTest extends TestCase {\r
+public class DiffUtilsTest {\r
 \r
+       @Test\r
        public void testDiffOutputTypes() throws Exception {\r
-               assertTrue(DiffOutputType.forName("plain").equals(DiffOutputType.PLAIN));\r
-               assertTrue(DiffOutputType.forName("gitweb").equals(DiffOutputType.GITWEB));\r
-               assertTrue(DiffOutputType.forName("gitblit").equals(DiffOutputType.GITBLIT));\r
-               assertTrue(DiffOutputType.forName(null) == null);\r
+               assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));\r
+               assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));\r
+               assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));\r
+               assertEquals(null, DiffOutputType.forName(null));\r
        }\r
 \r
+       @Test\r
        public void testParentCommitDiff() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
@@ -47,6 +51,7 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(diff.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testArbitraryCommitDiff() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit baseCommit = JGitUtils.getCommit(repository,\r
@@ -60,6 +65,7 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(diff.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testPlainFileDiff() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
@@ -71,6 +77,7 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(diff.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testFilePatch() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
@@ -82,6 +89,7 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(patch.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testArbitraryFilePatch() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit baseCommit = JGitUtils.getCommit(repository,\r
@@ -95,6 +103,7 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(patch.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testArbitraryCommitPatch() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit baseCommit = JGitUtils.getCommit(repository,\r
@@ -108,12 +117,13 @@ public class DiffUtilsTest extends TestCase {
                assertTrue(patch.indexOf(expected) > -1);\r
        }\r
 \r
+       @Test\r
        public void testBlame() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",\r
                                "1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
                repository.close();\r
                assertTrue(lines.size() > 0);\r
-               assertTrue(lines.get(0).commitId.equals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0"));\r
+               assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);\r
        }\r
 }\r
index e81867b9e05f6049623306e766dd650bd4b09614..ed65100d78e223d1c0ad0d7b062b80a4514f6fe3 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+\r
 import java.io.IOException;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
-import java.util.concurrent.Executors;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.FederationProposalResult;\r
 import com.gitblit.Constants.FederationRequest;\r
 import com.gitblit.Constants.FederationToken;\r
-import com.gitblit.GitBlitServer;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.FederationUtils;\r
 import com.gitblit.utils.JsonUtils;\r
 \r
-public class FederationTests extends TestCase {\r
-\r
-       int port = 8180;\r
+public class FederationTests {\r
 \r
-       int shutdownPort = 8181;\r
+       String url = GitBlitSuite.url;\r
+       String account = GitBlitSuite.account;\r
+       String password = GitBlitSuite.password;\r
 \r
-       @Override\r
-       protected void setUp() throws Exception {\r
-               // Start a Gitblit instance\r
-               Executors.newSingleThreadExecutor().execute(new Runnable() {\r
-                       public void run() {\r
-                               GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",\r
-                                               "" + shutdownPort, "--repositoriesFolder",\r
-                                               "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",\r
-                                               "distrib/users.conf");\r
-                       }\r
-               });\r
+       private static final AtomicBoolean started = new AtomicBoolean(false);\r
 \r
-               // Wait a few seconds for it to be running\r
-               Thread.sleep(2500);\r
+       @BeforeClass\r
+       public static void startGitblit() throws Exception {\r
+               started.set(GitBlitSuite.startGitblit());\r
        }\r
 \r
-       @Override\r
-       protected void tearDown() throws Exception {\r
-               // Stop Gitblit\r
-               GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);\r
-\r
-               // Wait a few seconds for it to be running\r
-               Thread.sleep(2500);\r
+       @AfterClass\r
+       public static void stopGitblit() throws Exception {\r
+               if (started.get()) {\r
+                       GitBlitSuite.stopGitblit();\r
+               }\r
        }\r
 \r
+       @Test\r
        public void testProposal() throws Exception {\r
                // create dummy repository data\r
                Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
@@ -83,16 +76,16 @@ public class FederationTests extends TestCase {
                                "testtoken", repositories);\r
 \r
                // propose federation\r
-               assertEquals("proposal refused",\r
-                               FederationUtils.propose("http://localhost:" + port, proposal),\r
+               assertEquals("proposal refused", FederationUtils.propose(url, proposal),\r
                                FederationProposalResult.NO_PROPOSALS);\r
        }\r
 \r
+       @Test\r
        public void testPullRepositories() throws Exception {\r
                try {\r
-                       String url = FederationUtils.asLink("http://localhost:" + port, "testtoken",\r
+                       String requrl = FederationUtils.asLink(url, "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c",\r
                                        FederationRequest.PULL_REPOSITORIES);\r
-                       String json = JsonUtils.retrieveJsonString(url, null, null);\r
+                       String json = JsonUtils.retrieveJsonString(requrl, null, null);\r
                } catch (IOException e) {\r
                        if (!e.getMessage().contains("403")) {\r
                                throw e;\r
index 025a2238e04abadc3de3bdf7cac891f9e5cb2733..12161bc2d8b4e99246233bd5ccf00d05636be0e1 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.File;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.FileUtils;\r
 \r
-public class FileUtilsTest extends TestCase {\r
+public class FileUtilsTest {\r
 \r
+       @Test\r
        public void testReadContent() throws Exception {\r
                File dir = new File(System.getProperty("user.dir"));\r
                String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");\r
                assertTrue(rawContent.trim().startsWith("Apache License"));\r
        }\r
-       \r
+\r
+       @Test\r
        public void testWriteContent() throws Exception {\r
                String contentA = "this is a test";\r
                File tmp = File.createTempFile("gitblit-", ".test");\r
@@ -37,6 +42,7 @@ public class FileUtilsTest extends TestCase {
                assertEquals(contentA, contentB);\r
        }\r
 \r
+       @Test\r
        public void testFolderSize() throws Exception {\r
                assertEquals(-1, FileUtils.folderSize(null));\r
                assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));\r
@@ -47,7 +53,6 @@ public class FileUtilsTest extends TestCase {
 \r
                File file = new File(System.getProperty("user.dir"), "LICENSE");\r
                size = FileUtils.folderSize(file);\r
-               assertTrue("size is actually " + size, size == 11556L);\r
-\r
+               assertEquals("size is actually " + size, 11556L, size);\r
        }\r
 }
\ No newline at end of file
index a2ab3e8b3f757864700fd3649cc779f73ef58f60..1d90b15715a05a1efe1758c452439dfbc34bd515 100644 (file)
@@ -17,23 +17,42 @@ package com.gitblit.tests;
 \r
 import java.io.File;\r
 import java.util.concurrent.Executors;\r
-\r
-import junit.extensions.TestSetup;\r
-import junit.framework.Test;\r
-import junit.framework.TestSuite;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.storage.file.FileRepository;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
+import org.junit.runner.RunWith;\r
+import org.junit.runners.Suite;\r
+import org.junit.runners.Suite.SuiteClasses;\r
 \r
-import com.gitblit.ConfigUserService;\r
-import com.gitblit.FileSettings;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.GitBlitServer;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.JGitUtils;\r
 \r
-public class GitBlitSuite extends TestSetup {\r
+/**\r
+ * The GitBlitSuite uses test-gitblit.properties and test-users.conf. The suite\r
+ * is fairly comprehensive for all lower-level functionality. Wicket pages are\r
+ * currently not unit-tested.\r
+ * \r
+ * This suite starts a Gitblit server instance within the same JVM instance as\r
+ * the unit tests. This allows the unit tests to access the GitBlit static\r
+ * singleton while also being able to communicate with the instance via tcp/ip\r
+ * for testing rpc requests, federation requests, and git servlet operations.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+@RunWith(Suite.class)\r
+@SuiteClasses({ FileUtilsTest.class, TimeUtilsTest.class, StringUtilsTest.class, Base64Test.class,\r
+               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
+public class GitBlitSuite {\r
 \r
        public static final File REPOSITORIES = new File("git");\r
 \r
@@ -44,30 +63,7 @@ public class GitBlitSuite extends TestSetup {
        public static String account = "admin";\r
        public static String password = "admin";\r
 \r
-       private GitBlitSuite(TestSuite suite) {\r
-               super(suite);\r
-       }\r
-\r
-       public static Test suite() {\r
-               TestSuite suite = new TestSuite();\r
-               suite.addTestSuite(FileUtilsTest.class);\r
-               suite.addTestSuite(TimeUtilsTest.class);\r
-               suite.addTestSuite(StringUtilsTest.class);\r
-               suite.addTestSuite(Base64Test.class);\r
-               suite.addTestSuite(JsonUtilsTest.class);\r
-               suite.addTestSuite(ByteFormatTest.class);\r
-               suite.addTestSuite(ObjectCacheTest.class);\r
-               suite.addTestSuite(UserServiceTest.class);\r
-               suite.addTestSuite(MarkdownUtilsTest.class);\r
-               suite.addTestSuite(JGitUtilsTest.class);\r
-               suite.addTestSuite(SyndicationUtilsTest.class);\r
-               suite.addTestSuite(DiffUtilsTest.class);\r
-               suite.addTestSuite(MetricUtilsTest.class);\r
-               suite.addTestSuite(TicgitUtilsTest.class);\r
-               suite.addTestSuite(GitBlitTest.class);\r
-               suite.addTestSuite(RpcTests.class);\r
-               return new GitBlitSuite(suite);\r
-       }\r
+       private static AtomicBoolean started = new AtomicBoolean(false);\r
 \r
        public static Repository getHelloworldRepository() throws Exception {\r
                return new FileRepository(new File(REPOSITORIES, "helloworld.git"));\r
@@ -85,19 +81,26 @@ public class GitBlitSuite extends TestSetup {
                return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));\r
        }\r
 \r
-       public static void startGitblit() throws Exception {\r
+       public static boolean startGitblit() throws Exception {\r
+               if (started.get()) {\r
+                       // already started\r
+                       return false;\r
+               }\r
                // Start a Gitblit instance\r
                Executors.newSingleThreadExecutor().execute(new Runnable() {\r
                        public void run() {\r
                                GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",\r
                                                "" + shutdownPort, "--repositoriesFolder",\r
                                                "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",\r
-                                               "distrib/users.conf");\r
+                                               "test-users.conf", "--settings", "test-gitblit.properties");\r
                        }\r
                });\r
 \r
                // Wait a few seconds for it to be running\r
                Thread.sleep(2500);\r
+\r
+               started.set(true);\r
+               return true;\r
        }\r
 \r
        public static void stopGitblit() throws Exception {\r
@@ -108,12 +111,9 @@ public class GitBlitSuite extends TestSetup {
                Thread.sleep(2500);\r
        }\r
 \r
-       @Override\r
-       protected void setUp() throws Exception {\r
-               FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
-               GitBlit.self().configureContext(settings, true);\r
-               ConfigUserService loginService = new ConfigUserService(new File("distrib/users.conf"));\r
-               GitBlit.self().setUserService(loginService);\r
+       @BeforeClass\r
+       public static void setUp() throws Exception {\r
+               startGitblit();\r
 \r
                if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {\r
                        cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");\r
@@ -128,22 +128,20 @@ public class GitBlitSuite extends TestSetup {
                        showRemoteBranches("ticgit.git");\r
                        showRemoteBranches("test/jgit.git");\r
                }\r
-\r
-               startGitblit();\r
        }\r
 \r
-       @Override\r
-       protected void tearDown() throws Exception {\r
+       @AfterClass\r
+       public static void tearDown() throws Exception {\r
                stopGitblit();\r
        }\r
 \r
-       private void cloneOrFetch(String name, String fromUrl) throws Exception {\r
+       private static void cloneOrFetch(String name, String fromUrl) throws Exception {\r
                System.out.print("Fetching " + name + "... ");\r
                JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);\r
                System.out.println("done.");\r
        }\r
 \r
-       private void enableTickets(String repositoryName) {\r
+       private static void enableTickets(String repositoryName) {\r
                try {\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
                        model.useTickets = true;\r
@@ -153,7 +151,7 @@ public class GitBlitSuite extends TestSetup {
                }\r
        }\r
 \r
-       private void enableDocs(String repositoryName) {\r
+       private static void enableDocs(String repositoryName) {\r
                try {\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
                        model.useDocs = true;\r
@@ -163,7 +161,7 @@ public class GitBlitSuite extends TestSetup {
                }\r
        }\r
 \r
-       private void showRemoteBranches(String repositoryName) {\r
+       private static void showRemoteBranches(String repositoryName) {\r
                try {\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
                        model.showRemoteBranches = true;\r
index 6d36d4973bdc7153a155ae6ad4dcfbbd261b1502..00b5854667213185ab0c984b263c22f32310d9d2 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.junit.Assert.assertNotNull;\r
+\r
 import java.util.List;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.FileSettings;\r
@@ -25,8 +30,9 @@ import com.gitblit.GitBlit;
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 \r
-public class GitBlitTest extends TestCase {\r
+public class GitBlitTest {\r
 \r
+       @Test\r
        public void testRepositoryModel() throws Exception {\r
                List<String> repositories = GitBlit.self().getRepositoryList();\r
                assertTrue("Repository list is empty!", repositories.size() > 0);\r
@@ -37,23 +43,24 @@ public class GitBlitTest extends TestCase {
                RepositoryModel model = GitBlit.self().getRepositoryModel(\r
                                GitBlitSuite.getHelloworldRepository().getDirectory().getName());\r
                assertTrue("Helloworld model is null!", model != null);\r
-               assertTrue(model.toString().equals(\r
-                               GitBlitSuite.getHelloworldRepository().getDirectory().getName()));\r
+               assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.toString());\r
                assertTrue(GitBlit.self().calculateSize(model) > 22000L);\r
        }\r
 \r
+       @Test\r
        public void testUserModel() throws Exception {\r
                List<String> users = GitBlit.self().getAllUsernames();\r
                assertTrue("No users found!", users.size() > 0);\r
                assertTrue("Admin not found", users.contains("admin"));\r
                UserModel model = GitBlit.self().getUserModel("admin");\r
-               assertTrue(model.toString().equals("admin"));\r
+               assertEquals("admin", model.toString());\r
                assertTrue("Admin missing #admin role!", model.canAdmin);\r
                model.canAdmin = false;\r
                assertFalse("Admin should not have #admin!", model.canAdmin);\r
                String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();\r
-               RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(model, repository);\r
-               assertFalse("Admin can still access repository!", model.canAccessRepository(repositoryModel));\r
+               RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repository);\r
+               assertFalse("Admin can still access repository!",\r
+                               model.canAccessRepository(repositoryModel));\r
                model.addRepository(repository);\r
                assertTrue("Admin can't access repository!", model.canAccessRepository(repositoryModel));\r
                assertEquals(GitBlit.self().getRepositoryModel(model, "pretend"), null);\r
@@ -61,6 +68,7 @@ public class GitBlitTest extends TestCase {
                assertTrue(GitBlit.self().getRepositoryModels(model).size() > 0);\r
        }\r
 \r
+       @Test\r
        public void testAccessRestrictionTypes() throws Exception {\r
                assertTrue(AccessRestrictionType.PUSH.exceeds(AccessRestrictionType.NONE));\r
                assertTrue(AccessRestrictionType.CLONE.exceeds(AccessRestrictionType.PUSH));\r
@@ -82,22 +90,23 @@ public class GitBlitTest extends TestCase {
                assertTrue(AccessRestrictionType.CLONE.toString().equals("CLONE"));\r
                assertTrue(AccessRestrictionType.VIEW.toString().equals("VIEW"));\r
 \r
-               assertTrue(AccessRestrictionType.fromName("none").equals(AccessRestrictionType.NONE));\r
-               assertTrue(AccessRestrictionType.fromName("push").equals(AccessRestrictionType.PUSH));\r
-               assertTrue(AccessRestrictionType.fromName("clone").equals(AccessRestrictionType.CLONE));\r
-               assertTrue(AccessRestrictionType.fromName("view").equals(AccessRestrictionType.VIEW));\r
+               assertEquals(AccessRestrictionType.NONE, AccessRestrictionType.fromName("none"));\r
+               assertEquals(AccessRestrictionType.PUSH, AccessRestrictionType.fromName("push"));\r
+               assertEquals(AccessRestrictionType.CLONE, AccessRestrictionType.fromName("clone"));\r
+               assertEquals(AccessRestrictionType.VIEW, AccessRestrictionType.fromName("view"));\r
        }\r
 \r
+       @Test\r
        public void testFileSettings() throws Exception {\r
                FileSettings settings = new FileSettings("distrib/gitblit.properties");\r
-               assertTrue(settings.getBoolean("missing", true));\r
-               assertTrue(settings.getString("missing", "default").equals("default"));\r
-               assertTrue(settings.getInteger("missing", 10) == 10);\r
-               assertTrue(settings.getInteger("realm.realmFile", 5) == 5);\r
+               assertEquals(true, settings.getBoolean("missing", true));\r
+               assertEquals("default", settings.getString("missing", "default"));\r
+               assertEquals(10, settings.getInteger("missing", 10));\r
+               assertEquals(5, settings.getInteger("realm.realmFile", 5));\r
 \r
                assertTrue(settings.getBoolean("git.enableGitServlet", false));\r
-               assertTrue(settings.getString("realm.userService", null).equals("users.conf"));\r
-               assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);\r
+               assertEquals("users.conf", settings.getString("realm.userService", null));\r
+               assertEquals(5, settings.getInteger("realm.minPasswordLength", 0));\r
                List<String> mdExtensions = settings.getStrings("web.markdownExtensions");\r
                assertTrue(mdExtensions.size() > 0);\r
                assertTrue(mdExtensions.contains("md"));\r
@@ -109,6 +118,7 @@ public class GitBlitTest extends TestCase {
                assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');\r
        }\r
 \r
+       @Test\r
        public void testGitblitSettings() throws Exception {\r
                // These are already tested by above test method.\r
                assertTrue(GitBlit.getBoolean("missing", true));\r
@@ -117,7 +127,7 @@ public class GitBlitTest extends TestCase {
                assertEquals(5, GitBlit.getInteger("realm.userService", 5));\r
 \r
                assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));\r
-               assertEquals("distrib/users.conf", GitBlit.getString("realm.userService", null));\r
+               assertEquals("test-users.conf", GitBlit.getString("realm.userService", null));\r
                assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));\r
                List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");\r
                assertTrue(mdExtensions.size() > 0);\r
@@ -131,10 +141,12 @@ public class GitBlitTest extends TestCase {
                assertFalse(GitBlit.isDebugMode());\r
        }\r
 \r
+       @Test\r
        public void testAuthentication() throws Exception {\r
                assertTrue(GitBlit.self().authenticate("admin", "admin".toCharArray()) != null);\r
        }\r
 \r
+       @Test\r
        public void testRepositories() throws Exception {\r
                assertTrue(GitBlit.self().getRepository("missing") == null);\r
                assertTrue(GitBlit.self().getRepositoryModel("missing") == null);\r
index db8182de60a41bb72f16ceeb173d21a6b182337d..548a72bcfdc36f82a4be9d6967a6d0238d87474d 100644 (file)
@@ -1,12 +1,15 @@
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.BufferedWriter;\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 import java.io.OutputStreamWriter;\r
 import java.text.MessageFormat;\r
 import java.util.Date;\r
-import java.util.concurrent.Executors;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
 import org.eclipse.jgit.api.CloneCommand;\r
 import org.eclipse.jgit.api.Git;\r
@@ -16,39 +19,30 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;\r
 import org.junit.Test;\r
 \r
-import com.gitblit.GitBlitServer;\r
+import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.models.RepositoryModel;\r
 \r
 public class GitServletTest {\r
 \r
        File folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");\r
 \r
-       static int port = 8180;\r
+       String url = GitBlitSuite.url;\r
+       String account = GitBlitSuite.account;\r
+       String password = GitBlitSuite.password;\r
 \r
-       static int shutdownPort = 8181;\r
+       private static final AtomicBoolean started = new AtomicBoolean(false);\r
 \r
        @BeforeClass\r
        public static void startGitblit() throws Exception {\r
-               // Start a Gitblit instance\r
-               Executors.newSingleThreadExecutor().execute(new Runnable() {\r
-                       public void run() {\r
-                               GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",\r
-                                               "" + shutdownPort, "--repositoriesFolder",\r
-                                               "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",\r
-                                               "distrib/users.conf");\r
-                       }\r
-               });\r
-\r
-               // Wait a few seconds for it to be running\r
-               Thread.sleep(2500);\r
+               started.set(GitBlitSuite.startGitblit());\r
        }\r
 \r
        @AfterClass\r
        public static void stopGitblit() throws Exception {\r
-               // Stop Gitblit\r
-               GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);\r
-\r
-               // Wait a few seconds for it to be running\r
-               Thread.sleep(2500);\r
+               if (started.get()) {\r
+                       GitBlitSuite.stopGitblit();\r
+               }\r
        }\r
 \r
        @Test\r
@@ -57,11 +51,46 @@ public class GitServletTest {
                        FileUtils.delete(folder, FileUtils.RECURSIVE);\r
                }\r
                CloneCommand clone = Git.cloneRepository();\r
-               clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/ticgit.git", port));\r
+               clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));\r
                clone.setDirectory(folder);\r
                clone.setBare(false);\r
                clone.setCloneAllBranches(true);\r
+               clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));\r
                clone.call();\r
+               assertTrue(true);\r
+       }\r
+\r
+       @Test\r
+       public void testBogusLoginClone() throws Exception {\r
+               // restrict repository access\r
+               RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");\r
+               model.accessRestriction = AccessRestrictionType.CLONE;\r
+               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+\r
+               // delete any existing working folder\r
+               File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");\r
+               if (folder.exists()) {\r
+                       FileUtils.delete(folder, FileUtils.RECURSIVE);\r
+               }\r
+               boolean cloned = false;\r
+               try {\r
+                       CloneCommand clone = Git.cloneRepository();\r
+                       clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));\r
+                       clone.setDirectory(folder);\r
+                       clone.setBare(false);\r
+                       clone.setCloneAllBranches(true);\r
+                       clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));\r
+                       clone.call();\r
+                       cloned = true;\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+\r
+               // restore anonymous repository access\r
+               model.accessRestriction = AccessRestrictionType.NONE;\r
+               GitBlit.self().updateRepositoryModel(model.name, model, false);\r
+\r
+               assertFalse("Bogus login cloned a repository?!", cloned);\r
        }\r
 \r
        @Test\r
@@ -77,19 +106,4 @@ public class GitServletTest {
                git.push().setPushAll().call();\r
                git.getRepository().close();\r
        }\r
-\r
-       @Test\r
-       public void testBogusLoginClone() throws Exception {\r
-               File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");\r
-               if (folder.exists()) {\r
-                       FileUtils.delete(folder, FileUtils.RECURSIVE);\r
-               }\r
-               CloneCommand clone = Git.cloneRepository();\r
-               clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/gitblit.git", port));\r
-               clone.setDirectory(folder);\r
-               clone.setBare(false);\r
-               clone.setCloneAllBranches(true);\r
-               clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));\r
-               clone.call();\r
-       }\r
 }\r
index 7cd79adcdac5e7d5cd38eceaa457a20740a16ffd..e330c4262c21a079d6bc9efb641db6889d82033b 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
 import java.text.SimpleDateFormat;\r
@@ -23,8 +29,6 @@ import java.util.Date;
 import java.util.List;\r
 import java.util.Map;\r
 \r
-import junit.framework.TestCase;\r
-\r
 import org.eclipse.jgit.diff.DiffEntry.ChangeType;\r
 import org.eclipse.jgit.lib.Constants;\r
 import org.eclipse.jgit.lib.FileMode;\r
@@ -35,7 +39,9 @@ import org.eclipse.jgit.lib.RepositoryCache.FileKey;
 import org.eclipse.jgit.revwalk.RevCommit;\r
 import org.eclipse.jgit.util.FS;\r
 import org.eclipse.jgit.util.FileUtils;\r
+import org.junit.Test;\r
 \r
+import com.gitblit.Constants.SearchType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.GitNote;\r
@@ -45,56 +51,62 @@ import com.gitblit.models.RefModel;
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
-public class JGitUtilsTest extends TestCase {\r
+public class JGitUtilsTest {\r
 \r
+       @Test\r
        public void testDisplayName() throws Exception {\r
-               assertTrue(JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")).equals(\r
-                               "Napoleon Bonaparte"));\r
-               assertTrue(JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")).equals(\r
-                               "<someone@somewhere.com>"));\r
-               assertTrue(JGitUtils.getDisplayName(\r
-                               new PersonIdent("Napoleon Bonaparte", "someone@somewhere.com")).equals(\r
-                               "Napoleon Bonaparte <someone@somewhere.com>"));\r
+               assertEquals("Napoleon Bonaparte",\r
+                               JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")));\r
+               assertEquals("<someone@somewhere.com>",\r
+                               JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")));\r
+               assertEquals("Napoleon Bonaparte <someone@somewhere.com>",\r
+                               JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte",\r
+                                               "someone@somewhere.com")));\r
        }\r
 \r
+       @Test\r
        public void testFindRepositories() {\r
                List<String> list = JGitUtils.getRepositoryList(null, true, true);\r
-               assertTrue(list.size() == 0);\r
+               assertEquals(0, list.size());\r
                list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));\r
-               assertTrue(list.size() == 0);\r
+               assertEquals(0, list.size());\r
                list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, true, true));\r
                assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);\r
        }\r
 \r
+       @Test\r
        public void testOpenRepository() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                repository.close();\r
-               assertTrue("Could not find repository!", repository != null);\r
+               assertNotNull("Could not find repository!", repository);\r
        }\r
 \r
+       @Test\r
        public void testFirstCommit() throws Exception {\r
-               assertTrue(JGitUtils.getFirstChange(null, null).equals(new Date(0)));\r
+               assertEquals(new Date(0), JGitUtils.getFirstChange(null, null));\r
 \r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getFirstCommit(repository, null);\r
                Date firstChange = JGitUtils.getFirstChange(repository, null);\r
                repository.close();\r
-               assertTrue("Could not get first commit!", commit != null);\r
-               assertTrue("Incorrect first commit!",\r
-                               commit.getName().equals("f554664a346629dc2b839f7292d06bad2db4aece"));\r
+               assertNotNull("Could not get first commit!", commit);\r
+               assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",\r
+                               commit.getName());\r
                assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));\r
        }\r
 \r
+       @Test\r
        public void testLastCommit() throws Exception {\r
-               assertTrue(JGitUtils.getLastChange(null, null).equals(new Date(0)));\r
+               assertEquals(new Date(0), JGitUtils.getLastChange(null, null));\r
 \r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                assertTrue(JGitUtils.getCommit(repository, null) != null);\r
                Date date = JGitUtils.getLastChange(repository, null);\r
                repository.close();\r
-               assertTrue("Could not get last repository change date!", date != null);\r
+               assertNotNull("Could not get last repository change date!", date);\r
        }\r
 \r
+       @Test\r
        public void testCreateRepository() throws Exception {\r
                String[] repositories = { "NewTestRepository.git", "NewTestRepository" };\r
                for (String repositoryName : repositories) {\r
@@ -102,18 +114,19 @@ public class JGitUtilsTest extends TestCase {
                                        repositoryName);\r
                        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),\r
                                        FS.DETECTED);\r
-                       assertTrue(repository != null);\r
+                       assertNotNull(repository);\r
                        assertFalse(JGitUtils.hasCommits(repository));\r
-                       assertTrue(JGitUtils.getFirstCommit(repository, null) == null);\r
-                       assertTrue(JGitUtils.getFirstChange(repository, null).getTime() == folder\r
-                                       .lastModified());\r
-                       assertTrue(JGitUtils.getLastChange(repository, null).getTime() == folder.lastModified());\r
-                       assertTrue(JGitUtils.getCommit(repository, null) == null);\r
+                       assertNull(JGitUtils.getFirstCommit(repository, null));\r
+                       assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)\r
+                                       .getTime());\r
+                       assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository, null).getTime());\r
+                       assertNull(JGitUtils.getCommit(repository, null));\r
                        repository.close();\r
                        assertTrue(GitBlit.self().deleteRepository(repositoryName));\r
                }\r
        }\r
 \r
+       @Test\r
        public void testRefs() throws Exception {\r
                Repository repository = GitBlitSuite.getJGitRepository();\r
                Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);\r
@@ -123,13 +136,13 @@ public class JGitUtilsTest extends TestCase {
                        List<RefModel> list = entry.getValue();\r
                        for (RefModel ref : list) {\r
                                if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {\r
-                                       assertTrue(ref.toString().equals("refs/tags/spearce-gpg-pub"));\r
-                                       assertTrue(ref.getObjectId().getName()\r
-                                                       .equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));\r
-                                       assertTrue(ref.getAuthorIdent().getEmailAddress().equals("spearce@spearce.org"));\r
+                                       assertEquals("refs/tags/spearce-gpg-pub", ref.toString());\r
+                                       assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId()\r
+                                                       .getName());\r
+                                       assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());\r
                                        assertTrue(ref.getShortMessage().startsWith("GPG key"));\r
                                        assertTrue(ref.getFullMessage().startsWith("GPG key"));\r
-                                       assertTrue(ref.getReferencedObjectType() == Constants.OBJ_BLOB);\r
+                                       assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());\r
                                } else if (ref.displayName.equals("refs/tags/v0.12.1")) {\r
                                        assertTrue(ref.isAnnotatedTag());\r
                                }\r
@@ -137,6 +150,7 @@ public class JGitUtilsTest extends TestCase {
                }\r
        }\r
 \r
+       @Test\r
        public void testBranches() throws Exception {\r
                Repository repository = GitBlitSuite.getJGitRepository();\r
                assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);\r
@@ -160,6 +174,7 @@ public class JGitUtilsTest extends TestCase {
                repository.close();\r
        }\r
 \r
+       @Test\r
        public void testTags() throws Exception {\r
                Repository repository = GitBlitSuite.getJGitRepository();\r
                assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);\r
@@ -180,13 +195,13 @@ public class JGitUtilsTest extends TestCase {
                        if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {\r
                                assertFalse(model.isAnnotatedTag());\r
                                assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));\r
-                               assertTrue(model.getFullMessage().equals(\r
-                                               "Update changelog and bump version number\n"));\r
+                               assertEquals("Update changelog and bump version number\n", model.getFullMessage());\r
                        }\r
                }\r
                repository.close();\r
        }\r
 \r
+       @Test\r
        public void testCommitNotes() throws Exception {\r
                Repository repository = GitBlitSuite.getJGitRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
@@ -194,10 +209,11 @@ public class JGitUtilsTest extends TestCase {
                List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);\r
                repository.close();\r
                assertTrue(list.size() > 0);\r
-               assertTrue(list.get(0).notesRef.getReferencedObjectId().getName()\r
-                               .equals("183474d554e6f68478a02d9d7888b67a9338cdff"));\r
+               assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef\r
+                               .getReferencedObjectId().getName());\r
        }\r
 \r
+       @Test\r
        public void testCreateOrphanedBranch() throws Exception {\r
                Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");\r
                assertTrue(JGitUtils.createOrphanBranch(repository,\r
@@ -205,6 +221,7 @@ public class JGitUtilsTest extends TestCase {
                FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);\r
        }\r
 \r
+       @Test\r
        public void testStringContent() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                String contentA = JGitUtils.getStringContent(repository, null, "java.java");\r
@@ -222,10 +239,11 @@ public class JGitUtilsTest extends TestCase {
                assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);\r
                assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);\r
                assertTrue(contentA.equals(contentB));\r
-               assertTrue(contentC == null);\r
+               assertNull(contentC);\r
                assertTrue(contentA.equals(contentD));\r
        }\r
 \r
+       @Test\r
        public void testFilesInCommit() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RevCommit commit = JGitUtils.getCommit(repository,\r
@@ -248,19 +266,21 @@ public class JGitUtilsTest extends TestCase {
                        assertTrue("PathChangeModel equals itself failed!", path.equals(path));\r
                        assertFalse("PathChangeModel equals string failed!", path.equals(""));\r
                }\r
-               assertTrue(deletions.get(0).changeType.equals(ChangeType.DELETE));\r
-               assertTrue(additions.get(0).changeType.equals(ChangeType.ADD));\r
+               assertEquals(ChangeType.DELETE, deletions.get(0).changeType);\r
+               assertEquals(ChangeType.ADD, additions.get(0).changeType);\r
                assertTrue(latestChanges.size() > 0);\r
        }\r
 \r
+       @Test\r
        public void testFilesInPath() throws Exception {\r
-               assertTrue(JGitUtils.getFilesInPath(null, null, null).size() == 0);\r
+               assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);\r
                repository.close();\r
                assertTrue(files.size() > 10);\r
        }\r
 \r
+       @Test\r
        public void testDocuments() throws Exception {\r
                Repository repository = GitBlitSuite.getTicgitRepository();\r
                List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);\r
@@ -274,17 +294,19 @@ public class JGitUtilsTest extends TestCase {
                assertTrue(allFiles.size() > markdownDocs.size());\r
        }\r
 \r
+       @Test\r
        public void testFileModes() throws Exception {\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()).equals("drwxr-xr-x"));\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()).equals(\r
-                               "-rw-r--r--"));\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()).equals(\r
-                               "-rwxr-xr-x"));\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()).equals("symlink"));\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()).equals("gitlink"));\r
-               assertTrue(JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()).equals("missing"));\r
+               assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));\r
+               assertEquals("-rw-r--r--",\r
+                               JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));\r
+               assertEquals("-rwxr-xr-x",\r
+                               JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));\r
+               assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));\r
+               assertEquals("gitlink", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));\r
+               assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));\r
        }\r
 \r
+       @Test\r
        public void testRevlog() throws Exception {\r
                assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);\r
                List<RevCommit> commits = JGitUtils.getRevLog(null, 10);\r
@@ -302,51 +324,55 @@ public class JGitUtilsTest extends TestCase {
                // grab the two most recent commits to java.java\r
                commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);\r
                assertEquals(2, commits.size());\r
-               \r
+\r
                // grab the commits since 2008-07-15\r
-               commits = JGitUtils.getRevLog(repository, null, new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));\r
+               commits = JGitUtils.getRevLog(repository, null,\r
+                               new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));\r
                assertEquals(12, commits.size());\r
                repository.close();\r
        }\r
 \r
+       @Test\r
        public void testSearchTypes() throws Exception {\r
-               assertTrue(com.gitblit.Constants.SearchType.forName("commit").equals(com.gitblit.Constants.SearchType.COMMIT));\r
-               assertTrue(com.gitblit.Constants.SearchType.forName("committer").equals(com.gitblit.Constants.SearchType.COMMITTER));\r
-               assertTrue(com.gitblit.Constants.SearchType.forName("author").equals(com.gitblit.Constants.SearchType.AUTHOR));\r
-               assertTrue(com.gitblit.Constants.SearchType.forName("unknown").equals(com.gitblit.Constants.SearchType.COMMIT));\r
-\r
-               assertTrue(com.gitblit.Constants.SearchType.COMMIT.toString().equals("commit"));\r
-               assertTrue(com.gitblit.Constants.SearchType.COMMITTER.toString().equals("committer"));\r
-               assertTrue(com.gitblit.Constants.SearchType.AUTHOR.toString().equals("author"));\r
+               assertEquals(SearchType.COMMIT, SearchType.forName("commit"));\r
+               assertEquals(SearchType.COMMITTER, SearchType.forName("committer"));\r
+               assertEquals(SearchType.AUTHOR, SearchType.forName("author"));\r
+               assertEquals(SearchType.COMMIT, SearchType.forName("unknown"));\r
+\r
+               assertEquals("commit", SearchType.COMMIT.toString());\r
+               assertEquals("committer", SearchType.COMMITTER.toString());\r
+               assertEquals("author", SearchType.AUTHOR.toString());\r
        }\r
 \r
+       @Test\r
        public void testSearchRevlogs() throws Exception {\r
-               assertTrue(JGitUtils.searchRevlogs(null, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0, 0).size() == 0);\r
-               List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0,\r
+               assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());\r
+               List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0,\r
                                3);\r
-               assertTrue(results.size() == 0);\r
+               assertEquals(0, results.size());\r
 \r
                // test commit message search\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
-               results = JGitUtils.searchRevlogs(repository, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0, 3);\r
-               assertTrue(results.size() == 3);\r
+               results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);\r
+               assertEquals(3, results.size());\r
 \r
                // test author search\r
-               results = JGitUtils.searchRevlogs(repository, null, "timothy", com.gitblit.Constants.SearchType.AUTHOR, 0, -1);\r
-               assertTrue(results.size() == 1);\r
+               results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);\r
+               assertEquals(1, results.size());\r
 \r
                // test committer search\r
-               results = JGitUtils.searchRevlogs(repository, null, "mike", com.gitblit.Constants.SearchType.COMMITTER, 0, 10);\r
-               assertTrue(results.size() == 10);\r
+               results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);\r
+               assertEquals(10, results.size());\r
 \r
                // test paging and offset\r
-               RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", com.gitblit.Constants.SearchType.COMMITTER,\r
+               RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER,\r
                                9, 1).get(0);\r
-               assertTrue(results.get(9).equals(commit));\r
+               assertEquals(results.get(9), commit);\r
 \r
                repository.close();\r
        }\r
 \r
+       @Test\r
        public void testZip() throws Exception {\r
                assertFalse(JGitUtils.zip(null, null, null, null));\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
index e70bd8a0e00a405a7578419ea48aa5c6cdc2bbfa..cf058441caf81ceacfcce1ed351ace135093c62b 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+\r
 import java.text.SimpleDateFormat;\r
 import java.util.Date;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.JsonUtils;\r
 import com.google.gson.reflect.TypeToken;\r
 \r
-public class JsonUtilsTest extends TestCase {\r
+public class JsonUtilsTest {\r
 \r
+       @Test\r
        public void testSerialization() {\r
                Map<String, String> map = new HashMap<String, String>();\r
                map.put("a", "alligator");\r
index 55002cee959ab72b9d7ac7131208a3c34e710e67..05d55a24dcd39bdca99f22dcf32ae85f1409266a 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertTrue;\r
+\r
 import javax.mail.Message;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.FileSettings;\r
 import com.gitblit.MailExecutor;\r
 \r
-public class MailTest extends TestCase {\r
+public class MailTest {\r
 \r
+       @Test\r
        public void testSendMail() throws Exception {\r
                FileSettings settings = new FileSettings("mailtest.properties");\r
                MailExecutor mail = new MailExecutor(settings);\r
@@ -31,7 +34,7 @@ public class MailTest extends TestCase {
                message.setSubject("Test");\r
                message.setText("this is a test");\r
                mail.queue(message);\r
-               mail.run();             \r
+               mail.run();\r
 \r
                assertTrue("mail queue is not empty!", mail.hasEmptyQueue());\r
        }\r
index d421fb16934f2e027f8d3c1a5bc7fac8c834af4a..cd7ca0201406d3bb73900efff8145cabc7ce7e44 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.text.ParseException;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.MarkdownUtils;\r
 \r
-public class MarkdownUtilsTest extends TestCase {\r
+public class MarkdownUtilsTest {\r
 \r
+       @Test\r
        public void testMarkdown() throws Exception {\r
                assertEquals("<h1> H1</h1>", MarkdownUtils.transformMarkdown("# H1"));\r
                assertEquals("<h2> H2</h2>", MarkdownUtils.transformMarkdown("## H2"));\r
@@ -34,8 +38,9 @@ public class MarkdownUtilsTest extends TestCase {
                                MarkdownUtils.transformMarkdown("**THIS ** is a test"));\r
                assertEquals("<p>** THIS** is a test</p>",\r
                                MarkdownUtils.transformMarkdown("** THIS** is a test"));\r
-               \r
-               assertEquals("<table><tr><td>test</td></tr></table>", MarkdownUtils.transformMarkdown("<table><tr><td>test</td></tr></table>"));\r
+\r
+               assertEquals("<table><tr><td>test</td></tr></table>",\r
+                               MarkdownUtils.transformMarkdown("<table><tr><td>test</td></tr></table>"));\r
                assertEquals("<table><tr><td>&lt;test&gt;</td></tr></table>",\r
                                MarkdownUtils.transformMarkdown("<table><tr><td>&lt;test&gt;</td></tr></table>"));\r
 \r
index bfa34b4b93db13e187ecc11002f70aa4c3219e63..71bf2ed7c6d61c4f0dfbca34b9c9190cc2d272f5 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import java.util.List;\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
-import junit.framework.TestCase;\r
+import java.util.List;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.models.Metric;\r
 import com.gitblit.utils.MetricUtils;\r
 \r
-public class MetricUtilsTest extends TestCase {\r
+public class MetricUtilsTest {\r
 \r
+       @Test\r
        public void testMetrics() throws Exception {\r
                testMetrics(GitBlitSuite.getHelloworldRepository());\r
                testMetrics(GitBlitSuite.getBluezGnomeRepository());\r
@@ -37,12 +40,13 @@ public class MetricUtilsTest extends TestCase {
                assertTrue("No date metrics found!", metrics.size() > 0);\r
        }\r
 \r
+       @Test\r
        public void testAuthorMetrics() throws Exception {\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);\r
                List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);\r
                repository.close();\r
-               assertTrue("No author metrics found!", byEmail.size() == 9);\r
-               assertTrue("No author metrics found!", byName.size() == 8);\r
+               assertEquals("No author metrics found!", 9, byEmail.size());\r
+               assertEquals("No author metrics found!", 8, byName.size());\r
        }\r
 }
\ No newline at end of file
index 054761ffded8c497a51198fef108cf75d9944fae..8d07fe65cfdfe6d4ea7871975c6b402cdb685db7 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.util.Date;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.ObjectCache;\r
 \r
-public class ObjectCacheTest extends TestCase {\r
+public class ObjectCacheTest {\r
 \r
+       @Test\r
        public void testCache() throws Exception {\r
                ObjectCache<String> cache = new ObjectCache<String>();\r
                cache.updateObject("test", "alpha");\r
index ab6a8b8a10435b9480d420cf0dd9010cf890f24c..30dc84dcc889d9e82fdaa235311616a08db01535 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.IOException;\r
 import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
-\r
-import junit.framework.TestCase;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
 import org.junit.AfterClass;\r
 import org.junit.BeforeClass;\r
@@ -45,27 +49,30 @@ import com.gitblit.utils.RpcUtils;
  * @author James Moger\r
  * \r
  */\r
-public class RpcTests extends TestCase {\r
-       \r
+public class RpcTests {\r
+\r
        String url = GitBlitSuite.url;\r
        String account = GitBlitSuite.account;\r
        String password = GitBlitSuite.password;\r
-       \r
+\r
+       private static final AtomicBoolean started = new AtomicBoolean(false);\r
 \r
        @BeforeClass\r
        public static void startGitblit() throws Exception {\r
-               GitBlitSuite.startGitblit();\r
+               started.set(GitBlitSuite.startGitblit());\r
        }\r
 \r
        @AfterClass\r
        public static void stopGitblit() throws Exception {\r
-               GitBlitSuite.stopGitblit();\r
+               if (started.get()) {\r
+                       GitBlitSuite.stopGitblit();\r
+               }\r
        }\r
 \r
        @Test\r
        public void testListRepositories() throws IOException {\r
                Map<String, RepositoryModel> map = RpcUtils.getRepositories(url, null, null);\r
-               assertTrue("Repository list is null!", map != null);\r
+               assertNotNull("Repository list is null!", map);\r
                assertTrue("Repository list is empty!", map.size() > 0);\r
        }\r
 \r
@@ -76,7 +83,7 @@ public class RpcTests extends TestCase {
                        list = RpcUtils.getUsers(url, null, null);\r
                } catch (UnauthorizedException e) {\r
                }\r
-               assertTrue("Server allows anyone to admin!", list == null);\r
+               assertNull("Server allows anyone to admin!", list);\r
 \r
                list = RpcUtils.getUsers(url, "admin", "admin".toCharArray());\r
                assertTrue("User list is empty!", list.size() > 0);\r
@@ -93,7 +100,7 @@ public class RpcTests extends TestCase {
                                RpcUtils.createUser(user, url, account, password.toCharArray()));\r
 \r
                UserModel retrievedUser = findUser(user.username);\r
-               assertTrue("Failed to find " + user.username, retrievedUser != null);\r
+               assertNotNull("Failed to find " + user.username, retrievedUser);\r
                assertTrue("Retrieved user can not administer Gitblit", retrievedUser.canAdmin);\r
 \r
                // rename and toggle admin permission\r
@@ -104,7 +111,7 @@ public class RpcTests extends TestCase {
                                RpcUtils.updateUser(originalName, user, url, account, password.toCharArray()));\r
 \r
                retrievedUser = findUser(user.username);\r
-               assertTrue("Failed to find " + user.username, retrievedUser != null);\r
+               assertNotNull("Failed to find " + user.username, retrievedUser);\r
                assertTrue("Retrieved user did not update", !retrievedUser.canAdmin);\r
 \r
                // delete\r
@@ -112,7 +119,7 @@ public class RpcTests extends TestCase {
                                RpcUtils.deleteUser(retrievedUser, url, account, password.toCharArray()));\r
 \r
                retrievedUser = findUser(user.username);\r
-               assertTrue("Failed to delete " + user.username, retrievedUser == null);\r
+               assertNull("Failed to delete " + user.username, retrievedUser);\r
        }\r
 \r
        private UserModel findUser(String name) throws IOException {\r
@@ -140,9 +147,8 @@ public class RpcTests extends TestCase {
                                RpcUtils.createRepository(model, url, account, password.toCharArray()));\r
 \r
                RepositoryModel retrievedRepository = findRepository(model.name);\r
-               assertTrue("Failed to find " + model.name, retrievedRepository != null);\r
-               assertTrue("Access retriction type is wrong",\r
-                               AccessRestrictionType.VIEW.equals(retrievedRepository.accessRestriction));\r
+               assertNotNull("Failed to find " + model.name, retrievedRepository);\r
+               assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);\r
 \r
                // rename and change access restriciton\r
                String originalName = model.name;\r
@@ -152,16 +158,18 @@ public class RpcTests extends TestCase {
                                url, account, password.toCharArray()));\r
 \r
                retrievedRepository = findRepository(model.name);\r
-               assertTrue("Failed to find " + model.name, retrievedRepository != null);\r
+               assertNotNull("Failed to find " + model.name, retrievedRepository);\r
                assertTrue("Access retriction type is wrong",\r
                                AccessRestrictionType.PUSH.equals(retrievedRepository.accessRestriction));\r
 \r
                // memberships\r
-               String testMember = "justadded";\r
+               UserModel testMember = new UserModel("justadded");\r
+               assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));\r
+\r
                List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,\r
                                password.toCharArray());\r
-               assertTrue("Membership roster is not empty!", members.size() == 0);\r
-               members.add(testMember);\r
+               assertEquals("Membership roster is not empty!", 0, members.size());\r
+               members.add(testMember.username);\r
                assertTrue(\r
                                "Failed to set memberships!",\r
                                RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,\r
@@ -170,7 +178,7 @@ public class RpcTests extends TestCase {
                                password.toCharArray());\r
                boolean foundMember = false;\r
                for (String member : members) {\r
-                       if (member.equalsIgnoreCase(testMember)) {\r
+                       if (member.equalsIgnoreCase(testMember.username)) {\r
                                foundMember = true;\r
                                break;\r
                        }\r
@@ -182,11 +190,11 @@ public class RpcTests extends TestCase {
                                url, account, password.toCharArray()));\r
 \r
                retrievedRepository = findRepository(model.name);\r
-               assertTrue("Failed to delete " + model.name, retrievedRepository == null);\r
+               assertNull("Failed to delete " + model.name, retrievedRepository);\r
 \r
                for (UserModel u : RpcUtils.getUsers(url, account, password.toCharArray())) {\r
-                       if (u.username.equals(testMember)) {\r
-                               RpcUtils.deleteUser(u, url, account, password.toCharArray());\r
+                       if (u.username.equals(testMember.username)) {\r
+                               assertTrue(RpcUtils.deleteUser(u, url, account, password.toCharArray()));\r
                                break;\r
                        }\r
                }\r
@@ -235,13 +243,13 @@ public class RpcTests extends TestCase {
        @Test\r
        public void testSettings() throws Exception {\r
                ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());\r
-               assertTrue("No settings were retrieved!", settings != null);\r
+               assertNotNull("No settings were retrieved!", settings);\r
        }\r
 \r
        @Test\r
        public void testServerStatus() throws Exception {\r
                ServerStatus status = RpcUtils.getStatus(url, account, password.toCharArray());\r
-               assertTrue("No status was retrieved!", status != null);\r
+               assertNotNull("No status was retrieved!", status);\r
        }\r
 \r
        @Test\r
@@ -272,7 +280,7 @@ public class RpcTests extends TestCase {
        public void testBranches() throws Exception {\r
                Map<String, Collection<String>> branches = RpcUtils.getBranches(url, account,\r
                                password.toCharArray());\r
-               assertTrue(branches != null);\r
+               assertNotNull(branches);\r
                assertTrue(branches.size() > 0);\r
        }\r
 }\r
index 489972a7e1d99b46df5fa8492d56f6abaa35744c..71d055f46b88e0387b4811026271ef6320faf77c 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.util.Arrays;\r
 import java.util.List;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.StringUtils;\r
 \r
-public class StringUtilsTest extends TestCase {\r
+public class StringUtilsTest {\r
 \r
+       @Test\r
        public void testIsEmpty() throws Exception {\r
                assertTrue(StringUtils.isEmpty(null));\r
                assertTrue(StringUtils.isEmpty(""));\r
@@ -31,86 +36,99 @@ public class StringUtilsTest extends TestCase {
                assertFalse(StringUtils.isEmpty("A"));\r
        }\r
 \r
+       @Test\r
        public void testBreakLinesForHtml() throws Exception {\r
                String input = "this\nis\r\na\rtest\r\n\r\nof\n\nline\r\rbreaking";\r
                String output = "this<br/>is<br/>a<br/>test<br/><br/>of<br/><br/>line<br/><br/>breaking";\r
-               assertTrue(StringUtils.breakLinesForHtml(input).equals(output));\r
+               assertEquals(output, StringUtils.breakLinesForHtml(input));\r
        }\r
 \r
+       @Test\r
        public void testEncodeUrl() throws Exception {\r
                String input = "test /";\r
                String output = "test%20%2F";\r
-               assertTrue(StringUtils.encodeURL(input).equals(output));\r
+               assertEquals(output, StringUtils.encodeURL(input));\r
        }\r
 \r
+       @Test\r
        public void testEscapeForHtml() throws Exception {\r
                String input = "& < > \" \t";\r
                String outputNoChange = "&amp; &lt; &gt; &quot; \t";\r
                String outputChange = "&amp;&nbsp;&lt;&nbsp;&gt;&nbsp;&quot;&nbsp; &nbsp; &nbsp;";\r
-               assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));\r
-               assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));\r
+               assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));\r
+               assertEquals(outputChange, StringUtils.escapeForHtml(input, true));\r
        }\r
 \r
+       @Test\r
        public void testDecodeForHtml() throws Exception {\r
                String input = "&amp; &lt; &gt; &quot;";\r
                String output = "& < > \"";\r
-               assertTrue(StringUtils.decodeFromHtml(input).equals(output));\r
+               assertEquals(output, StringUtils.decodeFromHtml(input));\r
        }\r
 \r
+       @Test\r
        public void testFlattenStrings() throws Exception {\r
                String[] strings = { "A", "B", "C", "D" };\r
-               assertTrue(StringUtils.flattenStrings(Arrays.asList(strings)).equals("A B C D"));\r
+               assertEquals("A B C D", StringUtils.flattenStrings(Arrays.asList(strings)));\r
        }\r
 \r
+       @Test\r
        public void testTrim() throws Exception {\r
                String input = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 ";\r
                String output = "123456789 123456789 123456789 123456789 123456789 1234567...";\r
-               assertTrue(StringUtils.trimShortLog(input).equals(output));\r
-               assertTrue(StringUtils.trimString(input, input.length()).equals(input));\r
+               assertEquals(output, StringUtils.trimShortLog(input));\r
+               assertEquals(input, StringUtils.trimString(input, input.length()));\r
        }\r
 \r
+       @Test\r
        public void testPadding() throws Exception {\r
                String input = "test";\r
-               assertTrue(StringUtils.leftPad(input, 6 + input.length(), ' ').equals("      test"));\r
-               assertTrue(StringUtils.rightPad(input, 6 + input.length(), ' ').equals("test      "));\r
+               assertEquals("      test", StringUtils.leftPad(input, 6 + input.length(), ' '));\r
+               assertEquals("test      ", StringUtils.rightPad(input, 6 + input.length(), ' '));\r
 \r
-               assertTrue(StringUtils.leftPad(input, input.length(), ' ').equals(input));\r
-               assertTrue(StringUtils.rightPad(input, input.length(), ' ').equals(input));\r
+               assertEquals(input, StringUtils.leftPad(input, input.length(), ' '));\r
+               assertEquals(input, StringUtils.rightPad(input, input.length(), ' '));\r
        }\r
 \r
+       @Test\r
        public void testSHA1() throws Exception {\r
-               assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(\r
-                               "bd9dbf5aae1a3862dd1526723246b20206e5fc37"));\r
+               assertEquals("bd9dbf5aae1a3862dd1526723246b20206e5fc37",\r
+                               StringUtils.getSHA1("blob 16\000what is up, doc?"));\r
        }\r
 \r
+       @Test\r
        public void testMD5() throws Exception {\r
-               assertTrue(StringUtils.getMD5("blob 16\000what is up, doc?").equals(\r
-                               "77fb8d95331f0d557472f6776d3aedf6"));\r
+               assertEquals("77fb8d95331f0d557472f6776d3aedf6",\r
+                               StringUtils.getMD5("blob 16\000what is up, doc?"));\r
        }\r
 \r
+       @Test\r
        public void testRootPath() throws Exception {\r
                String input = "/nested/path/to/repository";\r
                String output = "/nested/path/to";\r
-               assertTrue(StringUtils.getRootPath(input).equals(output));\r
-               assertTrue(StringUtils.getRootPath("repository").equals(""));\r
+               assertEquals(output, StringUtils.getRootPath(input));\r
+               assertEquals("", StringUtils.getRootPath("repository"));\r
        }\r
 \r
+       @Test\r
        public void testStringsFromValue() throws Exception {\r
                List<String> strings = StringUtils.getStringsFromValue("A B C D");\r
-               assertTrue(strings.size() == 4);\r
-               assertTrue(strings.get(0).equals("A"));\r
-               assertTrue(strings.get(1).equals("B"));\r
-               assertTrue(strings.get(2).equals("C"));\r
-               assertTrue(strings.get(3).equals("D"));\r
+               assertEquals(4, strings.size());\r
+               assertEquals("A", strings.get(0));\r
+               assertEquals("B", strings.get(1));\r
+               assertEquals("C", strings.get(2));\r
+               assertEquals("D", strings.get(3));\r
        }\r
 \r
+       @Test\r
        public void testStringsFromValue2() throws Exception {\r
                List<String> strings = StringUtils.getStringsFromValue("common/* libraries/*");\r
-               assertTrue(strings.size() == 2);\r
-               assertTrue(strings.get(0).equals("common/*"));\r
-               assertTrue(strings.get(1).equals("libraries/*"));\r
+               assertEquals(2, strings.size());\r
+               assertEquals("common/*", strings.get(0));\r
+               assertEquals("libraries/*", strings.get(1));\r
        }\r
 \r
+       @Test\r
        public void testFuzzyMatching() throws Exception {\r
                assertTrue(StringUtils.fuzzyMatch("12345", "12345"));\r
                assertTrue(StringUtils.fuzzyMatch("AbCdEf", "abcdef"));\r
index 448874f431d20eb7b1471d1743e814255dee0400..ca6678de2bb4d1d7a955bd60873e5f51c986f3d6 100644 (file)
@@ -15,6 +15,9 @@
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.ByteArrayOutputStream;\r
 import java.util.ArrayList;\r
 import java.util.Date;\r
@@ -22,14 +25,15 @@ import java.util.HashSet;
 import java.util.List;\r
 import java.util.Set;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.Constants.SearchType;\r
 import com.gitblit.models.FeedEntryModel;\r
 import com.gitblit.utils.SyndicationUtils;\r
 \r
-public class SyndicationUtilsTest extends TestCase {\r
+public class SyndicationUtilsTest {\r
 \r
+       @Test\r
        public void testSyndication() throws Exception {\r
                List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();\r
                for (int i = 0; i < 10; i++) {\r
@@ -58,12 +62,12 @@ public class SyndicationUtilsTest extends TestCase {
                assertTrue(feed.indexOf("<description>Description</description>") > -1);\r
        }\r
 \r
+       @Test\r
        public void testFeedRead() throws Exception {\r
                Set<String> links = new HashSet<String>();\r
                for (int i = 0; i < 2; i++) {\r
-                       List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url,\r
-                                       "ticgit.git", "deving", 5, i, GitBlitSuite.account,\r
-                                       GitBlitSuite.password.toCharArray());\r
+                       List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",\r
+                                       "deving", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());\r
                        assertTrue(feed != null);\r
                        assertTrue(feed.size() > 0);\r
                        assertEquals(5, feed.size());\r
@@ -75,10 +79,11 @@ public class SyndicationUtilsTest extends TestCase {
                assertEquals("Feed pagination failed", 10, links.size());\r
        }\r
 \r
+       @Test\r
        public void testSearchFeedRead() throws Exception {\r
-               List<FeedEntryModel> feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url,\r
-                               "ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account,\r
-                               GitBlitSuite.password.toCharArray());\r
+               List<FeedEntryModel> feed = SyndicationUtils\r
+                               .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,\r
+                                               GitBlitSuite.account, GitBlitSuite.password.toCharArray());\r
                assertTrue(feed != null);\r
                assertTrue(feed.size() > 0);\r
                assertEquals(5, feed.size());\r
index 9f5a488bbe8d50cc50cea46cbdc5dae3c6a74e71..a77dae43b0b38845228978f3ad5a4027b06b5416 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
-import java.util.List;\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.junit.Assert.assertTrue;\r
 \r
-import junit.framework.TestCase;\r
+import java.util.List;\r
 \r
 import org.eclipse.jgit.lib.Repository;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.TicketModel;\r
 import com.gitblit.models.TicketModel.Comment;\r
 import com.gitblit.utils.TicgitUtils;\r
 \r
-public class TicgitUtilsTest extends TestCase {\r
+public class TicgitUtilsTest {\r
 \r
+       @Test\r
        public void testTicgitBranch() throws Exception {\r
                Repository repository = GitBlitSuite.getTicgitRepository();\r
                RefModel branch = TicgitUtils.getTicketsBranch(repository);\r
                repository.close();\r
-               assertTrue("Ticgit branch does not exist!", branch != null);\r
+               assertNotNull("Ticgit branch does not exist!", branch);\r
 \r
                repository = GitBlitSuite.getHelloworldRepository();\r
                branch = TicgitUtils.getTicketsBranch(repository);\r
                repository.close();\r
-               assertTrue("Ticgit branch exists!", branch == null);\r
+               assertNull("Ticgit branch exists!", branch);\r
        }\r
 \r
+       @Test\r
        public void testRetrieveTickets() throws Exception {\r
                Repository repository = GitBlitSuite.getTicgitRepository();\r
                List<TicketModel> ticketsA = TicgitUtils.getTickets(repository);\r
@@ -57,24 +64,26 @@ public class TicgitUtilsTest extends TestCase {
                                Comment commentB = ticketB.comments.get(j);\r
                                assertTrue("Comments are not equal!", commentA.equals(commentB));\r
                                assertFalse(commentA.equals(""));\r
-                               assertTrue(commentA.hashCode() == commentA.text.hashCode());\r
+                               assertEquals(commentA.hashCode(), commentA.text.hashCode());\r
                        }\r
                }\r
 \r
                repository = GitBlitSuite.getHelloworldRepository();\r
                List<TicketModel> ticketsC = TicgitUtils.getTickets(repository);\r
                repository.close();\r
-               assertTrue(ticketsC == null);\r
+               assertNull(ticketsC);\r
        }\r
 \r
+       @Test\r
        public void testReadTicket() throws Exception {\r
                Repository repository = GitBlitSuite.getTicgitRepository();\r
                List<TicketModel> tickets = TicgitUtils.getTickets(repository);\r
                TicketModel ticket = TicgitUtils\r
                                .getTicket(repository, tickets.get(tickets.size() - 1).name);\r
                repository.close();\r
-               assertTrue(ticket != null);\r
-               assertTrue(ticket.name\r
-                               .equals("1254123752_comments-on-ticgits-longer-than-5-lines-can-t-be-viewed-entirely_266"));\r
+               assertNotNull(ticket);\r
+               assertEquals(\r
+                               "1254123752_comments-on-ticgits-longer-than-5-lines-can-t-be-viewed-entirely_266",\r
+                               ticket.name);\r
        }\r
 }
\ No newline at end of file
index 530e53c947071fd8155ee0ed91cf9525122ebe68..9d94df89c282f1ffec6b6c6e9d6ae2722f09bddf 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.util.Date;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.utils.TimeUtils;\r
 \r
-public class TimeUtilsTest extends TestCase {\r
+public class TimeUtilsTest {\r
 \r
        private Date offset(long subtract) {\r
                return new Date(System.currentTimeMillis() - subtract);\r
        }\r
 \r
+       @Test\r
        public void testBasicTimeFunctions() throws Exception {\r
                assertEquals(2, TimeUtils.minutesAgo(offset(2 * TimeUtils.MIN), false));\r
                assertEquals(3, TimeUtils.minutesAgo(offset((2 * TimeUtils.MIN) + (35 * 1000L)), true));\r
@@ -37,14 +41,17 @@ public class TimeUtilsTest extends TestCase {
                assertEquals(4, TimeUtils.daysAgo(offset(4 * TimeUtils.ONEDAY)));\r
        }\r
 \r
+       @Test\r
        public void testToday() throws Exception {\r
                assertTrue(TimeUtils.isToday(new Date()));\r
        }\r
 \r
+       @Test\r
        public void testYesterday() throws Exception {\r
                assertTrue(TimeUtils.isYesterday(offset(TimeUtils.ONEDAY)));\r
        }\r
 \r
+       @Test\r
        public void testDurations() throws Exception {\r
                assertEquals("1 day", TimeUtils.duration(1));\r
                assertEquals("5 days", TimeUtils.duration(5));\r
@@ -67,6 +74,7 @@ public class TimeUtilsTest extends TestCase {
                assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 60));\r
        }\r
 \r
+       @Test\r
        public void testTimeAgo() throws Exception {\r
                // standard time ago tests\r
                assertEquals("1 min ago", TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)));\r
@@ -91,6 +99,7 @@ public class TimeUtilsTest extends TestCase {
                assertEquals("age2", TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));\r
        }\r
 \r
+       @Test\r
        public void testFrequency() {\r
                assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins"));\r
                assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins"));\r
index 3dfdf7ac81fb2ecc7af4c540e964f94b713dd398..3f410fa53a94a10b808aad05a57ea1c5627ee54a 100644 (file)
  */\r
 package com.gitblit.tests;\r
 \r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
 import java.io.File;\r
 import java.io.IOException;\r
 \r
-import junit.framework.TestCase;\r
+import org.junit.Test;\r
 \r
 import com.gitblit.ConfigUserService;\r
 import com.gitblit.FileUserService;\r
 import com.gitblit.IUserService;\r
+import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 \r
-public class UserServiceTest extends TestCase {\r
+public class UserServiceTest {\r
 \r
+       @Test\r
        public void testFileUserService() throws IOException {\r
                File file = new File("us-test.properties");\r
                file.delete();\r
-               test(new FileUserService(file));\r
+               IUserService service = new FileUserService(file);\r
+               testUsers(service);\r
                file.delete();\r
        }\r
 \r
+       @Test\r
        public void testConfigUserService() throws IOException {\r
                File file = new File("us-test.conf");\r
                file.delete();\r
-               test(new ConfigUserService(file));\r
+               IUserService service = new ConfigUserService(file);\r
+               testUsers(service);\r
                file.delete();\r
        }\r
 \r
-       protected void test(IUserService service) {\r
+       protected void testUsers(IUserService service) {\r
 \r
                UserModel admin = service.getUserModel("admin");\r
                assertTrue(admin == null);\r