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 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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.Test;
  11. import javax.servlet.http.HttpServletRequest;
  12. import static org.junit.Assert.*;
  13. import static org.mockito.Mockito.mock;
  14. import static org.mockito.Mockito.when;
  15. public class RawServletTest
  16. {
  17. private final static String FSC = "!";
  18. private static MockRuntimeManager mockRuntimeManager = new MockRuntimeManager();
  19. private static IStoredSettings settings;
  20. private IRepositoryManager repositoryMngr;
  21. private RawServlet rawServlet;
  22. @BeforeClass
  23. public static void init()
  24. {
  25. MockGitblitContext gitblitContext = new MockGitblitContext();
  26. gitblitContext.addManager(mockRuntimeManager);
  27. settings = mockRuntimeManager.getSettings();
  28. }
  29. @Before
  30. public void setUp()
  31. {
  32. settings.overrideSetting(Keys.web.forwardSlashCharacter, "/");
  33. repositoryMngr = mock(IRepositoryManager.class);
  34. rawServlet = new RawServlet(mockRuntimeManager, repositoryMngr);
  35. }
  36. @Test
  37. public void asLink_HttpUrlRepo()
  38. {
  39. String baseUrl = "http://localhost";
  40. String repository = "test.git";
  41. String branch = null;
  42. String path = null;
  43. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  44. assertNotNull(link);
  45. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  46. }
  47. @Test
  48. public void asLink_HttpUrlTrailingSlashRepo()
  49. {
  50. String baseUrl = "http://localhost/";
  51. String repository = "test.git";
  52. String branch = null;
  53. String path = null;
  54. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  55. assertNotNull(link);
  56. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/", link);
  57. }
  58. @Test
  59. public void asLink_HttpUrlRepoLeadingSlash()
  60. {
  61. String baseUrl = "http://localhost";
  62. String repository = "/test.git";
  63. String branch = null;
  64. String path = null;
  65. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  66. assertNotNull(link);
  67. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/", link);
  68. }
  69. @Test
  70. public void asLink_HttpUrlTrailingSlashRepoLeadingSlash()
  71. {
  72. String baseUrl = "http://localhost/";
  73. String repository = "/test.git";
  74. String branch = null;
  75. String path = null;
  76. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  77. assertNotNull(link);
  78. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/", link);
  79. }
  80. @Test
  81. public void asLink_HttpUrlRepoBranch()
  82. {
  83. String baseUrl = "http://localhost";
  84. String repository = "test.git";
  85. String branch = "b52";
  86. String path = null;
  87. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  88. assertNotNull(link);
  89. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/", link);
  90. }
  91. @Test
  92. public void asLink_HttpUrlTrailingSlashRepoBranch()
  93. {
  94. String baseUrl = "http://localhost/";
  95. String repository = "test.git";
  96. String branch = "branch";
  97. String path = null;
  98. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  99. assertNotNull(link);
  100. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/" + branch + "/", link);
  101. }
  102. @Test
  103. public void asLink_HttpUrlRepoLeadingSlashBranch()
  104. {
  105. String baseUrl = "http://localhost";
  106. String repository = "/test.git";
  107. String branch = "featureOne";
  108. String path = null;
  109. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  110. assertNotNull(link);
  111. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
  112. }
  113. @Test
  114. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranch()
  115. {
  116. String baseUrl = "http://localhost/";
  117. String repository = "/test.git";
  118. String branch = "b";
  119. String path = null;
  120. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  121. assertNotNull(link);
  122. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/" + branch + "/", link);
  123. }
  124. @Test
  125. public void asLink_HttpUrlRepoBranchWithSlash()
  126. {
  127. String baseUrl = "http://localhost";
  128. String repository = "test.git";
  129. String branch = "feature/whatever";
  130. String path = null;
  131. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  132. assertNotNull(link);
  133. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch.replaceAll("/", FSC) + "/", link);
  134. }
  135. @Test
  136. public void asLink_HttpUrlTrailingSlashRepoBranchWithSlash()
  137. {
  138. String baseUrl = "http://localhost/";
  139. String repository = "test.git";
  140. String branch = "branch/for/issue/16";
  141. String path = null;
  142. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  143. assertNotNull(link);
  144. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  145. + branch.replaceAll("/", FSC) + "/", link);
  146. }
  147. @Test
  148. public void asLink_HttpUrlRepoLeadingSlashBranchWithSlash()
  149. {
  150. String baseUrl = "http://localhost";
  151. String repository = "/test.git";
  152. String branch = "releases/1.2.3";
  153. String path = null;
  154. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  155. assertNotNull(link);
  156. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  157. + branch.replaceAll("/", FSC) + "/", link);
  158. }
  159. @Test
  160. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlash()
  161. {
  162. String baseUrl = "http://localhost/";
  163. String repository = "/test.git";
  164. String branch = "b/52";
  165. String path = null;
  166. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  167. assertNotNull(link);
  168. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  169. + branch.replaceAll("/", FSC) + "/", link);
  170. }
  171. @Test
  172. public void asLink_HttpUrlRepoBranchPathFile()
  173. {
  174. String baseUrl = "http://localhost";
  175. String repository = "test.git";
  176. String branch = "b52";
  177. String path = "file.txt";
  178. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  179. assertNotNull(link);
  180. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/" + branch + "/" + path, link);
  181. }
  182. @Test
  183. public void asLink_HttpUrlTrailingSlashRepoBranchPathFolderFile()
  184. {
  185. String baseUrl = "http://localhost/";
  186. String repository = "test.git";
  187. String branch = "branch";
  188. String path = "path/to/file.png";
  189. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  190. assertNotNull(link);
  191. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  192. + branch + "/" + path.replaceAll("/", FSC), link);
  193. }
  194. @Test
  195. public void asLink_HttpUrlRepoLeadingSlashBranchPathFolderLeadingSlash()
  196. {
  197. String baseUrl = "http://localhost";
  198. String repository = "/test.git";
  199. String branch = "featureOne";
  200. String path = "/folder";
  201. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  202. assertNotNull(link);
  203. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/" + branch + path, link);
  204. }
  205. @Test
  206. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchSubFolder()
  207. {
  208. String baseUrl = "http://localhost/";
  209. String repository = "/test.git";
  210. String branch = "b";
  211. String path = "sub/folder";
  212. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  213. assertNotNull(link);
  214. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  215. + branch + "/" + path.replaceAll("/", FSC), link);
  216. }
  217. @Test
  218. public void asLink_HttpUrlRepoBranchWithSlashPathFolder()
  219. {
  220. String baseUrl = "http://localhost";
  221. String repository = "test.git";
  222. String branch = "feature/whatever";
  223. String path = "folder";
  224. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  225. assertNotNull(link);
  226. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  227. + branch.replaceAll("/", FSC) + "/" + path, link);
  228. }
  229. @Test
  230. public void asLink_HttpUrlTrailingSlashRepoBranchWithSlashPathFolderFile()
  231. {
  232. String baseUrl = "http://localhost/";
  233. String repository = "test.git";
  234. String branch = "branch/for/issue/16";
  235. String path = "a/file.gif";
  236. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  237. assertNotNull(link);
  238. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository + "/"
  239. + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
  240. }
  241. @Test
  242. public void asLink_HttpUrlRepoLeadingSlashBranchWithSlashPathFile()
  243. {
  244. String baseUrl = "http://localhost";
  245. String repository = "/test.git";
  246. String branch = "releases/1.2.3";
  247. String path = "hurray.png";
  248. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  249. assertNotNull(link);
  250. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  251. + branch.replaceAll("/", FSC) + "/" + path, link);
  252. }
  253. @Test
  254. public void asLink_HttpUrlTrailingSlashRepoLeadingSlashBranchWithSlashPathFolderFile()
  255. {
  256. String baseUrl = "http://localhost/";
  257. String repository = "/test.git";
  258. String branch = "b/52";
  259. String path = "go/to/f.k";
  260. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  261. assertNotNull(link);
  262. assertEquals(baseUrl.substring(0, baseUrl.length()-1) + Constants.RAW_PATH + repository.substring(1) + "/"
  263. + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
  264. }
  265. @Test
  266. public void asLink_HttpUrlRepoInFolder()
  267. {
  268. String baseUrl = "http://localhost";
  269. String repository = "project/repo.git";
  270. String branch = null;
  271. String path = null;
  272. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  273. assertNotNull(link);
  274. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  275. }
  276. @Test
  277. public void asLink_HttpUrlRepoInSubFolder()
  278. {
  279. String baseUrl = "http://localhost";
  280. String repository = "some/project/repo.git";
  281. String branch = null;
  282. String path = null;
  283. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  284. assertNotNull(link);
  285. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  286. }
  287. @Test
  288. public void asLink_HttpUrlRepoInSubFolderBranch()
  289. {
  290. String baseUrl = "http://localhost";
  291. String repository = "some/project/repo.git";
  292. String branch = "laluna";
  293. String path = null;
  294. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  295. assertNotNull(link);
  296. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  297. + branch + "/", link);
  298. }
  299. @Test
  300. public void asLink_HttpUrlRepoInSubFolderBranchWithSlash()
  301. {
  302. String baseUrl = "http://localhost";
  303. String repository = "some/project/repo.git";
  304. String branch = "la/le/lu";
  305. String path = null;
  306. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  307. assertNotNull(link);
  308. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  309. + branch.replaceAll("/", FSC) + "/", link);
  310. }
  311. @Test
  312. public void asLink_HttpUrlRepoInSubFolderBranchPathFile()
  313. {
  314. String baseUrl = "http://localhost";
  315. String repository = "some/project/repo.git";
  316. String branch = "laluna";
  317. String path = "elrtkx.fg";
  318. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  319. assertNotNull(link);
  320. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  321. + branch + "/" + path, link);
  322. }
  323. @Test
  324. public void asLink_HttpUrlRepoInSubFolderLeadingSlashBranchWithSlashPathFolderFile()
  325. {
  326. String baseUrl = "http://localhost";
  327. String repository = "/some/project/repo.git";
  328. String branch = "la/le/lu";
  329. String path = "doremi/fa/SOLA/di.mp3";
  330. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  331. assertNotNull(link);
  332. assertEquals(baseUrl + Constants.RAW_PATH + repository.substring(1) + "/"
  333. + branch.replaceAll("/", FSC) + "/" + path.replaceAll("/", FSC), link);
  334. }
  335. @Test
  336. public void asLink_HttpUrlRepoPathFolderFile()
  337. {
  338. String baseUrl = "http://localhost";
  339. String repository = "repo.git";
  340. String branch = null;
  341. String path = "doko/di.mp3";
  342. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  343. assertNotNull(link);
  344. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/", link);
  345. }
  346. @Test
  347. public void asLink_HttpUrlRepoTrailingSlashPathFileLeadingSlash()
  348. {
  349. String baseUrl = "http://localhost";
  350. String repository = "repo.git/";
  351. String branch = null;
  352. String path = "/di.mp3";
  353. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  354. assertNotNull(link);
  355. assertEquals(baseUrl + Constants.RAW_PATH + repository, link);
  356. }
  357. @Test
  358. public void asLink_HttpUrlRepoBranchPathFileLeadingSlash()
  359. {
  360. String baseUrl = "http://localhost";
  361. String repository = "repo.git";
  362. String branch = "bee";
  363. String path = "/bop.mp3";
  364. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  365. assertNotNull(link);
  366. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  367. + branch + path, link);
  368. }
  369. @Test
  370. public void asLink_HttpUrlRepoBranchPathFolderLeadingSlashTrailingSlash()
  371. {
  372. String baseUrl = "http://localhost";
  373. String repository = "repo.git";
  374. String branch = "bee";
  375. String path = "/bam/";
  376. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  377. assertNotNull(link);
  378. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  379. + branch + "/bam" + FSC, link);
  380. }
  381. @Test
  382. public void asLink_HttpUrlRepoBranchPathSubFolderLeadingSlashTrailingSlash()
  383. {
  384. String baseUrl = "http://localhost";
  385. String repository = "repo.git";
  386. String branch = "bee";
  387. String path = "/bapedi/boo/";
  388. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  389. assertNotNull(link);
  390. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  391. + branch + "/" + "bapedi" + FSC + "boo" + FSC, link);
  392. }
  393. @Test
  394. public void asLink_HttpUrlRepoCommitId()
  395. {
  396. String baseUrl = "http://localhost";
  397. String repository = "repo.git";
  398. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  399. String path = null;
  400. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  401. assertNotNull(link);
  402. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  403. + branch + "/" , link);
  404. }
  405. @Test
  406. public void asLink_HttpUrlRepoCommitIdPathFile()
  407. {
  408. String baseUrl = "http://localhost";
  409. String repository = "repo.git";
  410. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  411. String path = "file";
  412. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  413. assertNotNull(link);
  414. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  415. + branch + "/" + path, link);
  416. }
  417. @Test
  418. public void asLink_HttpUrlRepoCommitIdPathFolderFileFile()
  419. {
  420. String baseUrl = "http://localhost";
  421. String repository = "repo.git";
  422. String branch = "c7eef37bfe5ae246cdf5ca5c502e4b5471290cb1";
  423. String path = "file/in/folder";
  424. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  425. assertNotNull(link);
  426. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  427. + branch + "/" + path.replaceAll("/", FSC), link);
  428. }
  429. @Test
  430. public void asLink_HttpUrlRepoBranchWithSlash_differentFsc()
  431. {
  432. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  433. String baseUrl = "http://localhost";
  434. String repository = "repo.git";
  435. String branch = "some/feature";
  436. String path = null;
  437. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  438. assertNotNull(link);
  439. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  440. + branch.replaceAll("/", "|") + "/", link);
  441. }
  442. @Test
  443. public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_differentFsc()
  444. {
  445. settings.overrideSetting(Keys.web.forwardSlashCharacter, ";");
  446. String baseUrl = "http://localhost";
  447. String repository = "repo.git";
  448. String branch = "some/feature";
  449. String path = "file/in/folder";
  450. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  451. assertNotNull(link);
  452. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  453. + branch.replaceAll("/", ";") + "/" + path.replaceAll("/", ";"), link);
  454. }
  455. @Test
  456. public void asLink_HttpUrlRepoBranchWithSlash_explicitFscSameAsDefault()
  457. {
  458. settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
  459. String baseUrl = "http://localhost";
  460. String repository = "repo.git";
  461. String branch = "some/feature";
  462. String path = null;
  463. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  464. assertNotNull(link);
  465. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  466. + branch.replaceAll("/", "!") + "/", link);
  467. }
  468. @Test
  469. public void asLink_HttpUrlRepoBranchWithSlashPathFolderFile_explicitFscSameAsDefault()
  470. {
  471. settings.overrideSetting(Keys.web.forwardSlashCharacter, "!");
  472. String baseUrl = "http://localhost";
  473. String repository = "repo.git";
  474. String branch = "some/feature";
  475. String path = "file/in/folder";
  476. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  477. assertNotNull(link);
  478. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  479. + branch.replaceAll("/", "!") + "/" + path.replaceAll("/", "!"), link);
  480. }
  481. @Test
  482. public void asLink_HttpUrlRepoBranchWithDefaultFsc_differentFsc()
  483. {
  484. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  485. String baseUrl = "http://localhost";
  486. String repository = "repo.git";
  487. String branch = "important" + FSC + "feature";
  488. String path = null;
  489. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  490. assertNotNull(link);
  491. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  492. + branch + "/", link);
  493. }
  494. @Test
  495. public void asLink_HttpUrlRepoBranchWithSlashPathFileWithDefaultFsc_differentFsc()
  496. {
  497. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  498. String baseUrl = "http://localhost";
  499. String repository = "repo.git";
  500. String branch = "some/feature";
  501. String path = "large" + FSC + "file";
  502. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  503. assertNotNull(link);
  504. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  505. + branch.replaceAll("/", "|") + "/" + path, link);
  506. }
  507. @Test
  508. public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlash_differentFsc()
  509. {
  510. settings.overrideSetting(Keys.web.forwardSlashCharacter, ":");
  511. String baseUrl = "http://localhost";
  512. String repository = "repo.git";
  513. String branch = "hotf" + FSC + "x/issue/1234";
  514. String path = null;
  515. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  516. assertNotNull(link);
  517. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  518. + branch.replaceAll("/", ":") + "/", link);
  519. }
  520. @Test
  521. public void asLink_HttpUrlRepoBranchWithDefaultFscAndSlashPathFolderFileWithDefaultFsc_differentFsc()
  522. {
  523. settings.overrideSetting(Keys.web.forwardSlashCharacter, "|");
  524. String baseUrl = "http://localhost";
  525. String repository = "repo.git";
  526. String branch = "some/feature" + FSC + "in/here";
  527. String path = "large" + FSC + "stuff/folder/file" + FSC + "16";
  528. String link = RawServlet.asLink(baseUrl, repository, branch, path);
  529. assertNotNull(link);
  530. assertEquals(baseUrl + Constants.RAW_PATH + repository + "/"
  531. + branch.replaceAll("/", "|") + "/" + path.replaceAll("/", "|"), link);
  532. }
  533. @Test
  534. public void getBranch()
  535. {
  536. }
  537. @Test
  538. public void getPath()
  539. {
  540. }
  541. @Test
  542. public void getBranch_Repo()
  543. {
  544. HttpServletRequest request = mock(HttpServletRequest.class);
  545. when(request.getPathInfo()).thenReturn("/test.git/");
  546. String branch = rawServlet.getBranch("test.git", request);
  547. assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
  548. }
  549. @Test
  550. public void getBranch_RepoNoTrailingSlash()
  551. {
  552. HttpServletRequest request = mock(HttpServletRequest.class);
  553. when(request.getPathInfo()).thenReturn("/test.git");
  554. String branch = rawServlet.getBranch("test.git", request);
  555. assertEquals("Branch was supposed to be empty as no branch was given.", "", branch);
  556. }
  557. @Test
  558. public void getBranch_PiNull()
  559. {
  560. HttpServletRequest request = mock(HttpServletRequest.class);
  561. when(request.getPathInfo()).thenReturn(null);
  562. String branch = rawServlet.getBranch("test.git", request);
  563. assertEquals("Branch was supposed to be empty as path info is null.", "", branch);
  564. }
  565. @Test
  566. public void getBranch_PiEmpty()
  567. {
  568. HttpServletRequest request = mock(HttpServletRequest.class);
  569. when(request.getPathInfo()).thenReturn("");
  570. String branch = rawServlet.getBranch("test.git", request);
  571. assertEquals("Branch was supposed to be empty as no path info exists.", "", branch);
  572. }
  573. @Test
  574. public void getPath_Repo()
  575. {
  576. HttpServletRequest request = mock(HttpServletRequest.class);
  577. when(request.getPathInfo()).thenReturn("/test.git/");
  578. String path = rawServlet.getPath("test.git", "", request);
  579. assertEquals("Path was supposed to be empty as no path was given.", "", path);
  580. }
  581. @Test
  582. public void getPath_RepoNoTrailingSlash()
  583. {
  584. HttpServletRequest request = mock(HttpServletRequest.class);
  585. when(request.getPathInfo()).thenReturn("/test.git");
  586. String path = rawServlet.getPath("test.git", "", request);
  587. assertEquals("Path was supposed to be empty as no path was given.", "", path);
  588. }
  589. @Test
  590. public void getPath_PiNull()
  591. {
  592. HttpServletRequest request = mock(HttpServletRequest.class);
  593. when(request.getPathInfo()).thenReturn(null);
  594. String path = rawServlet.getPath("test.git", "", request);
  595. assertEquals("Path was supposed to be empty as path info is null.", "", path);
  596. }
  597. @Test
  598. public void getPath_PiEmpty()
  599. {
  600. HttpServletRequest request = mock(HttpServletRequest.class);
  601. when(request.getPathInfo()).thenReturn("");
  602. String path = rawServlet.getPath("test.git", "", request);
  603. assertEquals("Path was supposed to be empty as no path info exists.", "", path);
  604. }
  605. }