1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import jakarta.json.JsonObject;
9 import java.io.IOException;
10 import org.hamcrest.MatcherAssert;
11 import org.hamcrest.Matchers;
12 import org.junit.jupiter.api.AfterAll;
13 import org.junit.jupiter.api.BeforeAll;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19
20
21 @OAuthScope(OAuthScope.Scope.REPO)
22 final class RtTreesITCase {
23
24
25
26
27 private static Repos repos;
28
29
30
31
32 private static Repo repo;
33
34
35
36
37
38 private static RepoRule rule = new RepoRule();
39
40
41
42
43 @BeforeAll
44 static void setUp() throws IOException {
45 final GitHub github = GitHubIT.connect();
46 RtTreesITCase.repos = github.repos();
47 RtTreesITCase.repo = RtTreesITCase.rule.repo(RtTreesITCase.repos);
48 }
49
50
51
52
53 @AfterAll
54 static void tearDown() throws IOException {
55 if (RtTreesITCase.repos != null && RtTreesITCase.repo != null) {
56 RtTreesITCase.repos.remove(RtTreesITCase.repo.coordinates());
57 }
58 }
59
60 @Test
61 void createsAndObtainsTree() throws IOException {
62 final Trees trees = RtTreesITCase.repo.git().trees();
63 final JsonObject json = Json.createObjectBuilder().add(
64 "tree",
65 Json.createArrayBuilder().add(
66 Json.createObjectBuilder()
67 .add("path", "test.txt")
68 .add("mode", "100644")
69 .add("type", "blob")
70 .add("content", "hello").build()
71 ).build()
72 ).build();
73 final Tree tree = trees.create(json);
74 MatcherAssert.assertThat(
75 "Values are not equal",
76 trees.get(tree.json().getString("sha")),
77 Matchers.is(tree)
78 );
79 }
80 }