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.
*/\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
@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
--- /dev/null
+#
+# 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
--- /dev/null
+[user "admin"]
+ password = admin
+ role = "#admin"
+ role = "#notfederated"
+[team "admins"]
+ user = admin
*/\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
*/\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
*/\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
*/\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
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
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
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
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
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
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
*/\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
"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
*/\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
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
\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
\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
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
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
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
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
}\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
}\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
*/\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
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
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
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
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
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
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
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
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
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
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
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
*/\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
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
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
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
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
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
}\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
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
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
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
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
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
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
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
// 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
*/\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
*/\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
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
*/\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
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><test></td></tr></table>",\r
MarkdownUtils.transformMarkdown("<table><tr><td><test></td></tr></table>"));\r
\r
*/\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
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
*/\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
*/\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
* @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
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
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
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
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
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
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
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
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
@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
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
*/\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
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 = "& < > " \t";\r
String outputChange = "& < > " ";\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 = "& < > "";\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
*/\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
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
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
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
*/\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
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
*/\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
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
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
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
*/\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