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