Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SyndicationUtilsTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.tests;
  17. import java.io.ByteArrayOutputStream;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.HashSet;
  21. import java.util.List;
  22. import java.util.Set;
  23. import org.junit.Test;
  24. import com.gitblit.Constants.SearchType;
  25. import com.gitblit.models.FeedEntryModel;
  26. import com.gitblit.utils.SyndicationUtils;
  27. public class SyndicationUtilsTest extends GitblitUnitTest {
  28. @Test
  29. public void testSyndication() throws Exception {
  30. List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
  31. for (int i = 0; i < 10; i++) {
  32. FeedEntryModel entry = new FeedEntryModel();
  33. entry.title = "Title " + i;
  34. entry.author = "Author " + i;
  35. entry.link = "Link " + i;
  36. entry.published = new Date();
  37. entry.contentType = "text/plain";
  38. entry.content = "Content " + i;
  39. entry.repository = "Repository " + i;
  40. entry.branch = "Branch " + i;
  41. List<String> tags = new ArrayList<String>();
  42. for (int j = 0; j < 5; j++) {
  43. tags.add("Tag " + j);
  44. }
  45. entry.tags = tags;
  46. entries.add(entry);
  47. }
  48. ByteArrayOutputStream os = new ByteArrayOutputStream();
  49. SyndicationUtils.toRSS("http://localhost", "", "Title", "Description",
  50. entries, os);
  51. String feed = os.toString();
  52. os.close();
  53. assertTrue(feed.indexOf("<title>Title</title>") > -1);
  54. assertTrue(feed.indexOf("<description>Description</description>") > -1);
  55. }
  56. @Test
  57. public void testFeedRead() throws Exception {
  58. Set<String> links = new HashSet<String>();
  59. for (int i = 0; i < 2; i++) {
  60. List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",
  61. "master", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  62. assertTrue(feed != null);
  63. assertTrue(feed.size() > 0);
  64. assertEquals(5, feed.size());
  65. for (FeedEntryModel entry : feed) {
  66. links.add(entry.link);
  67. }
  68. }
  69. // confirm we have 10 unique commits
  70. assertEquals("Feed pagination failed", 10, links.size());
  71. }
  72. @Test
  73. public void testSearchFeedRead() throws Exception {
  74. List<FeedEntryModel> feed = SyndicationUtils
  75. .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,
  76. GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  77. assertTrue(feed != null);
  78. assertTrue(feed.size() > 0);
  79. assertEquals(5, feed.size());
  80. feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", "master", "test",
  81. SearchType.COMMIT, 5, 1, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  82. assertTrue(feed != null);
  83. assertTrue(feed.size() > 0);
  84. assertEquals(5, feed.size());
  85. }
  86. }