1
2
3
4
5 package com.jcabi.github;
6
7 import java.io.IOException;
8 import org.hamcrest.MatcherAssert;
9 import org.hamcrest.Matchers;
10 import org.junit.jupiter.api.AfterAll;
11 import org.junit.jupiter.api.BeforeAll;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18
19 @OAuthScope(OAuthScope.Scope.REPO)
20 final class RtBlobsITCase {
21
22
23
24
25 private static Repos repos;
26
27
28
29
30 private static Repo repo;
31
32
33
34
35
36 private static RepoRule rule = new RepoRule();
37
38
39
40
41 @BeforeAll
42 static void setUp() throws IOException {
43 final GitHub github = GitHubIT.connect();
44 RtBlobsITCase.repos = github.repos();
45 RtBlobsITCase.repo = RtBlobsITCase.rule.repo(RtBlobsITCase.repos);
46 }
47
48
49
50
51 @AfterAll
52 static void tearDown() throws IOException {
53 if (RtBlobsITCase.repos != null && RtBlobsITCase.repo != null) {
54 RtBlobsITCase.repos.remove(RtBlobsITCase.repo.coordinates());
55 }
56 }
57
58 @Test
59 void createsBlob() throws IOException {
60 final Blobs blobs = RtBlobsITCase.repo.git().blobs();
61 final Blob blob = blobs.create(
62 "Test Content", "utf-8"
63 );
64 MatcherAssert.assertThat(
65 "Values are not equal",
66 blob.sha(),
67 Matchers.equalTo(blob.json().getString("sha"))
68 );
69 }
70
71 @Test
72 void getsBlob() throws IOException {
73 final Blobs blobs = RtBlobsITCase.repo.git().blobs();
74 final String content = "Content of the blob";
75 final String encoding = "base64";
76 final Blob blob = blobs.create(
77 content, encoding
78 );
79 MatcherAssert.assertThat(
80 "Values are not equal",
81 blobs.get(blob.sha()).json().getString("sha"),
82 Matchers.equalTo(blob.sha())
83 );
84 MatcherAssert.assertThat(
85 "Values are not equal",
86 blobs.get(blob.sha()).json().getString("encoding"),
87 Matchers.equalTo(encoding)
88 );
89 }
90 }