diff options
author | Florian Zschocke <f.zschocke+git@gmail.com> | 2020-11-08 17:19:35 +0100 |
---|---|---|
committer | Florian Zschocke <f.zschocke+git@gmail.com> | 2020-11-09 23:19:53 +0100 |
commit | 26db31876aaf59651bb8b8a0b65bb4865f090788 (patch) | |
tree | f988b04b13485a5691a492da9d5c4d0337a2bf41 /src/test/java | |
parent | 23943971846437c8bc24504d3bd4b681edea5433 (diff) | |
download | gitblit-26db31876aaf59651bb8b8a0b65bb4865f090788.tar.gz gitblit-26db31876aaf59651bb8b8a0b65bb4865f090788.zip |
raw: Refactor RawServlet:getBranch and :getPath parameters
Refactor the `getBranch` and `getPath` methods to take a String as
second parameter, which is the already sanitised path info. Don't get
the path info from a passed in request anymore.
The methods are only ever called from within `processRequest`, which
already does some checks on the path info, like removing a leading
slash character. So no need to do that every time again the methods
and passing a request for that.
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/gitblit/servlet/RawServletTest.java | 729 |
1 files changed, 685 insertions, 44 deletions
diff --git a/src/test/java/com/gitblit/servlet/RawServletTest.java b/src/test/java/com/gitblit/servlet/RawServletTest.java index 1deacf7e..dac9896e 100644 --- a/src/test/java/com/gitblit/servlet/RawServletTest.java +++ b/src/test/java/com/gitblit/servlet/RawServletTest.java @@ -8,18 +8,16 @@ import com.gitblit.tests.mock.MockGitblitContext; import com.gitblit.tests.mock.MockRuntimeManager; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; -import javax.servlet.http.HttpServletRequest; - import static org.junit.Assert.*; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class RawServletTest { - private final static String FSC = "!"; + private static final String FSC = "!"; private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager(); private static IStoredSettings settings; @@ -513,7 +511,7 @@ public class RawServletTest assertNotNull(link); assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" - + branch + "/" , link); + + branch + "/", link); } @Test @@ -676,58 +674,366 @@ public class RawServletTest @Test - public void getBranch() + public void getBranch_Repo() { + String branch = rawServlet.getBranch("test.git", "test.git/"); + + assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getPath() + public void getBranch_PiNull() { + String branch = rawServlet.getBranch("test.git", null); + + assertEquals("Branch was supposed to be empty as path info is null.", "", branch); } + @Test - public void getBranch_Repo() + public void getBranch_PiEmpty() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git/"); + String branch = rawServlet.getBranch("test.git", ""); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("Branch was supposed to be empty as no path info exists.", "", branch); + } + + @Test + public void getBranch_LeadinRepo() + { + String branch = rawServlet.getBranch("test.git", "some/test.git/"); assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getBranch_RepoNoTrailingSlash() + public void getBranch_ProjectRepo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git"); - - String branch = rawServlet.getBranch("test.git", request); + String branch = rawServlet.getBranch("smack/dab.git", "smack/dab.git/"); assertEquals("Branch was supposed to be empty as no branch was given.", "", branch); } @Test - public void getBranch_PiNull() + public void getBranch_RepoBranch() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(null); + String branch = rawServlet.getBranch("test.git", "test.git/bee"); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("bee", branch); + } - assertEquals("Branch was supposed to be empty as path info is null.", "", branch); + @Test + public void getBranch_LeadinRepoBranch() + { + String branch = rawServlet.getBranch("repo.git", "project/repo.git/bae"); + + assertEquals("bae", branch); + } + + @Test + public void getBranch_ProjectRepoBranch() + { + String branch = rawServlet.getBranch("test/r.git", "test/r.git/b"); + + assertEquals("b", branch); } + @Test + public void getBranch_LeadinProjectRepoBranch() + { + String branch = rawServlet.getBranch("test/r.git", "a/b/test/r.git/b"); + + assertEquals("b", branch); + } @Test - public void getBranch_PiEmpty() + public void getBranch_RepoBranchTrailingSlash() + { + String branch = rawServlet.getBranch("/test.git", "test.git/fixthis/"); + + assertEquals("fixthis", branch); + } + + @Test + public void getBranch_RepoBranchFile() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(""); + String branch = rawServlet.getBranch("/bob.git", "bob.git/branch/file.txt"); - String branch = rawServlet.getBranch("test.git", request); + assertEquals("branch", branch); + } - assertEquals("Branch was supposed to be empty as no path info exists.", "", branch); + @Test + public void getBranch_RepoBranchFolderFile() + { + String branch = rawServlet.getBranch("/bill.git", "bill.git/flex/fold!laundr.y"); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_RepoBranchFoldersTrailingSlash() + { + String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold!gold/"); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_RepoBranchFoldersTrailingFsc() + { + String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold"+ FSC + "gold" + FSC); + + assertEquals("flex", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchFoldersTrailingSlash() + { + String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/"); + + assertEquals("klingeling", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchFoldersTrailingFsc() + { + String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC); + + assertEquals("klingeling", branch); + } + + @Test + public void getBranch_RepoCommitid() + { + String branch = rawServlet.getBranch("git.git", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectRepoCommitidFolderTrailingSlash() + { + String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectRepoCommitidFolderTrailingFsc() + { + String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_ProjectSubRepoCommitidFolderFile() + { + String branch = rawServlet.getBranch("git/git.git", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md"); + + assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithTwoFsc() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_ProjectRepoBranchWithTwoFsc() + { + String branch = rawServlet.getBranch("Java/git/git.git", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_RepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_ProjectRepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("in Go/git.git", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_LeadinProjectRepoBranchWithTwoFscTrailingSlash() + { + String branch = rawServlet.getBranch("Go/git.git", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("feature/rebase/onto", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolder() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolderFile() + { + String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto" + FSC + "head"); + + assertEquals("feature/rebase", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "|"); + + String branch = rawServlet.getBranch("git.git", "git.git/some|feature"); + + assertEquals("some/feature", branch); + } + + @Test + public void getBranch_RepoBranchWithFsc_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature"); + + assertEquals("some/feature", branch); + } + + @Test + public void getBranch_RepoBranchWithFscFolders_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String branch = rawServlet.getBranch("git.git", "git.git/hotfix:1.2.3/src:main:java/"); + + assertEquals("hotfix/1.2.3", branch); + } + + @Test + public void getBranch_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String branch = rawServlet.getBranch("git.git", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot"); + + assertEquals("some/feature", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature"); + + assertEquals("some" + FSC + "feature", branch); + } + + @Test + public void getBranch_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String branch = rawServlet.getBranch("git.git", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt"); + + assertEquals("some/feature", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to:start"); + + assertEquals("go" + FSC + "to/start", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+ prison/dont" + FSC + "collect/"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("go" + FSC + "to/prison", branch); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getBranch_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String branch = rawServlet.getBranch("games/Monopoly/git.git", "blah/games/Monopoly/git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("go" + FSC + "to/prison", branch); } @@ -740,46 +1046,381 @@ public class RawServletTest @Test public void getPath_Repo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git/"); - - String path = rawServlet.getPath("test.git", "", request); + String path = rawServlet.getPath("test.git", "", "test.git/"); assertEquals("Path was supposed to be empty as no path was given.", "", path); } @Test - public void getPath_RepoNoTrailingSlash() + public void getPath_PiNull() + { + String path = rawServlet.getPath("test.git", "", null); + + assertEquals("Path was supposed to be empty as path info is null.", "", path); + } + + + @Test + public void getPath_PiEmpty() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn("/test.git"); + String path = rawServlet.getPath("test.git", "", ""); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Path was supposed to be empty as no path info exists.", "", path); + } + + @Test + public void getPath_LeadinRepo() + { + String path = rawServlet.getPath("test.git", "", "some/test.git/"); assertEquals("Path was supposed to be empty as no path was given.", "", path); } @Test - public void getPath_PiNull() + public void getPath_ProjectRepo() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(null); + String path = rawServlet.getPath("smack/dab.git", "", "smack/dab.git/"); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Path was supposed to be empty as no path was given.", "", path); + } - assertEquals("Path was supposed to be empty as path info is null.", "", path); + @Test + public void getPath_RepoBranch() + { + String path = rawServlet.getPath("test.git", "bee", "test.git/bee"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); } + @Test + public void getPath_LeadinRepoBranch() + { + String path = rawServlet.getPath("repo.git", "bae", "project/repo.git/bae"); + + assertEquals("Expected path to be empty since no path was present","" , path); + } @Test - public void getPath_PiEmpty() + public void getPath_ProjectRepoBranch() { - HttpServletRequest request = mock(HttpServletRequest.class); - when(request.getPathInfo()).thenReturn(""); + String path = rawServlet.getPath("test/r.git", "b", "test/r.git/b"); - String path = rawServlet.getPath("test.git", "", request); + assertEquals("Expected returned path to be empty since no path was present", "", path); + } - assertEquals("Path was supposed to be empty as no path info exists.", "", path); + @Test + public void getPath_LeadinProjectRepoBranch() + { + String path = rawServlet.getPath("test/r.git", "b", "a/b/test/r.git/b"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchTrailingSlash() + { + String path = rawServlet.getPath("test.git", "fixthis", "test.git/fixthis/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchFile() + { + String path = rawServlet.getPath("/bob.git", "branch", "bob.git/branch/file.txt"); + + assertEquals("file.txt", path); + } + + @Test + public void getPath_RepoBranchFolderFile() + { + String path = rawServlet.getPath("/bill.git", "flex", "bill.git/flex/fold" + FSC + "laundr.y"); + + assertEquals("fold/laundr.y", path); + } + + @Test + public void getPath_RepoBranchFoldersTrailingSlash() + { + String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold/"); + + assertEquals("fold/gold", path); + } + + @Test + public void getPath_RepoBranchFoldersTrailingFsc() + { + String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold" + FSC); + + assertEquals("fold/gold", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchFoldersTrailingSlash() + { + String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/"); + + assertEquals("dumm/di/dumm", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchFoldersTrailingFsc() + { + String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC); + + assertEquals("dumm/di/dumm", path); + } + + @Test + public void getPath_RepoCommitid() + { + String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoCommitidNoTrailingSlash() + { + String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoCommitidFolderTrailingSlash() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/"); + + assertEquals("src", path); + } + + @Test + public void getPath_ProjectRepoCommitidFolderTrailingFsc() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC); + + assertEquals("src", path); + } + + @Test + public void getPath_ProjectSubRepoCommitidFolderFile() + { + String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md"); + + assertEquals("src/README.md", path); + } + + @Test + public void getPath_RepoBranchWithFsc() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithTwoFsc() + { + String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoBranchWithTwoFsc() + { + String path = rawServlet.getPath("Java/git/git.git", "feature/rebase/onto", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_ProjectRepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("in Go/git.git", "feature/rebase/onto", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_LeadinProjectRepoBranchWithTwoFscTrailingSlash() + { + String path = rawServlet.getPath("Go/git.git", "feature/rebase/onto", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFscFolder() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto"); + + assertEquals("onto", path); + } + + @Test + public void getPath_RepoBranchWithFscFolderFile() + { + String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto" + FSC + "head"); + + assertEquals("onto/head", path); + } + + @Test + public void getPath_RepoBranchWithFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "|"); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some|feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFsc_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some" + FSC + "feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Test + public void getPath_RepoBranchWithFscFoldersTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String path = rawServlet.getPath("git.git", "hotfix/1.2.3", "git.git/hotfix:1.2.3/src:main:java/"); + + assertEquals("src/main/java", path); } + @Test + public void getPath_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC); + + String path = rawServlet.getPath("git.git", "some/feature", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot"); + + assertEquals("some/folder/file.dot", path); + } + + @Test + public void getPath_RepoBranchWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + + @Test + public void getPath_RepoBranchWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature/"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ";"); + + String path = rawServlet.getPath("git.git", "some/feature", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt"); + + assertEquals("path" + FSC + "to" + FSC + "file.txt", path); + } + + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, ":"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/start", "git.git/go" + FSC + "to:start"); + + assertEquals("Expected returned path to be empty since no path was present", "", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect/"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+"); + + assertEquals("dont" + FSC + "collect", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC); + + assertEquals("dont" + FSC + "collect" + FSC, path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/" + FSC + "dont" + FSC + "collect+money.eur"); + + assertEquals(FSC + "dont" + FSC + "collect/money.eur", path); + } + + @Ignore // TODO: Why was it implemented this way? + @Test + public void getPath_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc() + { + settings.overrideSetting(Keys.web.forwardSlashCharacter, "+"); + + String path = rawServlet.getPath("games/Monopoly/git.git", "go" + FSC + "to/prison", "blah/games/Monopoly/git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur"); + + assertEquals("dont" + FSC + "collect/money.eur", path); + } } |