PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/im-crawler/src/test/java/com/wipro/ats/bdre/imcrawler/tests/URLCanonicalizerTest.java

https://gitlab.com/kingofhappy/openbdre
Java | 73 lines | 47 code | 26 blank | 0 comment | 0 complexity | cae30ffed3015eb4a3f054a1ce38412f MD5 | raw file
  1. package com.wipro.ats.bdre.imcrawler.tests;
  2. import com.wipro.ats.bdre.imcrawler.url.URLCanonicalizer;
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import static org.junit.Assert.assertEquals;
  6. public class URLCanonicalizerTest {
  7. @Test
  8. public void testCanonizalier() {
  9. Assert.assertEquals("http://www.example.com/display?category=foo%2Fbar%2Bbaz",
  10. URLCanonicalizer.getCanonicalURL("http://www.example.com/display?category=foo/bar+baz"));
  11. assertEquals("http://www.example.com/?q=a%2Bb", URLCanonicalizer.getCanonicalURL("http://www.example.com/?q=a+b"));
  12. assertEquals("http://www.example.com/display?category=foo%2Fbar%2Bbaz",
  13. URLCanonicalizer.getCanonicalURL("http://www.example.com/display?category=foo%2Fbar%2Bbaz"));
  14. assertEquals("http://somedomain.com/uploads/1/0/2/5/10259653/6199347.jpg?1325154037", URLCanonicalizer
  15. .getCanonicalURL("http://somedomain.com/uploads/1/0/2/5/10259653/6199347.jpg?1325154037"));
  16. assertEquals("http://hostname.com/", URLCanonicalizer.getCanonicalURL("http://hostname.com"));
  17. assertEquals("http://hostname.com/", URLCanonicalizer.getCanonicalURL("http://HOSTNAME.com"));
  18. assertEquals("http://www.example.com/index.html",
  19. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?&"));
  20. assertEquals("http://www.example.com/index.html",
  21. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?"));
  22. assertEquals("http://www.example.com/", URLCanonicalizer.getCanonicalURL("http://www.example.com"));
  23. assertEquals("http://www.example.com/bar.html",
  24. URLCanonicalizer.getCanonicalURL("http://www.example.com:80/bar.html"));
  25. assertEquals("http://www.example.com/index.html?name=test&rame=base",
  26. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?name=test&rame=base#123"));
  27. assertEquals("http://www.example.com/~username/",
  28. URLCanonicalizer.getCanonicalURL("http://www.example.com/%7Eusername/"));
  29. assertEquals("http://www.example.com/A/B/index.html",
  30. URLCanonicalizer.getCanonicalURL("http://www.example.com//A//B/index.html"));
  31. assertEquals("http://www.example.com/index.html?x=y",
  32. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?&x=y"));
  33. assertEquals("http://www.example.com/a.html",
  34. URLCanonicalizer.getCanonicalURL("http://www.example.com/../../a.html"));
  35. assertEquals("http://www.example.com/a/c/d.html",
  36. URLCanonicalizer.getCanonicalURL("http://www.example.com/../a/b/../c/./d.html"));
  37. assertEquals("http://foo.bar.com/?baz=1", URLCanonicalizer.getCanonicalURL("http://foo.bar.com?baz=1"));
  38. assertEquals("http://www.example.com/index.html?a=b&c=d&e=f",
  39. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?&c=d&e=f&a=b"));
  40. assertEquals("http://www.example.com/index.html?q=a%20b",
  41. URLCanonicalizer.getCanonicalURL("http://www.example.com/index.html?q=a b"));
  42. assertEquals("http://www.example.com/search?height=100%&width=100%",
  43. URLCanonicalizer.getCanonicalURL("http://www.example.com/search?width=100%&height=100%"));
  44. assertEquals("http://foo.bar/mydir/myfile?page=2",
  45. URLCanonicalizer.getCanonicalURL("?page=2", "http://foo.bar/mydir/myfile"));
  46. }
  47. }