Skip to content

Commit 2e2c67f

Browse files
committed
Initial check-in.
1 parent eb82986 commit 2e2c67f

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.gitlab4j.api;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assume.assumeTrue;
6+
7+
import org.gitlab4j.api.GitLabApi.ApiVersion;
8+
import org.gitlab4j.api.models.User;
9+
import org.gitlab4j.api.models.Version;
10+
import org.junit.Before;
11+
import org.junit.BeforeClass;
12+
import org.junit.Test;
13+
14+
/**
15+
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
16+
*
17+
* TEST_HOST_URL
18+
* TEST_PRIVATE_TOKEN
19+
* TEST_USERNAME
20+
*
21+
* If any of the above are NULL, all tests in this class will be skipped.
22+
*
23+
*/
24+
public class TestUserApi {
25+
26+
// The following needs to be set to your test repository
27+
private static final String TEST_HOST_URL;
28+
private static final String TEST_PRIVATE_TOKEN;
29+
private static final String TEST_USERNAME;
30+
static {
31+
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
32+
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
33+
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
34+
}
35+
36+
private static GitLabApi gitLabApi;
37+
38+
public TestUserApi() {
39+
super();
40+
}
41+
42+
@BeforeClass
43+
public static void setup() {
44+
45+
String problems = "";
46+
if (TEST_HOST_URL == null || TEST_HOST_URL.trim().length() == 0) {
47+
problems += "TEST_HOST_URL cannot be empty\n";
48+
}
49+
50+
if (TEST_PRIVATE_TOKEN == null || TEST_PRIVATE_TOKEN.trim().length() == 0) {
51+
problems += "TEST_PRIVATE_TOKEN cannot be empty\n";
52+
}
53+
54+
if (TEST_USERNAME == null || TEST_USERNAME.trim().length() == 0) {
55+
problems += "TEST_USER_NAME cannot be empty\n";
56+
}
57+
58+
if (problems.isEmpty()) {
59+
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
60+
} else {
61+
System.err.print(problems);
62+
}
63+
}
64+
65+
@Before
66+
public void beforeMethod() {
67+
assumeTrue(gitLabApi != null);
68+
}
69+
70+
@Test
71+
public void testGetVersion() throws GitLabApiException {
72+
Version version = gitLabApi.getVersion();
73+
assertNotNull(version);
74+
System.out.format("version=%s, revision=%s%n", version.getVersion(), version.getRevision());
75+
assertNotNull(version.getVersion());
76+
assertNotNull(version.getRevision());
77+
}
78+
79+
@Test
80+
public void testGetCurrentUser() throws GitLabApiException {
81+
User currentUser = gitLabApi.getUserApi().getCurrentUser();
82+
assertNotNull(currentUser);
83+
assertEquals(TEST_USERNAME, currentUser.getUsername());
84+
}
85+
}

0 commit comments

Comments
 (0)