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 package com.jcabi.github;
31
32 import com.jcabi.aspects.Tv;
33 import com.jcabi.github.OAuthScope.Scope;
34 import org.apache.commons.lang3.RandomStringUtils;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.AfterClass;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
40
41
42
43
44
45
46
47 @OAuthScope(Scope.REPO)
48 @SuppressWarnings("PMD.ConsecutiveLiteralAppends")
49 public final class RtReferencesITCase {
50
51
52
53
54
55 private static RepoRule rule = new RepoRule();
56
57
58
59
60 private static Repos repos;
61
62
63
64
65 private static Repo repo;
66
67
68
69
70
71 @BeforeClass
72 public static void setUp() throws Exception {
73 final Github github = new GithubIT().connect();
74 repos = github.repos();
75 repo = rule.repo(repos);
76 }
77
78
79
80
81
82 @AfterClass
83 public static void tearDown() throws Exception {
84 if (repos != null && repo != null) {
85 repos.remove(repo.coordinates());
86 }
87 }
88
89
90
91
92
93 @Test
94 public void createsReference() throws Exception {
95 final References refs = repo.git().references();
96 final String name = RandomStringUtils.randomAlphanumeric(Tv.TEN);
97 final StringBuilder builder = new StringBuilder("refs/tags/")
98 .append(name);
99 final Reference reference = refs.create(
100 builder.toString(),
101 refs.get("refs/heads/master").json().getJsonObject("object")
102 .getString("sha")
103 );
104 MatcherAssert.assertThat(
105 reference,
106 Matchers.notNullValue()
107 );
108 builder.delete(0, builder.length());
109 builder.append("tags/").append(name);
110 refs.remove(builder.toString());
111 }
112
113
114
115
116
117 @Test
118 public void iteratesReferences() throws Exception {
119 final References refs = repo.git().references();
120 final String name = RandomStringUtils.randomAlphanumeric(Tv.TEN);
121 final StringBuilder builder = new StringBuilder("refs/heads/")
122 .append(name);
123 refs.create(
124 builder.toString(),
125 refs.get("refs/heads/master").json().getJsonObject("object")
126 .getString("sha")
127 );
128 MatcherAssert.assertThat(
129 refs.iterate(),
130 Matchers.notNullValue()
131 );
132 builder.delete(0, builder.length());
133 builder.append("heads/").append(name);
134 refs.remove(builder.toString());
135 }
136
137
138
139
140
141 @Test
142 public void iteratesReferencesInSubNamespace() throws Exception {
143 final References refs = repo.git().references();
144 final String name = RandomStringUtils.randomAlphanumeric(Tv.TEN);
145 final StringBuilder builder = new StringBuilder("refs/heads/")
146 .append(name);
147 refs.create(
148 builder.toString(),
149 refs.get("refs/heads/master").json().getJsonObject("object")
150 .getString("sha")
151 );
152 MatcherAssert.assertThat(
153 refs.iterate("heads"),
154 Matchers.notNullValue()
155 );
156 builder.delete(0, builder.length());
157 builder.append("heads/").append(name);
158 refs.remove(builder.toString());
159 }
160
161 }