您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SyndicationUtilsTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertTrue;
  19. import java.io.ByteArrayOutputStream;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.HashSet;
  23. import java.util.List;
  24. import java.util.Set;
  25. import org.junit.Test;
  26. import com.gitblit.Constants.SearchType;
  27. import com.gitblit.models.FeedEntryModel;
  28. import com.gitblit.utils.SyndicationUtils;
  29. public class SyndicationUtilsTest {
  30. @Test
  31. public void testSyndication() throws Exception {
  32. List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
  33. for (int i = 0; i < 10; i++) {
  34. FeedEntryModel entry = new FeedEntryModel();
  35. entry.title = "Title " + i;
  36. entry.author = "Author " + i;
  37. entry.link = "Link " + i;
  38. entry.published = new Date();
  39. entry.contentType = "text/plain";
  40. entry.content = "Content " + i;
  41. entry.repository = "Repository " + i;
  42. entry.branch = "Branch " + i;
  43. List<String> tags = new ArrayList<String>();
  44. for (int j = 0; j < 5; j++) {
  45. tags.add("Tag " + j);
  46. }
  47. entry.tags = tags;
  48. entries.add(entry);
  49. }
  50. ByteArrayOutputStream os = new ByteArrayOutputStream();
  51. SyndicationUtils.toRSS("http://localhost", "", "Title", "Description",
  52. entries, os);
  53. String feed = os.toString();
  54. os.close();
  55. assertTrue(feed.indexOf("<title>Title</title>") > -1);
  56. assertTrue(feed.indexOf("<description>Description</description>") > -1);
  57. }
  58. @Test
  59. public void testFeedRead() throws Exception {
  60. Set<String> links = new HashSet<String>();
  61. for (int i = 0; i < 2; i++) {
  62. List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",
  63. "master", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  64. assertTrue(feed != null);
  65. assertTrue(feed.size() > 0);
  66. assertEquals(5, feed.size());
  67. for (FeedEntryModel entry : feed) {
  68. links.add(entry.link);
  69. }
  70. }
  71. // confirm we have 10 unique commits
  72. assertEquals("Feed pagination failed", 10, links.size());
  73. }
  74. @Test
  75. public void testSearchFeedRead() throws Exception {
  76. List<FeedEntryModel> feed = SyndicationUtils
  77. .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,
  78. GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  79. assertTrue(feed != null);
  80. assertTrue(feed.size() > 0);
  81. assertEquals(5, feed.size());
  82. feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", "master", "test",
  83. SearchType.COMMIT, 5, 1, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  84. assertTrue(feed != null);
  85. assertTrue(feed.size() > 0);
  86. assertEquals(5, feed.size());
  87. }
  88. }