Unit testing overhaul.
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.
2 files added
22 files modified
| | |
| | | */
|
| | | private static void start(Params params) {
|
| | | FileSettings settings = Params.FILESETTINGS;
|
| | | if (!StringUtils.isEmpty(params.settingsfile)) {
|
| | | if (new File(params.settingsfile).exists()) {
|
| | | settings = new FileSettings(params.settingsfile); |
| | | }
|
| | | }
|
| | |
|
| | | logger = LoggerFactory.getLogger(GitBlitServer.class);
|
| | | logger.info(Constants.BORDER);
|
| | |
| | | @Parameter(names = "--shutdownPort", description = "Port for Shutdown Monitor to listen on. (port <= 0 will disable this monitor)")
|
| | | public Integer shutdownPort = FILESETTINGS.getInteger(Keys.server.shutdownPort, 8081);
|
| | |
|
| | | /*
|
| | | * Setting overrides
|
| | | */
|
| | | @Parameter(names = { "--settings" }, description = "Path to alternative settings")
|
| | | public String settingsfile;
|
| | |
|
| | | }
|
| | | } |
New file |
| | |
| | | # |
| | | # 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 |
New file |
| | |
| | | [user "admin"] |
| | | password = admin |
| | | role = "#admin" |
| | | role = "#notfederated" |
| | | [team "admins"] |
| | | user = admin |
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | |
|
| | | import java.io.IOException;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.models.GravatarProfile;
|
| | | import com.gitblit.utils.ActivityUtils;
|
| | |
|
| | | public class ActivityTest extends TestCase {
|
| | | public class ActivityTest {
|
| | |
|
| | | @Test
|
| | | public void testGravatarProfile() throws IOException {
|
| | | GravatarProfile profile = ActivityUtils.getGravatarProfile("beau@dentedreality.com.au");
|
| | | assertEquals("beau", profile.preferredUsername);
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import static org.junit.Assert.assertEquals;
|
| | |
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.Base64;
|
| | |
|
| | | public class Base64Test extends TestCase {
|
| | | public class Base64Test {
|
| | |
|
| | | @Test
|
| | | public void testBase64() {
|
| | | String source = "this is a test"; |
| | | String source = "this is a test";
|
| | | String base64 = Base64.encodeBytes(source.getBytes());
|
| | | assertEquals("dGhpcyBpcyBhIHRlc3Q=", base64);
|
| | | String decoded = new String(Base64.decode(base64));
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import static org.junit.Assert.assertEquals;
|
| | |
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.ByteFormat;
|
| | |
|
| | | public class ByteFormatTest extends TestCase {
|
| | | public class ByteFormatTest {
|
| | |
|
| | | @Test
|
| | | public void testByteFormat() throws Exception {
|
| | | ByteFormat format = new ByteFormat();
|
| | | assertTrue(format.format(10).equals("10 b"));
|
| | | assertTrue(format.format(1024 * 10).equals("10 KB"));
|
| | | assertTrue(format.format(1024 * 1000).equals("1,000 KB"));
|
| | | assertTrue(format.format(2 * 1024 * 1000).equals("2.0 MB"));
|
| | | assertTrue(format.format(1024 * 1024 * 1000).equals("1,000.0 MB"));
|
| | | assertTrue(format.format(2 * 1024 * 1024 * 1000).equals("2.0 GB"));
|
| | | assertEquals("10 b", format.format(10));
|
| | | assertEquals("10 KB", format.format(1024 * 10));
|
| | | assertEquals("1,000 KB", format.format(1024 * 1000));
|
| | | assertEquals("2.0 MB", format.format(2 * 1024 * 1000));
|
| | | assertEquals("1,000.0 MB", format.format(1024 * 1024 * 1000));
|
| | | assertEquals("2.0 GB", format.format(2 * 1024 * 1024 * 1000));
|
| | | }
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.util.List;
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import java.util.List;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.models.AnnotatedLine;
|
| | | import com.gitblit.utils.DiffUtils;
|
| | | import com.gitblit.utils.DiffUtils.DiffOutputType;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | |
|
| | | public class DiffUtilsTest extends TestCase {
|
| | | public class DiffUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testDiffOutputTypes() throws Exception {
|
| | | assertTrue(DiffOutputType.forName("plain").equals(DiffOutputType.PLAIN));
|
| | | assertTrue(DiffOutputType.forName("gitweb").equals(DiffOutputType.GITWEB));
|
| | | assertTrue(DiffOutputType.forName("gitblit").equals(DiffOutputType.GITBLIT));
|
| | | assertTrue(DiffOutputType.forName(null) == null);
|
| | | assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));
|
| | | assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));
|
| | | assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));
|
| | | assertEquals(null, DiffOutputType.forName(null));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testParentCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testPlainFileDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryCommitPatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBlame() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | repository.close();
|
| | | assertTrue(lines.size() > 0);
|
| | | assertTrue(lines.get(0).commitId.equals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0"));
|
| | | assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
|
| | | }
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.Executors;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.FederationProposalResult;
|
| | | import com.gitblit.Constants.FederationRequest;
|
| | | import com.gitblit.Constants.FederationToken;
|
| | | import com.gitblit.GitBlitServer;
|
| | | import com.gitblit.models.FederationProposal;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.FederationUtils;
|
| | | import com.gitblit.utils.JsonUtils;
|
| | |
|
| | | public class FederationTests extends TestCase {
|
| | | public class FederationTests {
|
| | |
|
| | | int port = 8180;
|
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | |
|
| | | int shutdownPort = 8181;
|
| | | private static final AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | @Override
|
| | | protected void setUp() throws Exception {
|
| | | // Start a Gitblit instance
|
| | | Executors.newSingleThreadExecutor().execute(new Runnable() {
|
| | | public void run() {
|
| | | GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
| | | "" + shutdownPort, "--repositoriesFolder",
|
| | | "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
| | | "distrib/users.conf");
|
| | | }
|
| | | });
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | started.set(GitBlitSuite.startGitblit());
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void tearDown() throws Exception {
|
| | | // Stop Gitblit
|
| | | GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | if (started.get()) {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testProposal() throws Exception {
|
| | | // create dummy repository data
|
| | | Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();
|
| | |
| | | "testtoken", repositories);
|
| | |
|
| | | // propose federation
|
| | | assertEquals("proposal refused",
|
| | | FederationUtils.propose("http://localhost:" + port, proposal),
|
| | | assertEquals("proposal refused", FederationUtils.propose(url, proposal),
|
| | | FederationProposalResult.NO_PROPOSALS);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testPullRepositories() throws Exception {
|
| | | try {
|
| | | String url = FederationUtils.asLink("http://localhost:" + port, "testtoken",
|
| | | String requrl = FederationUtils.asLink(url, "d7cc58921a80b37e0329a4dae2f9af38bf61ef5c",
|
| | | FederationRequest.PULL_REPOSITORIES);
|
| | | String json = JsonUtils.retrieveJsonString(url, null, null);
|
| | | String json = JsonUtils.retrieveJsonString(requrl, null, null);
|
| | | } catch (IOException e) {
|
| | | if (!e.getMessage().contains("403")) {
|
| | | throw e;
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.File;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.FileUtils;
|
| | |
|
| | | public class FileUtilsTest extends TestCase {
|
| | | public class FileUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testReadContent() throws Exception {
|
| | | File dir = new File(System.getProperty("user.dir"));
|
| | | String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");
|
| | | assertTrue(rawContent.trim().startsWith("Apache License"));
|
| | | }
|
| | | |
| | |
|
| | | @Test
|
| | | public void testWriteContent() throws Exception {
|
| | | String contentA = "this is a test";
|
| | | File tmp = File.createTempFile("gitblit-", ".test");
|
| | |
| | | assertEquals(contentA, contentB);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFolderSize() throws Exception {
|
| | | assertEquals(-1, FileUtils.folderSize(null));
|
| | | assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));
|
| | |
| | |
|
| | | File file = new File(System.getProperty("user.dir"), "LICENSE");
|
| | | size = FileUtils.folderSize(file);
|
| | | assertTrue("size is actually " + size, size == 11556L);
|
| | |
|
| | | assertEquals("size is actually " + size, 11556L, size);
|
| | | }
|
| | | } |
| | |
| | |
|
| | | import java.io.File;
|
| | | import java.util.concurrent.Executors;
|
| | |
|
| | | import junit.extensions.TestSetup;
|
| | | import junit.framework.Test;
|
| | | import junit.framework.TestSuite;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.storage.file.FileRepository;
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | | import org.junit.runner.RunWith;
|
| | | import org.junit.runners.Suite;
|
| | | import org.junit.runners.Suite.SuiteClasses;
|
| | |
|
| | | import com.gitblit.ConfigUserService;
|
| | | import com.gitblit.FileSettings;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.GitBlitServer;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | |
|
| | | public class GitBlitSuite extends TestSetup {
|
| | | /**
|
| | | * The GitBlitSuite uses test-gitblit.properties and test-users.conf. The suite
|
| | | * is fairly comprehensive for all lower-level functionality. Wicket pages are
|
| | | * currently not unit-tested.
|
| | | * |
| | | * This suite starts a Gitblit server instance within the same JVM instance as
|
| | | * the unit tests. This allows the unit tests to access the GitBlit static
|
| | | * singleton while also being able to communicate with the instance via tcp/ip
|
| | | * for testing rpc requests, federation requests, and git servlet operations.
|
| | | * |
| | | * @author James Moger
|
| | | * |
| | | */
|
| | | @RunWith(Suite.class)
|
| | | @SuiteClasses({ FileUtilsTest.class, TimeUtilsTest.class, StringUtilsTest.class, Base64Test.class,
|
| | | JsonUtilsTest.class, ByteFormatTest.class, ObjectCacheTest.class, UserServiceTest.class,
|
| | | MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
|
| | | DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class, GitBlitTest.class,
|
| | | FederationTests.class, RpcTests.class, GitServletTest.class })
|
| | | public class GitBlitSuite {
|
| | |
|
| | | public static final File REPOSITORIES = new File("git");
|
| | |
|
| | |
| | | public static String account = "admin";
|
| | | public static String password = "admin";
|
| | |
|
| | | private GitBlitSuite(TestSuite suite) {
|
| | | super(suite);
|
| | | }
|
| | |
|
| | | public static Test suite() {
|
| | | TestSuite suite = new TestSuite();
|
| | | suite.addTestSuite(FileUtilsTest.class);
|
| | | suite.addTestSuite(TimeUtilsTest.class);
|
| | | suite.addTestSuite(StringUtilsTest.class);
|
| | | suite.addTestSuite(Base64Test.class);
|
| | | suite.addTestSuite(JsonUtilsTest.class);
|
| | | suite.addTestSuite(ByteFormatTest.class);
|
| | | suite.addTestSuite(ObjectCacheTest.class);
|
| | | suite.addTestSuite(UserServiceTest.class);
|
| | | suite.addTestSuite(MarkdownUtilsTest.class);
|
| | | suite.addTestSuite(JGitUtilsTest.class);
|
| | | suite.addTestSuite(SyndicationUtilsTest.class);
|
| | | suite.addTestSuite(DiffUtilsTest.class);
|
| | | suite.addTestSuite(MetricUtilsTest.class);
|
| | | suite.addTestSuite(TicgitUtilsTest.class);
|
| | | suite.addTestSuite(GitBlitTest.class);
|
| | | suite.addTestSuite(RpcTests.class);
|
| | | return new GitBlitSuite(suite);
|
| | | }
|
| | | private static AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | public static Repository getHelloworldRepository() throws Exception {
|
| | | return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
|
| | |
| | | return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
|
| | | }
|
| | |
|
| | | public static void startGitblit() throws Exception {
|
| | | public static boolean startGitblit() throws Exception {
|
| | | if (started.get()) {
|
| | | // already started
|
| | | return false;
|
| | | }
|
| | | // Start a Gitblit instance
|
| | | Executors.newSingleThreadExecutor().execute(new Runnable() {
|
| | | public void run() {
|
| | | GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
| | | "" + shutdownPort, "--repositoriesFolder",
|
| | | "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
| | | "distrib/users.conf");
|
| | | "test-users.conf", "--settings", "test-gitblit.properties");
|
| | | }
|
| | | });
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | |
|
| | | started.set(true);
|
| | | return true;
|
| | | }
|
| | |
|
| | | public static void stopGitblit() throws Exception {
|
| | |
| | | Thread.sleep(2500);
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setUp() throws Exception {
|
| | | FileSettings settings = new FileSettings("distrib/gitblit.properties");
|
| | | GitBlit.self().configureContext(settings, true);
|
| | | ConfigUserService loginService = new ConfigUserService(new File("distrib/users.conf"));
|
| | | GitBlit.self().setUserService(loginService);
|
| | | @BeforeClass
|
| | | public static void setUp() throws Exception {
|
| | | startGitblit();
|
| | |
|
| | | if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
|
| | | cloneOrFetch("helloworld.git", "https://github.com/git/hello-world.git");
|
| | |
| | | showRemoteBranches("ticgit.git");
|
| | | showRemoteBranches("test/jgit.git");
|
| | | }
|
| | |
|
| | | startGitblit();
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void tearDown() throws Exception {
|
| | | @AfterClass
|
| | | public static void tearDown() throws Exception {
|
| | | stopGitblit();
|
| | | }
|
| | |
|
| | | private void cloneOrFetch(String name, String fromUrl) throws Exception {
|
| | | private static void cloneOrFetch(String name, String fromUrl) throws Exception {
|
| | | System.out.print("Fetching " + name + "... ");
|
| | | JGitUtils.cloneRepository(REPOSITORIES, name, fromUrl);
|
| | | System.out.println("done.");
|
| | | }
|
| | |
|
| | | private void enableTickets(String repositoryName) {
|
| | | private static void enableTickets(String repositoryName) {
|
| | | try {
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | model.useTickets = true;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void enableDocs(String repositoryName) {
|
| | | private static void enableDocs(String repositoryName) {
|
| | | try {
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | model.useDocs = true;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void showRemoteBranches(String repositoryName) {
|
| | | private static void showRemoteBranches(String repositoryName) {
|
| | | try {
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | model.showRemoteBranches = true;
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertTrue;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.FileSettings;
|
| | |
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
|
| | | public class GitBlitTest extends TestCase {
|
| | | public class GitBlitTest {
|
| | |
|
| | | @Test
|
| | | public void testRepositoryModel() throws Exception {
|
| | | List<String> repositories = GitBlit.self().getRepositoryList();
|
| | | assertTrue("Repository list is empty!", repositories.size() > 0);
|
| | |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(
|
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName());
|
| | | assertTrue("Helloworld model is null!", model != null);
|
| | | assertTrue(model.toString().equals(
|
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()));
|
| | | assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.toString());
|
| | | assertTrue(GitBlit.self().calculateSize(model) > 22000L);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testUserModel() throws Exception {
|
| | | List<String> users = GitBlit.self().getAllUsernames();
|
| | | assertTrue("No users found!", users.size() > 0);
|
| | | assertTrue("Admin not found", users.contains("admin"));
|
| | | UserModel model = GitBlit.self().getUserModel("admin");
|
| | | assertTrue(model.toString().equals("admin"));
|
| | | assertEquals("admin", model.toString());
|
| | | assertTrue("Admin missing #admin role!", model.canAdmin);
|
| | | model.canAdmin = false;
|
| | | assertFalse("Admin should not have #admin!", model.canAdmin);
|
| | | String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();
|
| | | RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(model, repository);
|
| | | assertFalse("Admin can still access repository!", model.canAccessRepository(repositoryModel));
|
| | | RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repository);
|
| | | assertFalse("Admin can still access repository!",
|
| | | model.canAccessRepository(repositoryModel));
|
| | | model.addRepository(repository);
|
| | | assertTrue("Admin can't access repository!", model.canAccessRepository(repositoryModel));
|
| | | assertEquals(GitBlit.self().getRepositoryModel(model, "pretend"), null);
|
| | |
| | | assertTrue(GitBlit.self().getRepositoryModels(model).size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testAccessRestrictionTypes() throws Exception {
|
| | | assertTrue(AccessRestrictionType.PUSH.exceeds(AccessRestrictionType.NONE));
|
| | | assertTrue(AccessRestrictionType.CLONE.exceeds(AccessRestrictionType.PUSH));
|
| | |
| | | assertTrue(AccessRestrictionType.CLONE.toString().equals("CLONE"));
|
| | | assertTrue(AccessRestrictionType.VIEW.toString().equals("VIEW"));
|
| | |
|
| | | assertTrue(AccessRestrictionType.fromName("none").equals(AccessRestrictionType.NONE));
|
| | | assertTrue(AccessRestrictionType.fromName("push").equals(AccessRestrictionType.PUSH));
|
| | | assertTrue(AccessRestrictionType.fromName("clone").equals(AccessRestrictionType.CLONE));
|
| | | assertTrue(AccessRestrictionType.fromName("view").equals(AccessRestrictionType.VIEW));
|
| | | assertEquals(AccessRestrictionType.NONE, AccessRestrictionType.fromName("none"));
|
| | | assertEquals(AccessRestrictionType.PUSH, AccessRestrictionType.fromName("push"));
|
| | | assertEquals(AccessRestrictionType.CLONE, AccessRestrictionType.fromName("clone"));
|
| | | assertEquals(AccessRestrictionType.VIEW, AccessRestrictionType.fromName("view"));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFileSettings() throws Exception {
|
| | | FileSettings settings = new FileSettings("distrib/gitblit.properties");
|
| | | assertTrue(settings.getBoolean("missing", true));
|
| | | assertTrue(settings.getString("missing", "default").equals("default"));
|
| | | assertTrue(settings.getInteger("missing", 10) == 10);
|
| | | assertTrue(settings.getInteger("realm.realmFile", 5) == 5);
|
| | | assertEquals(true, settings.getBoolean("missing", true));
|
| | | assertEquals("default", settings.getString("missing", "default"));
|
| | | assertEquals(10, settings.getInteger("missing", 10));
|
| | | assertEquals(5, settings.getInteger("realm.realmFile", 5));
|
| | |
|
| | | assertTrue(settings.getBoolean("git.enableGitServlet", false));
|
| | | assertTrue(settings.getString("realm.userService", null).equals("users.conf"));
|
| | | assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);
|
| | | assertEquals("users.conf", settings.getString("realm.userService", null));
|
| | | assertEquals(5, settings.getInteger("realm.minPasswordLength", 0));
|
| | | List<String> mdExtensions = settings.getStrings("web.markdownExtensions");
|
| | | assertTrue(mdExtensions.size() > 0);
|
| | | assertTrue(mdExtensions.contains("md"));
|
| | |
| | | assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testGitblitSettings() throws Exception {
|
| | | // These are already tested by above test method.
|
| | | assertTrue(GitBlit.getBoolean("missing", true));
|
| | |
| | | assertEquals(5, GitBlit.getInteger("realm.userService", 5));
|
| | |
|
| | | assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));
|
| | | assertEquals("distrib/users.conf", GitBlit.getString("realm.userService", null));
|
| | | assertEquals("test-users.conf", GitBlit.getString("realm.userService", null));
|
| | | assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));
|
| | | List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");
|
| | | assertTrue(mdExtensions.size() > 0);
|
| | |
| | | assertFalse(GitBlit.isDebugMode());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testAuthentication() throws Exception {
|
| | | assertTrue(GitBlit.self().authenticate("admin", "admin".toCharArray()) != null);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRepositories() throws Exception {
|
| | | assertTrue(GitBlit.self().getRepository("missing") == null);
|
| | | assertTrue(GitBlit.self().getRepositoryModel("missing") == null);
|
| | |
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.BufferedWriter;
|
| | | import java.io.File;
|
| | | import java.io.FileOutputStream;
|
| | | import java.io.OutputStreamWriter;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.Date;
|
| | | import java.util.concurrent.Executors;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | import org.eclipse.jgit.api.CloneCommand;
|
| | | import org.eclipse.jgit.api.Git;
|
| | |
| | | import org.junit.BeforeClass;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.GitBlitServer;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
|
| | | public class GitServletTest {
|
| | |
|
| | | File folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit");
|
| | |
|
| | | static int port = 8180;
|
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | |
|
| | | static int shutdownPort = 8181;
|
| | | private static final AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | // Start a Gitblit instance
|
| | | Executors.newSingleThreadExecutor().execute(new Runnable() {
|
| | | public void run() {
|
| | | GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
| | | "" + shutdownPort, "--repositoriesFolder",
|
| | | "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
| | | "distrib/users.conf");
|
| | | }
|
| | | });
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | started.set(GitBlitSuite.startGitblit());
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | // Stop Gitblit
|
| | | GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | if (started.get()) {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | |
| | | FileUtils.delete(folder, FileUtils.RECURSIVE);
|
| | | }
|
| | | CloneCommand clone = Git.cloneRepository();
|
| | | clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/ticgit.git", port));
|
| | | clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));
|
| | | clone.setDirectory(folder);
|
| | | clone.setBare(false);
|
| | | clone.setCloneAllBranches(true);
|
| | | clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
|
| | | clone.call();
|
| | | assertTrue(true);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBogusLoginClone() throws Exception {
|
| | | // restrict repository access
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
|
| | | model.accessRestriction = AccessRestrictionType.CLONE;
|
| | | GitBlit.self().updateRepositoryModel(model.name, model, false);
|
| | |
|
| | | // delete any existing working folder
|
| | | File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");
|
| | | if (folder.exists()) {
|
| | | FileUtils.delete(folder, FileUtils.RECURSIVE);
|
| | | }
|
| | | boolean cloned = false;
|
| | | try {
|
| | | CloneCommand clone = Git.cloneRepository();
|
| | | clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url));
|
| | | clone.setDirectory(folder);
|
| | | clone.setBare(false);
|
| | | clone.setCloneAllBranches(true);
|
| | | clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));
|
| | | clone.call();
|
| | | cloned = true;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // restore anonymous repository access
|
| | | model.accessRestriction = AccessRestrictionType.NONE;
|
| | | GitBlit.self().updateRepositoryModel(model.name, model, false);
|
| | |
|
| | | assertFalse("Bogus login cloned a repository?!", cloned);
|
| | | }
|
| | |
|
| | | @Test
|
| | |
| | | git.commit().setMessage("test commit").call();
|
| | | git.push().setPushAll().call();
|
| | | git.getRepository().close();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBogusLoginClone() throws Exception {
|
| | | File folder = new File(GitBlitSuite.REPOSITORIES, "working/gitblit");
|
| | | if (folder.exists()) {
|
| | | FileUtils.delete(folder, FileUtils.RECURSIVE);
|
| | | }
|
| | | CloneCommand clone = Git.cloneRepository();
|
| | | clone.setURI(MessageFormat.format("http://localhost:{0,number,#}/git/gitblit.git", port));
|
| | | clone.setDirectory(folder);
|
| | | clone.setBare(false);
|
| | | clone.setCloneAllBranches(true);
|
| | | clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));
|
| | | clone.call();
|
| | | }
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | | import static org.junit.Assert.assertNull;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileOutputStream;
|
| | | import java.text.SimpleDateFormat;
|
| | |
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
| | | import org.eclipse.jgit.lib.Constants;
|
| | |
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.eclipse.jgit.util.FS;
|
| | | import org.eclipse.jgit.util.FileUtils;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.SearchType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.GitNote;
|
| | |
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | public class JGitUtilsTest extends TestCase {
|
| | | public class JGitUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testDisplayName() throws Exception {
|
| | | assertTrue(JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")).equals(
|
| | | "Napoleon Bonaparte"));
|
| | | assertTrue(JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")).equals(
|
| | | "<someone@somewhere.com>"));
|
| | | assertTrue(JGitUtils.getDisplayName(
|
| | | new PersonIdent("Napoleon Bonaparte", "someone@somewhere.com")).equals(
|
| | | "Napoleon Bonaparte <someone@somewhere.com>"));
|
| | | assertEquals("Napoleon Bonaparte",
|
| | | JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")));
|
| | | assertEquals("<someone@somewhere.com>",
|
| | | JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")));
|
| | | assertEquals("Napoleon Bonaparte <someone@somewhere.com>",
|
| | | JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte",
|
| | | "someone@somewhere.com")));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFindRepositories() {
|
| | | List<String> list = JGitUtils.getRepositoryList(null, true, true);
|
| | | assertTrue(list.size() == 0);
|
| | | assertEquals(0, list.size());
|
| | | list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));
|
| | | assertTrue(list.size() == 0);
|
| | | assertEquals(0, list.size());
|
| | | list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, true, true));
|
| | | assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testOpenRepository() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | repository.close();
|
| | | assertTrue("Could not find repository!", repository != null);
|
| | | assertNotNull("Could not find repository!", repository);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFirstCommit() throws Exception {
|
| | | assertTrue(JGitUtils.getFirstChange(null, null).equals(new Date(0)));
|
| | | assertEquals(new Date(0), JGitUtils.getFirstChange(null, null));
|
| | |
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getFirstCommit(repository, null);
|
| | | Date firstChange = JGitUtils.getFirstChange(repository, null);
|
| | | repository.close();
|
| | | assertTrue("Could not get first commit!", commit != null);
|
| | | assertTrue("Incorrect first commit!",
|
| | | commit.getName().equals("f554664a346629dc2b839f7292d06bad2db4aece"));
|
| | | assertNotNull("Could not get first commit!", commit);
|
| | | assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
|
| | | commit.getName());
|
| | | assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testLastCommit() throws Exception {
|
| | | assertTrue(JGitUtils.getLastChange(null, null).equals(new Date(0)));
|
| | | assertEquals(new Date(0), JGitUtils.getLastChange(null, null));
|
| | |
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | assertTrue(JGitUtils.getCommit(repository, null) != null);
|
| | | Date date = JGitUtils.getLastChange(repository, null);
|
| | | repository.close();
|
| | | assertTrue("Could not get last repository change date!", date != null);
|
| | | assertNotNull("Could not get last repository change date!", date);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testCreateRepository() throws Exception {
|
| | | String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
|
| | | for (String repositoryName : repositories) {
|
| | |
| | | repositoryName);
|
| | | File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
|
| | | FS.DETECTED);
|
| | | assertTrue(repository != null);
|
| | | assertNotNull(repository);
|
| | | assertFalse(JGitUtils.hasCommits(repository));
|
| | | assertTrue(JGitUtils.getFirstCommit(repository, null) == null);
|
| | | assertTrue(JGitUtils.getFirstChange(repository, null).getTime() == folder
|
| | | .lastModified());
|
| | | assertTrue(JGitUtils.getLastChange(repository, null).getTime() == folder.lastModified());
|
| | | assertTrue(JGitUtils.getCommit(repository, null) == null);
|
| | | assertNull(JGitUtils.getFirstCommit(repository, null));
|
| | | assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
|
| | | .getTime());
|
| | | assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository, null).getTime());
|
| | | assertNull(JGitUtils.getCommit(repository, null));
|
| | | repository.close();
|
| | | assertTrue(GitBlit.self().deleteRepository(repositoryName));
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRefs() throws Exception {
|
| | | Repository repository = GitBlitSuite.getJGitRepository();
|
| | | Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
|
| | |
| | | List<RefModel> list = entry.getValue();
|
| | | for (RefModel ref : list) {
|
| | | if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
|
| | | assertTrue(ref.toString().equals("refs/tags/spearce-gpg-pub"));
|
| | | assertTrue(ref.getObjectId().getName()
|
| | | .equals("8bbde7aacf771a9afb6992434f1ae413e010c6d8"));
|
| | | assertTrue(ref.getAuthorIdent().getEmailAddress().equals("spearce@spearce.org"));
|
| | | assertEquals("refs/tags/spearce-gpg-pub", ref.toString());
|
| | | assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId()
|
| | | .getName());
|
| | | assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());
|
| | | assertTrue(ref.getShortMessage().startsWith("GPG key"));
|
| | | assertTrue(ref.getFullMessage().startsWith("GPG key"));
|
| | | assertTrue(ref.getReferencedObjectType() == Constants.OBJ_BLOB);
|
| | | assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());
|
| | | } else if (ref.displayName.equals("refs/tags/v0.12.1")) {
|
| | | assertTrue(ref.isAnnotatedTag());
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBranches() throws Exception {
|
| | | Repository repository = GitBlitSuite.getJGitRepository();
|
| | | assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
|
| | |
| | | repository.close();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testTags() throws Exception {
|
| | | Repository repository = GitBlitSuite.getJGitRepository();
|
| | | assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);
|
| | |
| | | if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {
|
| | | assertFalse(model.isAnnotatedTag());
|
| | | assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));
|
| | | assertTrue(model.getFullMessage().equals(
|
| | | "Update changelog and bump version number\n"));
|
| | | assertEquals("Update changelog and bump version number\n", model.getFullMessage());
|
| | | }
|
| | | }
|
| | | repository.close();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testCommitNotes() throws Exception {
|
| | | Repository repository = GitBlitSuite.getJGitRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
|
| | | repository.close();
|
| | | assertTrue(list.size() > 0);
|
| | | assertTrue(list.get(0).notesRef.getReferencedObjectId().getName()
|
| | | .equals("183474d554e6f68478a02d9d7888b67a9338cdff"));
|
| | | assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef
|
| | | .getReferencedObjectId().getName());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testCreateOrphanedBranch() throws Exception {
|
| | | Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");
|
| | | assertTrue(JGitUtils.createOrphanBranch(repository,
|
| | |
| | | FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testStringContent() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | String contentA = JGitUtils.getStringContent(repository, null, "java.java");
|
| | |
| | | assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
|
| | | assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
|
| | | assertTrue(contentA.equals(contentB));
|
| | | assertTrue(contentC == null);
|
| | | assertNull(contentC);
|
| | | assertTrue(contentA.equals(contentD));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFilesInCommit() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue("PathChangeModel equals itself failed!", path.equals(path));
|
| | | assertFalse("PathChangeModel equals string failed!", path.equals(""));
|
| | | }
|
| | | assertTrue(deletions.get(0).changeType.equals(ChangeType.DELETE));
|
| | | assertTrue(additions.get(0).changeType.equals(ChangeType.ADD));
|
| | | assertEquals(ChangeType.DELETE, deletions.get(0).changeType);
|
| | | assertEquals(ChangeType.ADD, additions.get(0).changeType);
|
| | | assertTrue(latestChanges.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFilesInPath() throws Exception {
|
| | | assertTrue(JGitUtils.getFilesInPath(null, null, null).size() == 0);
|
| | | assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);
|
| | | repository.close();
|
| | | assertTrue(files.size() > 10);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testDocuments() throws Exception {
|
| | | Repository repository = GitBlitSuite.getTicgitRepository();
|
| | | List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);
|
| | |
| | | assertTrue(allFiles.size() > markdownDocs.size());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFileModes() throws Exception {
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()).equals("drwxr-xr-x"));
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()).equals(
|
| | | "-rw-r--r--"));
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()).equals(
|
| | | "-rwxr-xr-x"));
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()).equals("symlink"));
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()).equals("gitlink"));
|
| | | assertTrue(JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()).equals("missing"));
|
| | | assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));
|
| | | assertEquals("-rw-r--r--",
|
| | | JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));
|
| | | assertEquals("-rwxr-xr-x",
|
| | | JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
|
| | | assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
|
| | | assertEquals("gitlink", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
|
| | | assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRevlog() throws Exception {
|
| | | assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
|
| | | List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
|
| | |
| | | // grab the two most recent commits to java.java
|
| | | commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
|
| | | assertEquals(2, commits.size());
|
| | | |
| | |
|
| | | // grab the commits since 2008-07-15
|
| | | commits = JGitUtils.getRevLog(repository, null, new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
|
| | | commits = JGitUtils.getRevLog(repository, null,
|
| | | new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
|
| | | assertEquals(12, commits.size());
|
| | | repository.close();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSearchTypes() throws Exception {
|
| | | assertTrue(com.gitblit.Constants.SearchType.forName("commit").equals(com.gitblit.Constants.SearchType.COMMIT));
|
| | | assertTrue(com.gitblit.Constants.SearchType.forName("committer").equals(com.gitblit.Constants.SearchType.COMMITTER));
|
| | | assertTrue(com.gitblit.Constants.SearchType.forName("author").equals(com.gitblit.Constants.SearchType.AUTHOR));
|
| | | assertTrue(com.gitblit.Constants.SearchType.forName("unknown").equals(com.gitblit.Constants.SearchType.COMMIT));
|
| | | assertEquals(SearchType.COMMIT, SearchType.forName("commit"));
|
| | | assertEquals(SearchType.COMMITTER, SearchType.forName("committer"));
|
| | | assertEquals(SearchType.AUTHOR, SearchType.forName("author"));
|
| | | assertEquals(SearchType.COMMIT, SearchType.forName("unknown"));
|
| | |
|
| | | assertTrue(com.gitblit.Constants.SearchType.COMMIT.toString().equals("commit"));
|
| | | assertTrue(com.gitblit.Constants.SearchType.COMMITTER.toString().equals("committer"));
|
| | | assertTrue(com.gitblit.Constants.SearchType.AUTHOR.toString().equals("author"));
|
| | | assertEquals("commit", SearchType.COMMIT.toString());
|
| | | assertEquals("committer", SearchType.COMMITTER.toString());
|
| | | assertEquals("author", SearchType.AUTHOR.toString());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSearchRevlogs() throws Exception {
|
| | | assertTrue(JGitUtils.searchRevlogs(null, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0, 0).size() == 0);
|
| | | List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0,
|
| | | assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());
|
| | | List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0,
|
| | | 3);
|
| | | assertTrue(results.size() == 0);
|
| | | assertEquals(0, results.size());
|
| | |
|
| | | // test commit message search
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | results = JGitUtils.searchRevlogs(repository, null, "java", com.gitblit.Constants.SearchType.COMMIT, 0, 3);
|
| | | assertTrue(results.size() == 3);
|
| | | results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);
|
| | | assertEquals(3, results.size());
|
| | |
|
| | | // test author search
|
| | | results = JGitUtils.searchRevlogs(repository, null, "timothy", com.gitblit.Constants.SearchType.AUTHOR, 0, -1);
|
| | | assertTrue(results.size() == 1);
|
| | | results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);
|
| | | assertEquals(1, results.size());
|
| | |
|
| | | // test committer search
|
| | | results = JGitUtils.searchRevlogs(repository, null, "mike", com.gitblit.Constants.SearchType.COMMITTER, 0, 10);
|
| | | assertTrue(results.size() == 10);
|
| | | results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);
|
| | | assertEquals(10, results.size());
|
| | |
|
| | | // test paging and offset
|
| | | RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", com.gitblit.Constants.SearchType.COMMITTER,
|
| | | RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER,
|
| | | 9, 1).get(0);
|
| | | assertTrue(results.get(9).equals(commit));
|
| | | assertEquals(results.get(9), commit);
|
| | |
|
| | | repository.close();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testZip() throws Exception {
|
| | | assertFalse(JGitUtils.zip(null, null, null, null));
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.JsonUtils;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | |
|
| | | public class JsonUtilsTest extends TestCase {
|
| | | public class JsonUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testSerialization() {
|
| | | Map<String, String> map = new HashMap<String, String>();
|
| | | map.put("a", "alligator");
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import javax.mail.Message;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.FileSettings;
|
| | | import com.gitblit.MailExecutor;
|
| | |
|
| | | public class MailTest extends TestCase {
|
| | | public class MailTest {
|
| | |
|
| | | @Test
|
| | | public void testSendMail() throws Exception {
|
| | | FileSettings settings = new FileSettings("mailtest.properties");
|
| | | MailExecutor mail = new MailExecutor(settings);
|
| | |
| | | message.setSubject("Test");
|
| | | message.setText("this is a test");
|
| | | mail.queue(message);
|
| | | mail.run(); |
| | | mail.run();
|
| | |
|
| | | assertTrue("mail queue is not empty!", mail.hasEmptyQueue());
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.text.ParseException;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.MarkdownUtils;
|
| | |
|
| | | public class MarkdownUtilsTest extends TestCase {
|
| | | public class MarkdownUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testMarkdown() throws Exception {
|
| | | assertEquals("<h1> H1</h1>", MarkdownUtils.transformMarkdown("# H1"));
|
| | | assertEquals("<h2> H2</h2>", MarkdownUtils.transformMarkdown("## H2"));
|
| | |
| | | MarkdownUtils.transformMarkdown("**THIS ** is a test"));
|
| | | assertEquals("<p>** THIS** is a test</p>",
|
| | | MarkdownUtils.transformMarkdown("** THIS** is a test"));
|
| | | |
| | | assertEquals("<table><tr><td>test</td></tr></table>", MarkdownUtils.transformMarkdown("<table><tr><td>test</td></tr></table>"));
|
| | |
|
| | | assertEquals("<table><tr><td>test</td></tr></table>",
|
| | | MarkdownUtils.transformMarkdown("<table><tr><td>test</td></tr></table>"));
|
| | | assertEquals("<table><tr><td><test></td></tr></table>",
|
| | | MarkdownUtils.transformMarkdown("<table><tr><td><test></td></tr></table>"));
|
| | |
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.models.Metric;
|
| | | import com.gitblit.utils.MetricUtils;
|
| | |
|
| | | public class MetricUtilsTest extends TestCase {
|
| | | public class MetricUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testMetrics() throws Exception {
|
| | | testMetrics(GitBlitSuite.getHelloworldRepository());
|
| | | testMetrics(GitBlitSuite.getBluezGnomeRepository());
|
| | |
| | | assertTrue("No date metrics found!", metrics.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testAuthorMetrics() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | List<Metric> byEmail = MetricUtils.getAuthorMetrics(repository, null, true);
|
| | | List<Metric> byName = MetricUtils.getAuthorMetrics(repository, null, false);
|
| | | repository.close();
|
| | | assertTrue("No author metrics found!", byEmail.size() == 9);
|
| | | assertTrue("No author metrics found!", byName.size() == 8);
|
| | | assertEquals("No author metrics found!", 9, byEmail.size());
|
| | | assertEquals("No author metrics found!", 8, byName.size());
|
| | | }
|
| | | } |
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.ObjectCache;
|
| | |
|
| | | public class ObjectCacheTest extends TestCase {
|
| | | public class ObjectCacheTest {
|
| | |
|
| | | @Test
|
| | | public void testCache() throws Exception {
|
| | | ObjectCache<String> cache = new ObjectCache<String>();
|
| | | cache.updateObject("test", "alpha");
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | | import static org.junit.Assert.assertNull;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Collection;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class RpcTests extends TestCase {
|
| | | |
| | | public class RpcTests {
|
| | |
|
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | | |
| | |
|
| | | private static final AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | GitBlitSuite.startGitblit();
|
| | | started.set(GitBlitSuite.startGitblit());
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | GitBlitSuite.stopGitblit();
|
| | | if (started.get()) {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testListRepositories() throws IOException {
|
| | | Map<String, RepositoryModel> map = RpcUtils.getRepositories(url, null, null);
|
| | | assertTrue("Repository list is null!", map != null);
|
| | | assertNotNull("Repository list is null!", map);
|
| | | assertTrue("Repository list is empty!", map.size() > 0);
|
| | | }
|
| | |
|
| | |
| | | list = RpcUtils.getUsers(url, null, null);
|
| | | } catch (UnauthorizedException e) {
|
| | | }
|
| | | assertTrue("Server allows anyone to admin!", list == null);
|
| | | assertNull("Server allows anyone to admin!", list);
|
| | |
|
| | | list = RpcUtils.getUsers(url, "admin", "admin".toCharArray());
|
| | | assertTrue("User list is empty!", list.size() > 0);
|
| | |
| | | RpcUtils.createUser(user, url, account, password.toCharArray()));
|
| | |
|
| | | UserModel retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to find " + user.username, retrievedUser != null);
|
| | | assertNotNull("Failed to find " + user.username, retrievedUser);
|
| | | assertTrue("Retrieved user can not administer Gitblit", retrievedUser.canAdmin);
|
| | |
|
| | | // rename and toggle admin permission
|
| | |
| | | RpcUtils.updateUser(originalName, user, url, account, password.toCharArray()));
|
| | |
|
| | | retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to find " + user.username, retrievedUser != null);
|
| | | assertNotNull("Failed to find " + user.username, retrievedUser);
|
| | | assertTrue("Retrieved user did not update", !retrievedUser.canAdmin);
|
| | |
|
| | | // delete
|
| | |
| | | RpcUtils.deleteUser(retrievedUser, url, account, password.toCharArray()));
|
| | |
|
| | | retrievedUser = findUser(user.username);
|
| | | assertTrue("Failed to delete " + user.username, retrievedUser == null);
|
| | | assertNull("Failed to delete " + user.username, retrievedUser);
|
| | | }
|
| | |
|
| | | private UserModel findUser(String name) throws IOException {
|
| | |
| | | RpcUtils.createRepository(model, url, account, password.toCharArray()));
|
| | |
|
| | | RepositoryModel retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to find " + model.name, retrievedRepository != null);
|
| | | assertTrue("Access retriction type is wrong",
|
| | | AccessRestrictionType.VIEW.equals(retrievedRepository.accessRestriction));
|
| | | assertNotNull("Failed to find " + model.name, retrievedRepository);
|
| | | assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
|
| | |
|
| | | // rename and change access restriciton
|
| | | String originalName = model.name;
|
| | |
| | | url, account, password.toCharArray()));
|
| | |
|
| | | retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to find " + model.name, retrievedRepository != null);
|
| | | assertNotNull("Failed to find " + model.name, retrievedRepository);
|
| | | assertTrue("Access retriction type is wrong",
|
| | | AccessRestrictionType.PUSH.equals(retrievedRepository.accessRestriction));
|
| | |
|
| | | // memberships
|
| | | String testMember = "justadded";
|
| | | UserModel testMember = new UserModel("justadded");
|
| | | assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));
|
| | |
|
| | | List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,
|
| | | password.toCharArray());
|
| | | assertTrue("Membership roster is not empty!", members.size() == 0);
|
| | | members.add(testMember);
|
| | | assertEquals("Membership roster is not empty!", 0, members.size());
|
| | | members.add(testMember.username);
|
| | | assertTrue(
|
| | | "Failed to set memberships!",
|
| | | RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,
|
| | |
| | | password.toCharArray());
|
| | | boolean foundMember = false;
|
| | | for (String member : members) {
|
| | | if (member.equalsIgnoreCase(testMember)) {
|
| | | if (member.equalsIgnoreCase(testMember.username)) {
|
| | | foundMember = true;
|
| | | break;
|
| | | }
|
| | |
| | | url, account, password.toCharArray()));
|
| | |
|
| | | retrievedRepository = findRepository(model.name);
|
| | | assertTrue("Failed to delete " + model.name, retrievedRepository == null);
|
| | | assertNull("Failed to delete " + model.name, retrievedRepository);
|
| | |
|
| | | for (UserModel u : RpcUtils.getUsers(url, account, password.toCharArray())) {
|
| | | if (u.username.equals(testMember)) {
|
| | | RpcUtils.deleteUser(u, url, account, password.toCharArray());
|
| | | if (u.username.equals(testMember.username)) {
|
| | | assertTrue(RpcUtils.deleteUser(u, url, account, password.toCharArray()));
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | @Test
|
| | | public void testSettings() throws Exception {
|
| | | ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());
|
| | | assertTrue("No settings were retrieved!", settings != null);
|
| | | assertNotNull("No settings were retrieved!", settings);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testServerStatus() throws Exception {
|
| | | ServerStatus status = RpcUtils.getStatus(url, account, password.toCharArray());
|
| | | assertTrue("No status was retrieved!", status != null);
|
| | | assertNotNull("No status was retrieved!", status);
|
| | | }
|
| | |
|
| | | @Test
|
| | |
| | | public void testBranches() throws Exception {
|
| | | Map<String, Collection<String>> branches = RpcUtils.getBranches(url, account,
|
| | | password.toCharArray());
|
| | | assertTrue(branches != null);
|
| | | assertNotNull(branches);
|
| | | assertTrue(branches.size() > 0);
|
| | | }
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.Arrays;
|
| | | import java.util.List;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | public class StringUtilsTest extends TestCase {
|
| | | public class StringUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testIsEmpty() throws Exception {
|
| | | assertTrue(StringUtils.isEmpty(null));
|
| | | assertTrue(StringUtils.isEmpty(""));
|
| | |
| | | assertFalse(StringUtils.isEmpty("A"));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBreakLinesForHtml() throws Exception {
|
| | | String input = "this\nis\r\na\rtest\r\n\r\nof\n\nline\r\rbreaking";
|
| | | String output = "this<br/>is<br/>a<br/>test<br/><br/>of<br/><br/>line<br/><br/>breaking";
|
| | | assertTrue(StringUtils.breakLinesForHtml(input).equals(output));
|
| | | assertEquals(output, StringUtils.breakLinesForHtml(input));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testEncodeUrl() throws Exception {
|
| | | String input = "test /";
|
| | | String output = "test%20%2F";
|
| | | assertTrue(StringUtils.encodeURL(input).equals(output));
|
| | | assertEquals(output, StringUtils.encodeURL(input));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testEscapeForHtml() throws Exception {
|
| | | String input = "& < > \" \t";
|
| | | String outputNoChange = "& < > " \t";
|
| | | String outputChange = "& < > " ";
|
| | | assertTrue(StringUtils.escapeForHtml(input, false).equals(outputNoChange));
|
| | | assertTrue(StringUtils.escapeForHtml(input, true).equals(outputChange));
|
| | | assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));
|
| | | assertEquals(outputChange, StringUtils.escapeForHtml(input, true));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testDecodeForHtml() throws Exception {
|
| | | String input = "& < > "";
|
| | | String output = "& < > \"";
|
| | | assertTrue(StringUtils.decodeFromHtml(input).equals(output));
|
| | | assertEquals(output, StringUtils.decodeFromHtml(input));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFlattenStrings() throws Exception {
|
| | | String[] strings = { "A", "B", "C", "D" };
|
| | | assertTrue(StringUtils.flattenStrings(Arrays.asList(strings)).equals("A B C D"));
|
| | | assertEquals("A B C D", StringUtils.flattenStrings(Arrays.asList(strings)));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testTrim() throws Exception {
|
| | | String input = "123456789 123456789 123456789 123456789 123456789 123456789 123456789 ";
|
| | | String output = "123456789 123456789 123456789 123456789 123456789 1234567...";
|
| | | assertTrue(StringUtils.trimShortLog(input).equals(output));
|
| | | assertTrue(StringUtils.trimString(input, input.length()).equals(input));
|
| | | assertEquals(output, StringUtils.trimShortLog(input));
|
| | | assertEquals(input, StringUtils.trimString(input, input.length()));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testPadding() throws Exception {
|
| | | String input = "test";
|
| | | assertTrue(StringUtils.leftPad(input, 6 + input.length(), ' ').equals(" test"));
|
| | | assertTrue(StringUtils.rightPad(input, 6 + input.length(), ' ').equals("test "));
|
| | | assertEquals(" test", StringUtils.leftPad(input, 6 + input.length(), ' '));
|
| | | assertEquals("test ", StringUtils.rightPad(input, 6 + input.length(), ' '));
|
| | |
|
| | | assertTrue(StringUtils.leftPad(input, input.length(), ' ').equals(input));
|
| | | assertTrue(StringUtils.rightPad(input, input.length(), ' ').equals(input));
|
| | | assertEquals(input, StringUtils.leftPad(input, input.length(), ' '));
|
| | | assertEquals(input, StringUtils.rightPad(input, input.length(), ' '));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSHA1() throws Exception {
|
| | | assertTrue(StringUtils.getSHA1("blob 16\000what is up, doc?").equals(
|
| | | "bd9dbf5aae1a3862dd1526723246b20206e5fc37"));
|
| | | assertEquals("bd9dbf5aae1a3862dd1526723246b20206e5fc37",
|
| | | StringUtils.getSHA1("blob 16\000what is up, doc?"));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testMD5() throws Exception {
|
| | | assertTrue(StringUtils.getMD5("blob 16\000what is up, doc?").equals(
|
| | | "77fb8d95331f0d557472f6776d3aedf6"));
|
| | | assertEquals("77fb8d95331f0d557472f6776d3aedf6",
|
| | | StringUtils.getMD5("blob 16\000what is up, doc?"));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRootPath() throws Exception {
|
| | | String input = "/nested/path/to/repository";
|
| | | String output = "/nested/path/to";
|
| | | assertTrue(StringUtils.getRootPath(input).equals(output));
|
| | | assertTrue(StringUtils.getRootPath("repository").equals(""));
|
| | | assertEquals(output, StringUtils.getRootPath(input));
|
| | | assertEquals("", StringUtils.getRootPath("repository"));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testStringsFromValue() throws Exception {
|
| | | List<String> strings = StringUtils.getStringsFromValue("A B C D");
|
| | | assertTrue(strings.size() == 4);
|
| | | assertTrue(strings.get(0).equals("A"));
|
| | | assertTrue(strings.get(1).equals("B"));
|
| | | assertTrue(strings.get(2).equals("C"));
|
| | | assertTrue(strings.get(3).equals("D"));
|
| | | assertEquals(4, strings.size());
|
| | | assertEquals("A", strings.get(0));
|
| | | assertEquals("B", strings.get(1));
|
| | | assertEquals("C", strings.get(2));
|
| | | assertEquals("D", strings.get(3));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testStringsFromValue2() throws Exception {
|
| | | List<String> strings = StringUtils.getStringsFromValue("common/* libraries/*");
|
| | | assertTrue(strings.size() == 2);
|
| | | assertTrue(strings.get(0).equals("common/*"));
|
| | | assertTrue(strings.get(1).equals("libraries/*"));
|
| | | assertEquals(2, strings.size());
|
| | | assertEquals("common/*", strings.get(0));
|
| | | assertEquals("libraries/*", strings.get(1));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFuzzyMatching() throws Exception {
|
| | | assertTrue(StringUtils.fuzzyMatch("12345", "12345"));
|
| | | assertTrue(StringUtils.fuzzyMatch("AbCdEf", "abcdef"));
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.SearchType;
|
| | | import com.gitblit.models.FeedEntryModel;
|
| | | import com.gitblit.utils.SyndicationUtils;
|
| | |
|
| | | public class SyndicationUtilsTest extends TestCase {
|
| | | public class SyndicationUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testSyndication() throws Exception {
|
| | | List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
|
| | | for (int i = 0; i < 10; i++) {
|
| | |
| | | assertTrue(feed.indexOf("<description>Description</description>") > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFeedRead() throws Exception {
|
| | | Set<String> links = new HashSet<String>();
|
| | | for (int i = 0; i < 2; i++) {
|
| | | List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url,
|
| | | "ticgit.git", "deving", 5, i, GitBlitSuite.account,
|
| | | GitBlitSuite.password.toCharArray());
|
| | | List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",
|
| | | "deving", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(5, feed.size());
|
| | |
| | | assertEquals("Feed pagination failed", 10, links.size());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSearchFeedRead() throws Exception {
|
| | | List<FeedEntryModel> feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url,
|
| | | "ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account,
|
| | | GitBlitSuite.password.toCharArray());
|
| | | List<FeedEntryModel> feed = SyndicationUtils
|
| | | .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,
|
| | | GitBlitSuite.account, GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(5, feed.size());
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertNotNull;
|
| | | import static org.junit.Assert.assertNull;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.TicketModel;
|
| | | import com.gitblit.models.TicketModel.Comment;
|
| | | import com.gitblit.utils.TicgitUtils;
|
| | |
|
| | | public class TicgitUtilsTest extends TestCase {
|
| | | public class TicgitUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testTicgitBranch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getTicgitRepository();
|
| | | RefModel branch = TicgitUtils.getTicketsBranch(repository);
|
| | | repository.close();
|
| | | assertTrue("Ticgit branch does not exist!", branch != null);
|
| | | assertNotNull("Ticgit branch does not exist!", branch);
|
| | |
|
| | | repository = GitBlitSuite.getHelloworldRepository();
|
| | | branch = TicgitUtils.getTicketsBranch(repository);
|
| | | repository.close();
|
| | | assertTrue("Ticgit branch exists!", branch == null);
|
| | | assertNull("Ticgit branch exists!", branch);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testRetrieveTickets() throws Exception {
|
| | | Repository repository = GitBlitSuite.getTicgitRepository();
|
| | | List<TicketModel> ticketsA = TicgitUtils.getTickets(repository);
|
| | |
| | | Comment commentB = ticketB.comments.get(j);
|
| | | assertTrue("Comments are not equal!", commentA.equals(commentB));
|
| | | assertFalse(commentA.equals(""));
|
| | | assertTrue(commentA.hashCode() == commentA.text.hashCode());
|
| | | assertEquals(commentA.hashCode(), commentA.text.hashCode());
|
| | | }
|
| | | }
|
| | |
|
| | | repository = GitBlitSuite.getHelloworldRepository();
|
| | | List<TicketModel> ticketsC = TicgitUtils.getTickets(repository);
|
| | | repository.close();
|
| | | assertTrue(ticketsC == null);
|
| | | assertNull(ticketsC);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testReadTicket() throws Exception {
|
| | | Repository repository = GitBlitSuite.getTicgitRepository();
|
| | | List<TicketModel> tickets = TicgitUtils.getTickets(repository);
|
| | | TicketModel ticket = TicgitUtils
|
| | | .getTicket(repository, tickets.get(tickets.size() - 1).name);
|
| | | repository.close();
|
| | | assertTrue(ticket != null);
|
| | | assertTrue(ticket.name
|
| | | .equals("1254123752_comments-on-ticgits-longer-than-5-lines-can-t-be-viewed-entirely_266"));
|
| | | assertNotNull(ticket);
|
| | | assertEquals(
|
| | | "1254123752_comments-on-ticgits-longer-than-5-lines-can-t-be-viewed-entirely_266",
|
| | | ticket.name);
|
| | | }
|
| | | } |
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.utils.TimeUtils;
|
| | |
|
| | | public class TimeUtilsTest extends TestCase {
|
| | | public class TimeUtilsTest {
|
| | |
|
| | | private Date offset(long subtract) {
|
| | | return new Date(System.currentTimeMillis() - subtract);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBasicTimeFunctions() throws Exception {
|
| | | assertEquals(2, TimeUtils.minutesAgo(offset(2 * TimeUtils.MIN), false));
|
| | | assertEquals(3, TimeUtils.minutesAgo(offset((2 * TimeUtils.MIN) + (35 * 1000L)), true));
|
| | |
| | | assertEquals(4, TimeUtils.daysAgo(offset(4 * TimeUtils.ONEDAY)));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testToday() throws Exception {
|
| | | assertTrue(TimeUtils.isToday(new Date()));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testYesterday() throws Exception {
|
| | | assertTrue(TimeUtils.isYesterday(offset(TimeUtils.ONEDAY)));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testDurations() throws Exception {
|
| | | assertEquals("1 day", TimeUtils.duration(1));
|
| | | assertEquals("5 days", TimeUtils.duration(5));
|
| | |
| | | assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 60));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testTimeAgo() throws Exception {
|
| | | // standard time ago tests
|
| | | assertEquals("1 min ago", TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)));
|
| | |
| | | assertEquals("age2", TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFrequency() {
|
| | | assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins"));
|
| | | assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins"));
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertFalse;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.ConfigUserService;
|
| | | import com.gitblit.FileUserService;
|
| | | import com.gitblit.IUserService;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
|
| | | public class UserServiceTest extends TestCase {
|
| | | public class UserServiceTest {
|
| | |
|
| | | @Test
|
| | | public void testFileUserService() throws IOException {
|
| | | File file = new File("us-test.properties");
|
| | | file.delete();
|
| | | test(new FileUserService(file));
|
| | | IUserService service = new FileUserService(file);
|
| | | testUsers(service);
|
| | | file.delete();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testConfigUserService() throws IOException {
|
| | | File file = new File("us-test.conf");
|
| | | file.delete();
|
| | | test(new ConfigUserService(file));
|
| | | IUserService service = new ConfigUserService(file);
|
| | | testUsers(service);
|
| | | file.delete();
|
| | | }
|
| | |
|
| | | protected void test(IUserService service) {
|
| | | protected void testUsers(IUserService service) {
|
| | |
|
| | | UserModel admin = service.getUserModel("admin");
|
| | | assertTrue(admin == null);
|