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.

SyndicationUtilsTest.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 java.util.concurrent.atomic.AtomicBoolean;
  24. import org.junit.AfterClass;
  25. import org.junit.BeforeClass;
  26. import org.junit.Test;
  27. import com.gitblit.Constants.SearchType;
  28. import com.gitblit.models.FeedEntryModel;
  29. import com.gitblit.utils.SyndicationUtils;
  30. public class SyndicationUtilsTest extends GitblitUnitTest {
  31. private static final AtomicBoolean started = new AtomicBoolean(false);
  32. @BeforeClass
  33. public static void startGitblit() throws Exception {
  34. started.set(GitBlitSuite.startGitblit());
  35. }
  36. @AfterClass
  37. public static void stopGitblit() throws Exception {
  38. if (started.get()) {
  39. GitBlitSuite.stopGitblit();
  40. }
  41. }
  42. @Test
  43. public void testSyndication() throws Exception {
  44. List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
  45. for (int i = 0; i < 10; i++) {
  46. FeedEntryModel entry = new FeedEntryModel();
  47. entry.title = "Title " + i;
  48. entry.author = "Author " + i;
  49. entry.link = "Link " + i;
  50. entry.published = new Date();
  51. entry.contentType = "text/plain";
  52. entry.content = "Content " + i;
  53. entry.repository = "Repository " + i;
  54. entry.branch = "Branch " + i;
  55. List<String> tags = new ArrayList<String>();
  56. for (int j = 0; j < 5; j++) {
  57. tags.add("Tag " + j);
  58. }
  59. entry.tags = tags;
  60. entries.add(entry);
  61. }
  62. ByteArrayOutputStream os = new ByteArrayOutputStream();
  63. SyndicationUtils.toRSS("http://localhost", "", "Title", "Description",
  64. entries, os);
  65. String feed = os.toString();
  66. os.close();
  67. assertTrue(feed.indexOf("<title>Title</title>") > -1);
  68. assertTrue(feed.indexOf("<description>Description</description>") > -1);
  69. }
  70. @Test
  71. public void testFeedReadCommits() throws Exception {
  72. Set<String> links = new HashSet<String>();
  73. for (int i = 0; i < 2; i++) {
  74. List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",
  75. "master", 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  76. assertTrue(feed != null);
  77. assertTrue(feed.size() > 0);
  78. assertEquals(5, feed.size());
  79. for (FeedEntryModel entry : feed) {
  80. links.add(entry.link);
  81. }
  82. }
  83. // confirm we have 10 unique commits
  84. assertEquals("Feed pagination failed", 10, links.size());
  85. }
  86. @Test
  87. public void testFeedReadTags() throws Exception {
  88. Set<String> links = new HashSet<String>();
  89. for (int i = 0; i < 2; i++) {
  90. List<FeedEntryModel> feed = SyndicationUtils.readTags(GitBlitSuite.url, "test/gitective.git",
  91. 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  92. assertTrue(feed != null);
  93. assertTrue(feed.size() > 0);
  94. assertEquals(5, feed.size());
  95. for (FeedEntryModel entry : feed) {
  96. links.add(entry.link);
  97. }
  98. }
  99. // confirm we have 10 unique tags
  100. assertEquals("Feed pagination failed", 10, links.size());
  101. }
  102. @Test
  103. public void testSearchFeedRead() throws Exception {
  104. List<FeedEntryModel> feed = SyndicationUtils
  105. .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,
  106. GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  107. assertTrue(feed != null);
  108. assertTrue(feed.size() > 0);
  109. assertEquals(5, feed.size());
  110. feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", "master", "test",
  111. SearchType.COMMIT, 5, 1, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
  112. assertTrue(feed != null);
  113. assertTrue(feed.size() > 0);
  114. assertEquals(5, feed.size());
  115. }
  116. }