123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675 |
- package com.gitblit.servlet;
-
- import com.gitblit.Constants;
- import com.gitblit.IStoredSettings;
- import com.gitblit.Keys;
- import com.gitblit.tests.mock.MockGitblitContext;
- import com.gitblit.tests.mock.MockRuntimeManager;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
-
-
- import static org.junit.Assert.*;
-
- public class RawServletTest
- {
- private final static String FSC = "!";
-
- private static IStoredSettings settings;
-
-
- @BeforeClass
- public static void init()
- {
- MockGitblitContext gitblitContext = new MockGitblitContext();
- MockRuntimeManager mockRuntimeManager = new MockRuntimeManager();
- gitblitContext.addManager(mockRuntimeManager);
- settings = mockRuntimeManager.getSettings();
- }
-
- @Before
- public void setUp()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "/");
- }
-
-
-
- @Test
- public void asLink_HttpUrlRepo()
- {
- String baseUrl = "http://localhost";
- String repository = "test.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepo()
- {
- String baseUrl = "http://localhost/";
- String repository = "test.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoLeadingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "/test.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoLeadingSlash()
- {
- String baseUrl = "http://localhost/";
- String repository = "/test.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranch()
- {
- String baseUrl = "http://localhost";
- String repository = "test.git";
- String branch = "b52";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoBranch()
- {
- String baseUrl = "http://localhost/";
- String repository = "test.git";
- String branch = "branch";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" + branch + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoLeadingSlashBranch()
- {
- String baseUrl = "http://localhost";
- String repository = "/test.git";
- String branch = "featureOne";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranch()
- {
- String baseUrl = "http://localhost/";
- String repository = "/test.git";
- String branch = "b";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
- }
-
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "test.git";
- String branch = "feature/whatever";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch.replaceAll("/", FSC) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoBranchWithSlash()
- {
- String baseUrl = "http://localhost/";
- String repository = "test.git";
- String branch = "branch/for/issue/16";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoLeadingSlashBranchWithSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "/test.git";
- String branch = "releases/1.2.3";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlash()
- {
- String baseUrl = "http://localhost/";
- String repository = "/test.git";
- String branch = "b/52";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/", link);
- }
-
-
- @Test
- public void asLink_HttpUrlRepoBranchPathFile()
- {
- String baseUrl = "http://localhost";
- String repository = "test.git";
- String branch = "b52";
- String path = "file.txt";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoBranchPathFolderFile()
- {
- String baseUrl = "http://localhost/";
- String repository = "test.git";
- String branch = "branch";
- String path = "path/to/file.png";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path.replaceAll("/", FSC), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoLeadingSlashBranchPathFolderLeadingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "/test.git";
- String branch = "featureOne";
- String path = "/folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + path, link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchSubFolder()
- {
- String baseUrl = "http://localhost/";
- String repository = "/test.git";
- String branch = "b";
- String path = "sub/folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch + "/" + path.replaceAll("/", FSC), link);
- }
-
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlashPathFolder()
- {
- String baseUrl = "http://localhost";
- String repository = "test.git";
- String branch = "feature/whatever";
- String path = "folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoBranchWithSlashPathFolderFile()
- {
- String baseUrl = "http://localhost/";
- String repository = "test.git";
- String branch = "branch/for/issue/16";
- String path = "a/file.gif";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoLeadingSlashBranchWithSlashPathFile()
- {
- String baseUrl = "http://localhost";
- String repository = "/test.git";
- String branch = "releases/1.2.3";
- String path = "hurray.png";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlashPathFolderFile()
- {
- String baseUrl = "http://localhost/";
- String repository = "/test.git";
- String branch = "b/52";
- String path = "go/to/f.k";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInFolder()
- {
- String baseUrl = "http://localhost";
- String repository = "project/repo.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInSubFolder()
- {
- String baseUrl = "http://localhost";
- String repository = "some/project/repo.git";
- String branch = null;
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInSubFolderBranch()
- {
- String baseUrl = "http://localhost";
- String repository = "some/project/repo.git";
- String branch = "laluna";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInSubFolderBranchWithSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "some/project/repo.git";
- String branch = "la/le/lu";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", FSC) + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInSubFolderBranchPathFile()
- {
- String baseUrl = "http://localhost";
- String repository = "some/project/repo.git";
- String branch = "laluna";
- String path = "elrtkx.fg";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoInSubFolderLeadingSlashBranchWithSlashPathFolderFile()
- {
- String baseUrl = "http://localhost";
- String repository = "/some/project/repo.git";
- String branch = "la/le/lu";
- String path = "doremi/fa/SOLA/di.mp3";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
- + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoPathFolderFile()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = null;
- String path = "doko/di.mp3";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoTrailingSlashPathFileLeadingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git/";
- String branch = null;
- String path = "/di.mp3";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchPathFileLeadingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "bee";
- String path = "/bop.mp3";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + path, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchPathFolderLeadingSlashTrailingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "bee";
- String path = "/bam/";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/bam" + FSC, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchPathSubFolderLeadingSlashTrailingSlash()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "bee";
- String path = "/bapedi/boo/";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" + "bapedi" + FSC + "boo" + FSC, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoCommitId()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" , link);
- }
-
- @Test
- public void asLink_HttpUrlRepoCommitIdPathFile()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
- String path = "file";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoCommitIdPathFolderFileFile()
- {
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
- String path = "file/in/folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/" + path.replaceAll("/", FSC), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlash_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", "|") + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature";
- String path = "file/in/folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", ";") + "/" + path.replaceAll("/", ";"), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlash_explicitFscSameAsDefault()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", "!") + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_explicitFscSameAsDefault()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature";
- String path = "file/in/folder";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", "!") + "/" + path.replaceAll("/", "!"), link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithDefaultFsc_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "important" + FSC + "feature";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithSlashPathFileWithDefaultFsc_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature";
- String path = "large" + FSC + "file";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", "|") + "/" + path, link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlash_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "hotf" + FSC + "x/issue/1234";
- String path = null;
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", ":") + "/", link);
- }
-
- @Test
- public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlashPathFolderFileWithDefaultFsc_differentFsc()
- {
- settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
- String baseUrl = "http://localhost";
- String repository = "repo.git";
- String branch = "some/feature" + FSC + "in/here";
- String path = "large" + FSC + "stuff/folder/file" + FSC + "16";
-
- String link = RawServlet.asLink(baseUrl, repository, branch, path);
-
- assertNotNull(link);
- assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
- + branch.replaceAll("/", "|") + "/" + path.replaceAll("/", "|"), link);
- }
-
-
- @Test
- public void getBranch()
- {
- }
-
- @Test
- public void getPath()
- {
- }
- }
|