Skip to content

Commit 4bd96b6

Browse files
committed
Initial commit (#279).
1 parent 2b91ecd commit 4bd96b6

File tree

7 files changed

+771
-0
lines changed

7 files changed

+771
-0
lines changed

src/main/java/org/gitlab4j/api/DiscussionsApi.java

Lines changed: 357 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.gitlab4j.api;
2+
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import org.gitlab4j.api.utils.JacksonJson;
9+
10+
import com.fasterxml.jackson.core.JsonParseException;
11+
import com.fasterxml.jackson.core.JsonProcessingException;
12+
import com.fasterxml.jackson.databind.JsonMappingException;
13+
import com.fasterxml.jackson.databind.JsonNode;
14+
import com.fasterxml.jackson.databind.MapperFeature;
15+
import com.fasterxml.jackson.databind.SerializationFeature;
16+
17+
public class JsonUtils {
18+
19+
private static JacksonJson jacksonJson;
20+
static {
21+
jacksonJson = new JacksonJson();
22+
jacksonJson.getObjectMapper().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
23+
jacksonJson.getObjectMapper().configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
24+
}
25+
26+
27+
static <T> T unmarshal(Class<T> returnType, String filename) throws JsonParseException, JsonMappingException, IOException {
28+
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename));
29+
return (jacksonJson.unmarshal(returnType, reader));
30+
}
31+
32+
static <T> List<T> unmarshalList(Class<T> returnType, String filename) throws JsonParseException, JsonMappingException, IOException {
33+
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename));
34+
return (jacksonJson.unmarshalList(returnType, reader));
35+
}
36+
37+
static <T> Map<String, T> unmarshalMap(Class<T> returnType, String filename) throws JsonParseException, JsonMappingException, IOException {
38+
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename));
39+
return (jacksonJson.unmarshalMap(returnType, reader));
40+
}
41+
42+
static <T> boolean compareJson(T apiObject, String filename) throws IOException {
43+
44+
InputStreamReader reader = new InputStreamReader(GitLabApi.class.getResourceAsStream(filename));
45+
String objectJson = jacksonJson.marshal(apiObject);
46+
JsonNode tree1 = jacksonJson.getObjectMapper().readTree(objectJson.getBytes());
47+
JsonNode tree2 = jacksonJson.getObjectMapper().readTree(reader);
48+
49+
boolean sameJson = tree1.equals(tree2);
50+
if (!sameJson) {
51+
System.err.println("JSON did not match:");
52+
sortedDump(tree1);
53+
sortedDump(tree2);
54+
}
55+
56+
return (sameJson);
57+
}
58+
59+
static void sortedDump(final JsonNode node) throws JsonProcessingException {
60+
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class);
61+
System.out.println(jacksonJson.getObjectMapper().writeValueAsString(obj));
62+
System.out.flush();
63+
}
64+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[
2+
{
3+
"id": "6a9c1750b37d513a43987b574953fceb50b03ce7",
4+
"individual_note": false,
5+
"notes": [
6+
{
7+
"id": 1126,
8+
"type": "DiscussionNote",
9+
"body": "discussion text",
10+
"author": {
11+
"id": 1,
12+
"name": "root",
13+
"username": "root",
14+
"state": "active",
15+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
16+
"web_url": "http://localhost:3000/root"
17+
},
18+
"created_at": "2018-03-03T21:54:39.668Z",
19+
"updated_at": "2018-03-03T21:54:39.668Z",
20+
"system": false,
21+
"noteable_id": 3,
22+
"noteable_type": "Commit",
23+
"resolvable": false
24+
},
25+
{
26+
"id": 1129,
27+
"type": "DiscussionNote",
28+
"body": "reply to the discussion",
29+
"author": {
30+
"id": 1,
31+
"name": "root",
32+
"username": "root",
33+
"state": "active",
34+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
35+
"web_url": "http://localhost:3000/root"
36+
},
37+
"created_at": "2018-03-04T13:38:02.127Z",
38+
"updated_at": "2018-03-04T13:38:02.127Z",
39+
"system": false,
40+
"noteable_id": 3,
41+
"noteable_type": "Commit",
42+
"resolvable": false
43+
}
44+
]
45+
},
46+
{
47+
"id": "87805b7c09016a7058e91bdbe7b29d1f284a39e6",
48+
"individual_note": true,
49+
"notes": [
50+
{
51+
"id": 1128,
52+
"body": "a single comment",
53+
"author": {
54+
"id": 1,
55+
"name": "root",
56+
"username": "root",
57+
"state": "active",
58+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
59+
"web_url": "http://localhost:3000/root"
60+
},
61+
"created_at": "2018-03-04T09:17:22.520Z",
62+
"updated_at": "2018-03-04T09:17:22.520Z",
63+
"system": false,
64+
"noteable_id": 3,
65+
"noteable_type": "Commit",
66+
"resolvable": false
67+
}
68+
]
69+
}
70+
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[
2+
{
3+
"id": "6a9c1750b37d513a43987b574953fceb50b03ce7",
4+
"individual_note": false,
5+
"notes": [
6+
{
7+
"id": 1126,
8+
"type": "DiscussionNote",
9+
"body": "discussion text",
10+
"author": {
11+
"id": 1,
12+
"name": "root",
13+
"username": "root",
14+
"state": "active",
15+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
16+
"web_url": "http://localhost:3000/root"
17+
},
18+
"created_at": "2018-03-03T21:54:39.668Z",
19+
"updated_at": "2018-03-03T21:54:39.668Z",
20+
"system": false,
21+
"noteable_id": 3,
22+
"noteable_type": "Epic",
23+
"resolvable": false
24+
},
25+
{
26+
"id": 1129,
27+
"type": "DiscussionNote",
28+
"body": "reply to the discussion",
29+
"author": {
30+
"id": 1,
31+
"name": "root",
32+
"username": "root",
33+
"state": "active",
34+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
35+
"web_url": "http://localhost:3000/root"
36+
},
37+
"created_at": "2018-03-04T13:38:02.127Z",
38+
"updated_at": "2018-03-04T13:38:02.127Z",
39+
"system": false,
40+
"noteable_id": 3,
41+
"noteable_type": "Epic",
42+
"resolvable": false
43+
}
44+
]
45+
},
46+
{
47+
"id": "87805b7c09016a7058e91bdbe7b29d1f284a39e6",
48+
"individual_note": true,
49+
"notes": [
50+
{
51+
"id": 1128,
52+
"body": "a single comment",
53+
"author": {
54+
"id": 1,
55+
"name": "root",
56+
"username": "root",
57+
"state": "active",
58+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
59+
"web_url": "http://localhost:3000/root"
60+
},
61+
"created_at": "2018-03-04T09:17:22.520Z",
62+
"updated_at": "2018-03-04T09:17:22.520Z",
63+
"system": false,
64+
"noteable_id": 3,
65+
"noteable_type": "Epic",
66+
"resolvable": false
67+
}
68+
]
69+
}
70+
]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[
2+
{
3+
"id": "6a9c1750b37d513a43987b574953fceb50b03ce7",
4+
"individual_note": false,
5+
"notes": [
6+
{
7+
"id": 1126,
8+
"type": "DiscussionNote",
9+
"body": "discussion text",
10+
"author": {
11+
"id": 1,
12+
"name": "root",
13+
"username": "root",
14+
"state": "active",
15+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
16+
"web_url": "http://localhost:3000/root"
17+
},
18+
"created_at": "2018-03-03T21:54:39.668Z",
19+
"updated_at": "2018-03-03T21:54:39.668Z",
20+
"system": false,
21+
"noteable_id": 3,
22+
"noteable_type": "Issue"
23+
},
24+
{
25+
"id": 1129,
26+
"type": "DiscussionNote",
27+
"body": "reply to the discussion",
28+
"author": {
29+
"id": 1,
30+
"name": "root",
31+
"username": "root",
32+
"state": "active",
33+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
34+
"web_url": "http://localhost:3000/root"
35+
},
36+
"created_at": "2018-03-04T13:38:02.127Z",
37+
"updated_at": "2018-03-04T13:38:02.127Z",
38+
"system": false,
39+
"noteable_id": 3,
40+
"noteable_type": "Issue",
41+
"resolvable": false
42+
}
43+
]
44+
},
45+
{
46+
"id": "87805b7c09016a7058e91bdbe7b29d1f284a39e6",
47+
"individual_note": true,
48+
"notes": [
49+
{
50+
"id": 1128,
51+
"body": "a single comment",
52+
"author": {
53+
"id": 1,
54+
"name": "root",
55+
"username": "root",
56+
"state": "active",
57+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
58+
"web_url": "http://localhost:3000/root"
59+
},
60+
"created_at": "2018-03-04T09:17:22.520Z",
61+
"updated_at": "2018-03-04T09:17:22.520Z",
62+
"system": false,
63+
"noteable_id": 3,
64+
"noteable_type": "Issue",
65+
"resolvable": false
66+
}
67+
]
68+
}
69+
]
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"id": "6a9c1750b37d513a43987b574953fceb50b03ce7",
4+
"individual_note": false,
5+
"notes": [
6+
{
7+
"id": 1126,
8+
"type": "DiscussionNote",
9+
"author": {
10+
"id": 1,
11+
"name": "root",
12+
"username": "root",
13+
"state": "active",
14+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
15+
"web_url": "http://localhost:3000/root"
16+
},
17+
"created_at": "2018-03-03T21:54:39.668Z",
18+
"updated_at": "2018-03-03T21:54:39.668Z",
19+
"system": false,
20+
"noteable_id": 3,
21+
"noteable_type": "Merge request",
22+
"resolved": false,
23+
"resolvable": true
24+
},
25+
{
26+
"id": 1129,
27+
"type": "DiscussionNote",
28+
"body": "reply to the discussion",
29+
"author": {
30+
"id": 1,
31+
"name": "root",
32+
"username": "root",
33+
"state": "active",
34+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
35+
"web_url": "http://localhost:3000/root"
36+
},
37+
"created_at": "2018-03-04T13:38:02.127Z",
38+
"updated_at": "2018-03-04T13:38:02.127Z",
39+
"system": false,
40+
"noteable_id": 3,
41+
"noteable_type": "Merge request",
42+
"resolved": false,
43+
"resolvable": true
44+
}
45+
]
46+
},
47+
{
48+
"id": "87805b7c09016a7058e91bdbe7b29d1f284a39e6",
49+
"individual_note": true,
50+
"notes": [
51+
{
52+
"id": 1128,
53+
"body": "a single comment",
54+
"author": {
55+
"id": 1,
56+
"name": "root",
57+
"username": "root",
58+
"state": "active",
59+
"avatar_url": "https://www.gravatar.com/avatar/00afb8fb6ab07c3ee3e9c1f38777e2f4?s=80&d=identicon",
60+
"web_url": "http://localhost:3000/root"
61+
},
62+
"created_at": "2018-03-04T09:17:22.520Z",
63+
"updated_at": "2018-03-04T09:17:22.520Z",
64+
"system": false,
65+
"noteable_id": 3,
66+
"noteable_type": "Merge request",
67+
"resolved": false,
68+
"resolvable": true
69+
}
70+
]
71+
}
72+
]

0 commit comments

Comments
 (0)