You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RawServletTest.java 46KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. package com.gitblit.servlet;
  2. import com.gitblit.Constants;
  3. import com.gitblit.IStoredSettings;
  4. import com.gitblit.Keys;
  5. import com.gitblit.manager.IRepositoryManager;
  6. import com.gitblit.tests.mock.MockGitblitContext;
  7. import com.gitblit.tests.mock.MockRuntimeManager;
  8. import org.junit.Before;
  9. import org.junit.BeforeClass;
  10. import org.junit.Ignore;
  11. import org.junit.Test;
  12. import static org.junit.Assert.*;
  13. import static org.mockito.Mockito.mock;
  14. public class RawServletTest
  15. {
  16. private static final char FSC = RawServlet.FSC;
  17. private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager();
  18. private static IStoredSettings settings;
  19. private IRepositoryManager repositoryMngr;
  20. private RawServlet rawServlet;
  21. @BeforeClass
  22. public static void init()
  23. {
  24. MockGitblitContext gitblitContext = new MockGitblitContext();
  25. gitblitContext.addManager(mockRuntimeManager);
  26. settings = mockRuntimeManager.getSettings();
  27. }
  28. @Before
  29. public void setUp()
  30. {
  31. settings.overrideSetting(Keys.web.forwardSlashCharacter, "/");
  32. repositoryMngr = mock(IRepositoryManager.class);
  33. rawServlet = new RawServlet(mockRuntimeManager, repositoryMngr);
  34. }
  35. @Test
  36. public void asLink_HttpUrlRepo()
  37. {
  38. String baseUrl = "http://localhost";
  39. String repository = "test.git";
  40. String branch = null;
  41. String path = null;
  42. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  43. assertNotNull(link);
  44. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  45. }
  46. @Test
  47. public void asLink_HttpUrlTrailingSlashRepo()
  48. {
  49. String baseUrl = "http://localhost/";
  50. String repository = "test.git";
  51. String branch = null;
  52. String path = null;
  53. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  54. assertNotNull(link);
  55. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/", link);
  56. }
  57. @Test
  58. public void asLink_HttpUrlRepoLeadingSlash()
  59. {
  60. String baseUrl = "http://localhost";
  61. String repository = "/test.git";
  62. String branch = null;
  63. String path = null;
  64. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  65. assertNotNull(link);
  66. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/", link);
  67. }
  68. @Test
  69. public void asLink_HttpUrlTrailingSlashRepoLeadingSlash()
  70. {
  71. String baseUrl = "http://localhost/";
  72. String repository = "/test.git";
  73. String branch = null;
  74. String path = null;
  75. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  76. assertNotNull(link);
  77. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/", link);
  78. }
  79. @Test
  80. public void asLink_HttpUrlRepoBranch()
  81. {
  82. String baseUrl = "http://localhost";
  83. String repository = "test.git";
  84. String branch = "b52";
  85. String path = null;
  86. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  87. assertNotNull(link);
  88. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/", link);
  89. }
  90. @Test
  91. public void asLink_HttpUrlTrailingSlashRepoBranch()
  92. {
  93. String baseUrl = "http://localhost/";
  94. String repository = "test.git";
  95. String branch = "branch";
  96. String path = null;
  97. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  98. assertNotNull(link);
  99. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" + branch + "/", link);
  100. }
  101. @Test
  102. public void asLink_HttpUrlRepoLeadingSlashBranch()
  103. {
  104. String baseUrl = "http://localhost";
  105. String repository = "/test.git";
  106. String branch = "featureOne";
  107. String path = null;
  108. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  109. assertNotNull(link);
  110. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
  111. }
  112. @Test
  113. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranch()
  114. {
  115. String baseUrl = "http://localhost/";
  116. String repository = "/test.git";
  117. String branch = "b";
  118. String path = null;
  119. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  120. assertNotNull(link);
  121. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
  122. }
  123. @Test
  124. public void asLink_HttpUrlRepoBranchWithSlash()
  125. {
  126. String baseUrl = "http://localhost";
  127. String repository = "test.git";
  128. String branch = "feature/whatever";
  129. String path = null;
  130. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  131. assertNotNull(link);
  132. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch.replace('/', FSC) + "/", link);
  133. }
  134. @Test
  135. public void asLink_HttpUrlTrailingSlashRepoBranchWithSlash()
  136. {
  137. String baseUrl = "http://localhost/";
  138. String repository = "test.git";
  139. String branch = "branch/for/issue/16";
  140. String path = null;
  141. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  142. assertNotNull(link);
  143. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  144. + branch.replace('/', FSC) + "/", link);
  145. }
  146. @Test
  147. public void asLink_HttpUrlRepoLeadingSlashBranchWithSlash()
  148. {
  149. String baseUrl = "http://localhost";
  150. String repository = "/test.git";
  151. String branch = "releases/1.2.3";
  152. String path = null;
  153. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  154. assertNotNull(link);
  155. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  156. + branch.replace('/', FSC) + "/", link);
  157. }
  158. @Test
  159. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlash()
  160. {
  161. String baseUrl = "http://localhost/";
  162. String repository = "/test.git";
  163. String branch = "b/52";
  164. String path = null;
  165. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  166. assertNotNull(link);
  167. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  168. + branch.replace('/', FSC) + "/", link);
  169. }
  170. @Test
  171. public void asLink_HttpUrlRepoBranchPathFile()
  172. {
  173. String baseUrl = "http://localhost";
  174. String repository = "test.git";
  175. String branch = "b52";
  176. String path = "file.txt";
  177. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  178. assertNotNull(link);
  179. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/" + path, link);
  180. }
  181. @Test
  182. public void asLink_HttpUrlTrailingSlashRepoBranchPathFolderFile()
  183. {
  184. String baseUrl = "http://localhost/";
  185. String repository = "test.git";
  186. String branch = "branch";
  187. String path = "path/to/file.png";
  188. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  189. assertNotNull(link);
  190. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  191. + branch + "/" + path.replace('/', FSC), link);
  192. }
  193. @Test
  194. public void asLink_HttpUrlRepoLeadingSlashBranchPathFolderLeadingSlash()
  195. {
  196. String baseUrl = "http://localhost";
  197. String repository = "/test.git";
  198. String branch = "featureOne";
  199. String path = "/folder";
  200. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  201. assertNotNull(link);
  202. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + path, link);
  203. }
  204. @Test
  205. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchSubFolder()
  206. {
  207. String baseUrl = "http://localhost/";
  208. String repository = "/test.git";
  209. String branch = "b";
  210. String path = "sub/folder";
  211. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  212. assertNotNull(link);
  213. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  214. + branch + "/" + path.replace('/', FSC), link);
  215. }
  216. @Test
  217. public void asLink_HttpUrlRepoBranchWithSlashPathFolder()
  218. {
  219. String baseUrl = "http://localhost";
  220. String repository = "test.git";
  221. String branch = "feature/whatever";
  222. String path = "folder";
  223. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  224. assertNotNull(link);
  225. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  226. + branch.replace('/', FSC) + "/" + path, link);
  227. }
  228. @Test
  229. public void asLink_HttpUrlTrailingSlashRepoBranchWithSlashPathFolderFile()
  230. {
  231. String baseUrl = "http://localhost/";
  232. String repository = "test.git";
  233. String branch = "branch/for/issue/16";
  234. String path = "a/file.gif";
  235. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  236. assertNotNull(link);
  237. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  238. + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link);
  239. }
  240. @Test
  241. public void asLink_HttpUrlRepoLeadingSlashBranchWithSlashPathFile()
  242. {
  243. String baseUrl = "http://localhost";
  244. String repository = "/test.git";
  245. String branch = "releases/1.2.3";
  246. String path = "hurray.png";
  247. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  248. assertNotNull(link);
  249. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  250. + branch.replace('/', FSC) + "/" + path, link);
  251. }
  252. @Test
  253. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlashPathFolderFile()
  254. {
  255. String baseUrl = "http://localhost/";
  256. String repository = "/test.git";
  257. String branch = "b/52";
  258. String path = "go/to/f.k";
  259. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  260. assertNotNull(link);
  261. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  262. + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link);
  263. }
  264. @Test
  265. public void asLink_HttpUrlRepoInFolder()
  266. {
  267. String baseUrl = "http://localhost";
  268. String repository = "project/repo.git";
  269. String branch = null;
  270. String path = null;
  271. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  272. assertNotNull(link);
  273. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  274. }
  275. @Test
  276. public void asLink_HttpUrlRepoInSubFolder()
  277. {
  278. String baseUrl = "http://localhost";
  279. String repository = "some/project/repo.git";
  280. String branch = null;
  281. String path = null;
  282. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  283. assertNotNull(link);
  284. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  285. }
  286. @Test
  287. public void asLink_HttpUrlRepoInSubFolderBranch()
  288. {
  289. String baseUrl = "http://localhost";
  290. String repository = "some/project/repo.git";
  291. String branch = "laluna";
  292. String path = null;
  293. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  294. assertNotNull(link);
  295. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  296. + branch + "/", link);
  297. }
  298. @Test
  299. public void asLink_HttpUrlRepoInSubFolderBranchWithSlash()
  300. {
  301. String baseUrl = "http://localhost";
  302. String repository = "some/project/repo.git";
  303. String branch = "la/le/lu";
  304. String path = null;
  305. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  306. assertNotNull(link);
  307. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  308. + branch.replace('/', FSC) + "/", link);
  309. }
  310. @Test
  311. public void asLink_HttpUrlRepoInSubFolderBranchPathFile()
  312. {
  313. String baseUrl = "http://localhost";
  314. String repository = "some/project/repo.git";
  315. String branch = "laluna";
  316. String path = "elrtkx.fg";
  317. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  318. assertNotNull(link);
  319. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  320. + branch + "/" + path, link);
  321. }
  322. @Test
  323. public void asLink_HttpUrlRepoInSubFolderLeadingSlashBranchWithSlashPathFolderFile()
  324. {
  325. String baseUrl = "http://localhost";
  326. String repository = "/some/project/repo.git";
  327. String branch = "la/le/lu";
  328. String path = "doremi/fa/SOLA/di.mp3";
  329. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  330. assertNotNull(link);
  331. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  332. + branch.replace('/', FSC) + "/" + path.replace('/', FSC), link);
  333. }
  334. @Test
  335. public void asLink_HttpUrlRepoPathFolderFile()
  336. {
  337. String baseUrl = "http://localhost";
  338. String repository = "repo.git";
  339. String branch = null;
  340. String path = "doko/di.mp3";
  341. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  342. assertNotNull(link);
  343. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  344. }
  345. @Test
  346. public void asLink_HttpUrlRepoTrailingSlashPathFileLeadingSlash()
  347. {
  348. String baseUrl = "http://localhost";
  349. String repository = "repo.git/";
  350. String branch = null;
  351. String path = "/di.mp3";
  352. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  353. assertNotNull(link);
  354. assertEquals(baseUrl + Constants.RAW_PATH + repository, link);
  355. }
  356. @Test
  357. public void asLink_HttpUrlRepoBranchPathFileLeadingSlash()
  358. {
  359. String baseUrl = "http://localhost";
  360. String repository = "repo.git";
  361. String branch = "bee";
  362. String path = "/bop.mp3";
  363. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  364. assertNotNull(link);
  365. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  366. + branch + path, link);
  367. }
  368. @Test
  369. public void asLink_HttpUrlRepoBranchPathFolderLeadingSlashTrailingSlash()
  370. {
  371. String baseUrl = "http://localhost";
  372. String repository = "repo.git";
  373. String branch = "bee";
  374. String path = "/bam/";
  375. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  376. assertNotNull(link);
  377. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  378. + branch + "/bam" + FSC, link);
  379. }
  380. @Test
  381. public void asLink_HttpUrlRepoBranchPathSubFolderLeadingSlashTrailingSlash()
  382. {
  383. String baseUrl = "http://localhost";
  384. String repository = "repo.git";
  385. String branch = "bee";
  386. String path = "/bapedi/boo/";
  387. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  388. assertNotNull(link);
  389. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  390. + branch + "/" + "bapedi" + FSC + "boo" + FSC, link);
  391. }
  392. @Test
  393. public void asLink_HttpUrlRepoCommitId()
  394. {
  395. String baseUrl = "http://localhost";
  396. String repository = "repo.git";
  397. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  398. String path = null;
  399. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  400. assertNotNull(link);
  401. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  402. + branch + "/", link);
  403. }
  404. @Test
  405. public void asLink_HttpUrlRepoCommitIdPathFile()
  406. {
  407. String baseUrl = "http://localhost";
  408. String repository = "repo.git";
  409. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  410. String path = "file";
  411. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  412. assertNotNull(link);
  413. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  414. + branch + "/" + path, link);
  415. }
  416. @Test
  417. public void asLink_HttpUrlRepoCommitIdPathFolderFileFile()
  418. {
  419. String baseUrl = "http://localhost";
  420. String repository = "repo.git";
  421. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  422. String path = "file/in/folder";
  423. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  424. assertNotNull(link);
  425. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  426. + branch + "/" + path.replace('/', FSC), link);
  427. }
  428. @Test
  429. public void asLink_HttpUrlRepoBranchWithSlash_differentFsc()
  430. {
  431. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  432. String baseUrl = "http://localhost";
  433. String repository = "repo.git";
  434. String branch = "some/feature";
  435. String path = null;
  436. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  437. assertNotNull(link);
  438. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  439. + branch.replaceAll("/", "|") + "/", link);
  440. }
  441. @Test
  442. public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_differentFsc()
  443. {
  444. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  445. String baseUrl = "http://localhost";
  446. String repository = "repo.git";
  447. String branch = "some/feature";
  448. String path = "file/in/folder";
  449. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  450. assertNotNull(link);
  451. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  452. + branch.replaceAll("/", ";") + "/" + path.replaceAll("/", ";"), link);
  453. }
  454. @Test
  455. public void asLink_HttpUrlRepoBranchWithSlash_explicitFscSameAsDefault()
  456. {
  457. settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
  458. String baseUrl = "http://localhost";
  459. String repository = "repo.git";
  460. String branch = "some/feature";
  461. String path = null;
  462. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  463. assertNotNull(link);
  464. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  465. + branch.replaceAll("/", "!") + "/", link);
  466. }
  467. @Test
  468. public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_explicitFscSameAsDefault()
  469. {
  470. settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
  471. String baseUrl = "http://localhost";
  472. String repository = "repo.git";
  473. String branch = "some/feature";
  474. String path = "file/in/folder";
  475. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  476. assertNotNull(link);
  477. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  478. + branch.replaceAll("/", "!") + "/" + path.replaceAll("/", "!"), link);
  479. }
  480. @Test
  481. public void asLink_HttpUrlRepoBranchWithDefaultFsc_differentFsc()
  482. {
  483. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  484. String baseUrl = "http://localhost";
  485. String repository = "repo.git";
  486. String branch = "important" + FSC + "feature";
  487. String path = null;
  488. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  489. assertNotNull(link);
  490. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  491. + branch + "/", link);
  492. }
  493. @Test
  494. public void asLink_HttpUrlRepoBranchWithSlashPathFileWithDefaultFsc_differentFsc()
  495. {
  496. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  497. String baseUrl = "http://localhost";
  498. String repository = "repo.git";
  499. String branch = "some/feature";
  500. String path = "large" + FSC + "file";
  501. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  502. assertNotNull(link);
  503. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  504. + branch.replaceAll("/", "|") + "/" + path, link);
  505. }
  506. @Test
  507. public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlash_differentFsc()
  508. {
  509. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  510. String baseUrl = "http://localhost";
  511. String repository = "repo.git";
  512. String branch = "hotf" + FSC + "x/issue/1234";
  513. String path = null;
  514. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  515. assertNotNull(link);
  516. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  517. + branch.replaceAll("/", ":") + "/", link);
  518. }
  519. @Test
  520. public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlashPathFolderFileWithDefaultFsc_differentFsc()
  521. {
  522. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  523. String baseUrl = "http://localhost";
  524. String repository = "repo.git";
  525. String branch = "some/feature" + FSC + "in/here";
  526. String path = "large" + FSC + "stuff/folder/file" + FSC + "16";
  527. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  528. assertNotNull(link);
  529. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  530. + branch.replaceAll("/", "|") + "/" + path.replaceAll("/", "|"), link);
  531. }
  532. @Test
  533. public void getBranch_Repo()
  534. {
  535. String branch = rawServlet.getBranch("test.git", "test.git/");
  536. assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
  537. }
  538. @Test
  539. public void getBranch_PiNull()
  540. {
  541. String branch = rawServlet.getBranch("test.git", null);
  542. assertEquals("Branch was supposed to be empty as path info is null.", "", branch);
  543. }
  544. @Test
  545. public void getBranch_PiEmpty()
  546. {
  547. String branch = rawServlet.getBranch("test.git", "");
  548. assertEquals("Branch was supposed to be empty as no path info exists.", "", branch);
  549. }
  550. @Test
  551. public void getBranch_LeadinRepo()
  552. {
  553. String branch = rawServlet.getBranch("test.git", "some/test.git/");
  554. assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
  555. }
  556. @Test
  557. public void getBranch_ProjectRepo()
  558. {
  559. String branch = rawServlet.getBranch("smack/dab.git", "smack/dab.git/");
  560. assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
  561. }
  562. @Test
  563. public void getBranch_RepoBranch()
  564. {
  565. String branch = rawServlet.getBranch("test.git", "test.git/bee");
  566. assertEquals("bee", branch);
  567. }
  568. @Test
  569. public void getBranch_LeadinRepoBranch()
  570. {
  571. String branch = rawServlet.getBranch("repo.git", "project/repo.git/bae");
  572. assertEquals("bae", branch);
  573. }
  574. @Test
  575. public void getBranch_ProjectRepoBranch()
  576. {
  577. String branch = rawServlet.getBranch("test/r.git", "test/r.git/b");
  578. assertEquals("b", branch);
  579. }
  580. @Test
  581. public void getBranch_LeadinProjectRepoBranch()
  582. {
  583. String branch = rawServlet.getBranch("test/r.git", "a/b/test/r.git/b");
  584. assertEquals("b", branch);
  585. }
  586. @Test
  587. public void getBranch_RepoBranchTrailingSlash()
  588. {
  589. String branch = rawServlet.getBranch("/test.git", "test.git/fixthis/");
  590. assertEquals("fixthis", branch);
  591. }
  592. @Test
  593. public void getBranch_RepoBranchFile()
  594. {
  595. String branch = rawServlet.getBranch("/bob.git", "bob.git/branch/file.txt");
  596. assertEquals("branch", branch);
  597. }
  598. @Test
  599. public void getBranch_RepoBranchFolderFile()
  600. {
  601. String branch = rawServlet.getBranch("/bill.git", "bill.git/flex/fold!laundr.y");
  602. assertEquals("flex", branch);
  603. }
  604. @Test
  605. public void getBranch_RepoBranchFoldersTrailingSlash()
  606. {
  607. String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold!gold/");
  608. assertEquals("flex", branch);
  609. }
  610. @Test
  611. public void getBranch_RepoBranchFoldersTrailingFsc()
  612. {
  613. String branch = rawServlet.getBranch("bill.git", "bill.git/flex/fold"+ FSC + "gold" + FSC);
  614. assertEquals("flex", branch);
  615. }
  616. @Test
  617. public void getBranch_LeadinProjectRepoBranchFoldersTrailingSlash()
  618. {
  619. String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/");
  620. assertEquals("klingeling", branch);
  621. }
  622. @Test
  623. public void getBranch_LeadinProjectRepoBranchFoldersTrailingFsc()
  624. {
  625. String branch = rawServlet.getBranch("bam/bum.git", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC);
  626. assertEquals("klingeling", branch);
  627. }
  628. @Test
  629. public void getBranch_RepoCommitid()
  630. {
  631. String branch = rawServlet.getBranch("git.git", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89");
  632. assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch);
  633. }
  634. @Test
  635. public void getBranch_ProjectRepoCommitidFolderTrailingSlash()
  636. {
  637. String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/");
  638. assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch);
  639. }
  640. @Test
  641. public void getBranch_ProjectRepoCommitidFolderTrailingFsc()
  642. {
  643. String branch = rawServlet.getBranch("git/git.git", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC);
  644. assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch);
  645. }
  646. @Test
  647. public void getBranch_ProjectSubRepoCommitidFolderFile()
  648. {
  649. String branch = rawServlet.getBranch("git/git.git", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md");
  650. assertEquals("a02159e6378d63d0e1ad3c04a05462d9fc62fe89", branch);
  651. }
  652. @Test
  653. public void getBranch_RepoBranchWithFsc()
  654. {
  655. String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase");
  656. assertEquals("feature/rebase", branch);
  657. }
  658. @Test
  659. public void getBranch_RepoBranchWithTwoFsc()
  660. {
  661. String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto");
  662. assertEquals("feature/rebase/onto", branch);
  663. }
  664. @Test
  665. public void getBranch_ProjectRepoBranchWithTwoFsc()
  666. {
  667. String branch = rawServlet.getBranch("Java/git/git.git", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto");
  668. assertEquals("feature/rebase/onto", branch);
  669. }
  670. @Test
  671. public void getBranch_RepoBranchWithTwoFscTrailingSlash()
  672. {
  673. String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase" + FSC + "onto/");
  674. assertEquals("feature/rebase/onto", branch);
  675. }
  676. @Test
  677. public void getBranch_ProjectRepoBranchWithTwoFscTrailingSlash()
  678. {
  679. String branch = rawServlet.getBranch("in Go/git.git", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/");
  680. assertEquals("feature/rebase/onto", branch);
  681. }
  682. @Test
  683. public void getBranch_LeadinProjectRepoBranchWithTwoFscTrailingSlash()
  684. {
  685. String branch = rawServlet.getBranch("Go/git.git", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/");
  686. assertEquals("feature/rebase/onto", branch);
  687. }
  688. @Test
  689. public void getBranch_RepoBranchWithFscFolder()
  690. {
  691. String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto");
  692. assertEquals("feature/rebase", branch);
  693. }
  694. @Test
  695. public void getBranch_RepoBranchWithFscFolderFile()
  696. {
  697. String branch = rawServlet.getBranch("git.git", "git.git/feature" + FSC + "rebase/onto" + FSC + "head");
  698. assertEquals("feature/rebase", branch);
  699. }
  700. @Test
  701. public void getBranch_RepoBranchWithFsc_differentFsc()
  702. {
  703. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  704. String branch = rawServlet.getBranch("git.git", "git.git/some|feature");
  705. assertEquals("some/feature", branch);
  706. }
  707. @Test
  708. public void getBranch_RepoBranchWithFsc_explicitFscSameAsDefault()
  709. {
  710. settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC);
  711. String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature");
  712. assertEquals("some/feature", branch);
  713. }
  714. @Test
  715. public void getBranch_RepoBranchWithFscFolders_differentFsc()
  716. {
  717. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  718. String branch = rawServlet.getBranch("git.git", "git.git/hotfix:1.2.3/src:main:java/");
  719. assertEquals("hotfix/1.2.3", branch);
  720. }
  721. @Test
  722. public void getBranch_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault()
  723. {
  724. settings.overrideSetting(Keys.web.forwardSlashCharacter, FSC);
  725. String branch = rawServlet.getBranch("git.git", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot");
  726. assertEquals("some/feature", branch);
  727. }
  728. @Ignore // TODO: Why was it implemented this way?
  729. @Test
  730. public void getBranch_RepoBranchWithDefaultFsc_differentFsc()
  731. {
  732. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  733. String branch = rawServlet.getBranch("git.git", "git.git/some" + FSC + "feature");
  734. assertEquals("some" + FSC + "feature", branch);
  735. }
  736. @Test
  737. public void getBranch_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc()
  738. {
  739. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  740. String branch = rawServlet.getBranch("git.git", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt");
  741. assertEquals("some/feature", branch);
  742. }
  743. @Ignore // TODO: Why was it implemented this way?
  744. @Test
  745. public void getBranch_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc()
  746. {
  747. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  748. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to:start");
  749. assertEquals("go" + FSC + "to/start", branch);
  750. }
  751. @Ignore // TODO: Why was it implemented this way?
  752. @Test
  753. public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc()
  754. {
  755. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  756. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect");
  757. assertEquals("go" + FSC + "to/prison", branch);
  758. }
  759. @Ignore // TODO: Why was it implemented this way?
  760. @Test
  761. public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc()
  762. {
  763. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  764. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+ prison/dont" + FSC + "collect/");
  765. assertEquals("go" + FSC + "to/prison", branch);
  766. }
  767. @Ignore // TODO: Why was it implemented this way?
  768. @Test
  769. public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc()
  770. {
  771. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  772. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+");
  773. assertEquals("go" + FSC + "to/prison", branch);
  774. }
  775. @Ignore // TODO: Why was it implemented this way?
  776. @Test
  777. public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc()
  778. {
  779. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  780. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC);
  781. assertEquals("go" + FSC + "to/prison", branch);
  782. }
  783. @Ignore // TODO: Why was it implemented this way?
  784. @Test
  785. public void getBranch_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc()
  786. {
  787. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  788. String branch = rawServlet.getBranch("git.git", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur");
  789. assertEquals("go" + FSC + "to/prison", branch);
  790. }
  791. @Ignore // TODO: Why was it implemented this way?
  792. @Test
  793. public void getBranch_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc()
  794. {
  795. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  796. String branch = rawServlet.getBranch("games/Monopoly/git.git", "blah/games/Monopoly/git.git/go" + FSC + "to+prison/dont" + FSC + "collect+money.eur");
  797. assertEquals("go" + FSC + "to/prison", branch);
  798. }
  799. @Test
  800. public void getPath_Repo()
  801. {
  802. String path = rawServlet.getPath("test.git", "", "test.git/");
  803. assertEquals("Path was supposed to be empty as no path was given.", "", path);
  804. }
  805. @Test
  806. public void getPath_PiNull()
  807. {
  808. String path = rawServlet.getPath("test.git", "", null);
  809. assertEquals("Path was supposed to be empty as path info is null.", "", path);
  810. }
  811. @Test
  812. public void getPath_PiEmpty()
  813. {
  814. String path = rawServlet.getPath("test.git", "", "");
  815. assertEquals("Path was supposed to be empty as no path info exists.", "", path);
  816. }
  817. @Test
  818. public void getPath_LeadinRepo()
  819. {
  820. String path = rawServlet.getPath("test.git", "", "some/test.git/");
  821. assertEquals("Path was supposed to be empty as no path was given.", "", path);
  822. }
  823. @Test
  824. public void getPath_ProjectRepo()
  825. {
  826. String path = rawServlet.getPath("smack/dab.git", "", "smack/dab.git/");
  827. assertEquals("Path was supposed to be empty as no path was given.", "", path);
  828. }
  829. @Test
  830. public void getPath_RepoBranch()
  831. {
  832. String path = rawServlet.getPath("test.git", "bee", "test.git/bee");
  833. assertEquals("Expected returned path to be empty since no path was present", "", path);
  834. }
  835. @Test
  836. public void getPath_LeadinRepoBranch()
  837. {
  838. String path = rawServlet.getPath("repo.git", "bae", "project/repo.git/bae");
  839. assertEquals("Expected path to be empty since no path was present","" , path);
  840. }
  841. @Test
  842. public void getPath_ProjectRepoBranch()
  843. {
  844. String path = rawServlet.getPath("test/r.git", "b", "test/r.git/b");
  845. assertEquals("Expected returned path to be empty since no path was present", "", path);
  846. }
  847. @Test
  848. public void getPath_LeadinProjectRepoBranch()
  849. {
  850. String path = rawServlet.getPath("test/r.git", "b", "a/b/test/r.git/b");
  851. assertEquals("Expected returned path to be empty since no path was present", "", path);
  852. }
  853. @Test
  854. public void getPath_RepoBranchTrailingSlash()
  855. {
  856. String path = rawServlet.getPath("test.git", "fixthis", "test.git/fixthis/");
  857. assertEquals("Expected returned path to be empty since no path was present", "", path);
  858. }
  859. @Test
  860. public void getPath_RepoBranchFile()
  861. {
  862. String path = rawServlet.getPath("/bob.git", "branch", "bob.git/branch/file.txt");
  863. assertEquals("file.txt", path);
  864. }
  865. @Test
  866. public void getPath_RepoBranchFolderFile()
  867. {
  868. String path = rawServlet.getPath("/bill.git", "flex", "bill.git/flex/fold" + FSC + "laundr.y");
  869. assertEquals("fold/laundr.y", path);
  870. }
  871. @Test
  872. public void getPath_RepoBranchFoldersTrailingSlash()
  873. {
  874. String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold/");
  875. assertEquals("fold/gold", path);
  876. }
  877. @Test
  878. public void getPath_RepoBranchFoldersTrailingFsc()
  879. {
  880. String path = rawServlet.getPath("bill.git", "flex", "bill.git/flex/fold"+ FSC + "gold" + FSC);
  881. assertEquals("fold/gold", path);
  882. }
  883. @Test
  884. public void getPath_LeadinProjectRepoBranchFoldersTrailingSlash()
  885. {
  886. String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm/");
  887. assertEquals("dumm/di/dumm", path);
  888. }
  889. @Test
  890. public void getPath_LeadinProjectRepoBranchFoldersTrailingFsc()
  891. {
  892. String path = rawServlet.getPath("bam/bum.git", "klingeling", "bim/bam/bum.git/klingeling/dumm" + FSC + "di" + FSC + "dumm" + FSC);
  893. assertEquals("dumm/di/dumm", path);
  894. }
  895. @Test
  896. public void getPath_RepoCommitid()
  897. {
  898. String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/");
  899. assertEquals("Expected returned path to be empty since no path was present", "", path);
  900. }
  901. @Test
  902. public void getPath_RepoCommitidNoTrailingSlash()
  903. {
  904. String path = rawServlet.getPath("/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89");
  905. assertEquals("Expected returned path to be empty since no path was present", "", path);
  906. }
  907. @Test
  908. public void getPath_ProjectRepoCommitidFolderTrailingSlash()
  909. {
  910. String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src/");
  911. assertEquals("src", path);
  912. }
  913. @Test
  914. public void getPath_ProjectRepoCommitidFolderTrailingFsc()
  915. {
  916. String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC);
  917. assertEquals("src", path);
  918. }
  919. @Test
  920. public void getPath_ProjectSubRepoCommitidFolderFile()
  921. {
  922. String path = rawServlet.getPath("git/git.git", "a02159e6378d63d0e1ad3c04a05462d9fc62fe89", "Git implementations/git/git.git/a02159e6378d63d0e1ad3c04a05462d9fc62fe89/src" + FSC + "README.md");
  923. assertEquals("src/README.md", path);
  924. }
  925. @Test
  926. public void getPath_RepoBranchWithFsc()
  927. {
  928. String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase");
  929. assertEquals("Expected returned path to be empty since no path was present", "", path);
  930. }
  931. @Test
  932. public void getPath_RepoBranchWithTwoFsc()
  933. {
  934. String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto");
  935. assertEquals("Expected returned path to be empty since no path was present", "", path);
  936. }
  937. @Test
  938. public void getPath_ProjectRepoBranchWithTwoFsc()
  939. {
  940. String path = rawServlet.getPath("Java/git/git.git", "feature/rebase/onto", "Java/git/git.git/feature" + FSC + "rebase" + FSC + "onto");
  941. assertEquals("Expected returned path to be empty since no path was present", "", path);
  942. }
  943. @Test
  944. public void getPath_RepoBranchWithTwoFscTrailingSlash()
  945. {
  946. String path = rawServlet.getPath("git.git", "feature/rebase/onto", "git.git/feature" + FSC + "rebase" + FSC + "onto/");
  947. assertEquals("Expected returned path to be empty since no path was present", "", path);
  948. }
  949. @Test
  950. public void getPath_ProjectRepoBranchWithTwoFscTrailingSlash()
  951. {
  952. String path = rawServlet.getPath("in Go/git.git", "feature/rebase/onto", "in Go/git.git/feature" + FSC + "rebase" + FSC + "onto/");
  953. assertEquals("Expected returned path to be empty since no path was present", "", path);
  954. }
  955. @Test
  956. public void getPath_LeadinProjectRepoBranchWithTwoFscTrailingSlash()
  957. {
  958. String path = rawServlet.getPath("Go/git.git", "feature/rebase/onto", "all the gits/Go/git.git/feature" + FSC + "rebase" + FSC + "onto/");
  959. assertEquals("Expected returned path to be empty since no path was present", "", path);
  960. }
  961. @Test
  962. public void getPath_RepoBranchWithFscFolder()
  963. {
  964. String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto");
  965. assertEquals("onto", path);
  966. }
  967. @Test
  968. public void getPath_RepoBranchWithFscFolderFile()
  969. {
  970. String path = rawServlet.getPath("git.git", "feature/rebase", "git.git/feature" + FSC + "rebase/onto" + FSC + "head");
  971. assertEquals("onto/head", path);
  972. }
  973. @Test
  974. public void getPath_RepoBranchWithFsc_differentFsc()
  975. {
  976. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  977. String path = rawServlet.getPath("git.git", "some/feature", "git.git/some|feature");
  978. assertEquals("Expected returned path to be empty since no path was present", "", path);
  979. }
  980. @Test
  981. public void getPath_RepoBranchWithFsc_explicitFscSameAsDefault()
  982. {
  983. settings.overrideSetting(Keys.web.forwardSlashCharacter, String.valueOf(FSC));
  984. String path = rawServlet.getPath("git.git", "some/feature", "git.git/some" + FSC + "feature");
  985. assertEquals("Expected returned path to be empty since no path was present", "", path);
  986. }
  987. @Test
  988. public void getPath_RepoBranchWithFscFoldersTrailingSlash_differentFsc()
  989. {
  990. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  991. String path = rawServlet.getPath("git.git", "hotfix/1.2.3", "git.git/hotfix:1.2.3/src:main:java/");
  992. assertEquals("src/main/java", path);
  993. }
  994. @Test
  995. public void getPath_LeadindRepoBranchWithFscFolderFile_explicitFscSameAsDefault()
  996. {
  997. settings.overrideSetting(Keys.web.forwardSlashCharacter, String.valueOf(FSC));
  998. String path = rawServlet.getPath("git.git", "some/feature", "IBM/git.git/some" + FSC + "feature/some" + FSC + "folder" + FSC + "file.dot");
  999. assertEquals("some/folder/file.dot", path);
  1000. }
  1001. @Test
  1002. public void getPath_RepoBranchWithDefaultFsc_differentFsc()
  1003. {
  1004. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  1005. String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature");
  1006. assertEquals("Expected returned path to be empty since no path was present", "", path);
  1007. }
  1008. @Test
  1009. public void getPath_RepoBranchWithDefaultFscTrailingSlash_differentFsc()
  1010. {
  1011. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  1012. String path = rawServlet.getPath("git.git", "some" + FSC + "feature", "git.git/some" + FSC + "feature/");
  1013. assertEquals("Expected returned path to be empty since no path was present", "", path);
  1014. }
  1015. @Ignore // TODO: Why was it implemented this way?
  1016. @Test
  1017. public void getPath_RepoBranchWithDifferentFscFolderFileWithDefaultFsc_differentFsc()
  1018. {
  1019. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  1020. String path = rawServlet.getPath("git.git", "some/feature", "git.git/some;feature/path" + FSC + "to" + FSC + "file.txt");
  1021. assertEquals("path" + FSC + "to" + FSC + "file.txt", path);
  1022. }
  1023. @Test
  1024. public void getPath_RepoBranchWithDefaultFscAndDifferentFsc_differentFsc()
  1025. {
  1026. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  1027. String path = rawServlet.getPath("git.git", "go" + FSC + "to/start", "git.git/go" + FSC + "to:start");
  1028. assertEquals("Expected returned path to be empty since no path was present", "", path);
  1029. }
  1030. @Ignore // TODO: Why was it implemented this way?
  1031. @Test
  1032. public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFsc_differentFsc()
  1033. {
  1034. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1035. String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect");
  1036. assertEquals("dont" + FSC + "collect", path);
  1037. }
  1038. @Ignore // TODO: Why was it implemented this way?
  1039. @Test
  1040. public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingSlash_differentFsc()
  1041. {
  1042. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1043. String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect/");
  1044. assertEquals("dont" + FSC + "collect", path);
  1045. }
  1046. @Ignore // TODO: Why was it implemented this way?
  1047. @Test
  1048. public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingFsc_differentFsc()
  1049. {
  1050. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1051. String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect+");
  1052. assertEquals("dont" + FSC + "collect", path);
  1053. }
  1054. @Ignore // TODO: Why was it implemented this way?
  1055. @Test
  1056. public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderWithDefaultFscTrailingDefaultFsc_differentFsc()
  1057. {
  1058. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1059. String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/dont" + FSC + "collect" + FSC);
  1060. assertEquals("dont" + FSC + "collect" + FSC, path);
  1061. }
  1062. @Ignore // TODO: Why was it implemented this way?
  1063. @Test
  1064. public void getPath_RepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc()
  1065. {
  1066. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1067. String path = rawServlet.getPath("git.git", "go" + FSC + "to/prison", "git.git/go" + FSC + "to+prison/" + FSC + "dont" + FSC + "collect+money.eur");
  1068. assertEquals(FSC + "dont" + FSC + "collect/money.eur", path);
  1069. }
  1070. @Ignore // TODO: Why was it implemented this way?
  1071. @Test
  1072. public void getPath_LeadinProjectRepoBranchWithDefaultFscAndDifferentFscFolderFileWithDefaultFscAndDifferentFsc_differentFsc()
  1073. {
  1074. settings.overrideSetting(Keys.web.forwardSlashCharacter, "+");
  1075. 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");
  1076. assertEquals("dont" + FSC + "collect/money.eur", path);
  1077. }
  1078. }