1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
package org.fox.ttrss;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import static org.junit.Assert.*;
/**
* Tests for parsing TT-RSS API v2 article detail responses.
* Uses fixture from src/test/resources/responses/article_detail.json
*/
public class ArticleDetailResponseTest {
private String loadFixture(String path) throws IOException {
InputStream is = getClass().getClassLoader().getResourceAsStream(path);
if (is == null) {
throw new IOException("Fixture not found: " + path);
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}
}
// ── Response structure ──────────────────────────────────────────────────
@Test
public void articleResponse_hasSuccessTrue() throws IOException {
JsonObject response = JsonParser.parseString(loadFixture("responses/article_detail.json")).getAsJsonObject();
assertTrue("Article response should have success=true", response.get("success").getAsBoolean());
}
@Test
public void articleResponse_hasDataArray() throws IOException {
JsonObject response = JsonParser.parseString(loadFixture("responses/article_detail.json")).getAsJsonObject();
assertTrue("Article data should be an array", response.get("data").isJsonArray());
}
// ── Core fields ─────────────────────────────────────────────────────────
@Test
public void article_hasId() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have id", article.has("id"));
int id = article.get("id").getAsInt();
assertTrue("Article id should be positive", id > 0);
}
@Test
public void article_hasGuid() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have guid", article.has("guid"));
assertFalse("Article guid should not be empty", article.get("guid").getAsString().isEmpty());
}
@Test
public void article_hasTitle() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have title", article.has("title"));
assertFalse("Article title should not be empty", article.get("title").getAsString().isEmpty());
}
@Test
public void article_hasLink() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have link", article.has("link"));
assertFalse("Article link should not be empty", article.get("link").getAsString().isEmpty());
}
@Test
public void article_hasFeedId() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have feed_id", article.has("feed_id"));
assertTrue("Article feed_id should be positive", article.get("feed_id").getAsInt() > 0);
}
@Test
public void article_hasUpdated() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have updated", article.has("updated"));
assertTrue("Article updated should be non-negative", article.get("updated").getAsInt() >= 0);
}
// ── Boolean status fields ───────────────────────────────────────────────
@Test
public void article_hasUnreadBoolean() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("unread must be a primitive", article.get("unread").isJsonPrimitive());
// Just verify it's a valid boolean value
article.get("unread").getAsBoolean();
}
@Test
public void article_hasMarkedBoolean() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("marked must be a primitive", article.get("marked").isJsonPrimitive());
article.get("marked").getAsBoolean();
}
@Test
public void article_hasPublishedBoolean() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("published must be a primitive", article.get("published").isJsonPrimitive());
article.get("published").getAsBoolean();
}
// ── Content and metadata ────────────────────────────────────────────────
@Test
public void article_hasContent() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have content", article.has("content"));
String content = article.get("content").getAsString();
assertFalse("Article content should not be empty", content.isEmpty());
}
@Test
public void article_hasAuthor() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have author", article.has("author"));
// Author can be empty string but field must exist
}
@Test
public void article_hasScore() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have score", article.has("score"));
// Score should be an integer
article.get("score").getAsInt();
}
@Test
public void article_hasFeedTitle() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have feed_title", article.has("feed_title"));
assertFalse("Article feed_title should not be empty", article.get("feed_title").getAsString().isEmpty());
}
// ── Optional fields ─────────────────────────────────────────────────────
@Test
public void article_hasNote() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have note", article.has("note"));
// Note can be null (as in this fixture)
}
@Test
public void article_hasLang() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have lang", article.has("lang"));
}
@Test
public void article_hasComments() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have comments", article.has("comments"));
}
@Test
public void article_hasCommentsField() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have comments", article.has("comments"));
}
// ── Arrays ──────────────────────────────────────────────────────────────
@Test
public void article_hasLabelsArray() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have labels", article.has("labels"));
assertTrue("labels should be an array", article.get("labels").isJsonArray());
}
@Test
public void article_hasAttachmentsArray() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have attachments", article.has("attachments"));
assertTrue("attachments should be an array", article.get("attachments").isJsonArray());
}
@Test
public void article_hasEnclosuresArray() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have enclosures", article.has("enclosures"));
assertTrue("enclosures should be an array", article.get("enclosures").isJsonArray());
}
// ── Flavor data ─────────────────────────────────────────────────────────
@Test
public void article_hasFlavorImage() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have flavor_image", article.has("flavor_image"));
}
@Test
public void article_hasFlavorStream() throws IOException {
JsonObject article = getFirstArticle();
assertTrue("Article should have flavor_stream", article.has("flavor_stream"));
}
// ── Helper ──────────────────────────────────────────────────────────────
private JsonObject getFirstArticle() throws IOException {
JsonObject response = JsonParser.parseString(loadFixture("responses/article_detail.json")).getAsJsonObject();
JsonArray articles = response.getAsJsonArray("data");
assertTrue("Article data should not be empty", articles.size() > 0);
return articles.get(0).getAsJsonObject();
}
}
|