Commit 6c3e3a3c authored by Greg Messner's avatar Greg Messner
Browse files

General cleanup.

parent 9f6022dc
...@@ -48,6 +48,7 @@ public class TestCommitsApi { ...@@ -48,6 +48,7 @@ public class TestCommitsApi {
} }
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static Project testProject;
public TestCommitsApi() { public TestCommitsApi() {
super(); super();
...@@ -75,6 +76,13 @@ public class TestCommitsApi { ...@@ -75,6 +76,13 @@ public class TestCommitsApi {
if (problems.isEmpty()) { if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
try {
testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
} catch (GitLabApiException gle) {
System.err.print(gle.getMessage());
}
} else { } else {
System.err.print(problems); System.err.print(problems);
} }
...@@ -88,14 +96,13 @@ public class TestCommitsApi { ...@@ -88,14 +96,13 @@ public class TestCommitsApi {
@Test @Test
public void testDiff() throws GitLabApiException { public void testDiff() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(testProject);
assertNotNull(project);
List<Commit> commits = gitLabApi.getCommitsApi().getCommits(project.getId()); List<Commit> commits = gitLabApi.getCommitsApi().getCommits(testProject.getId());
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
List<Diff> diffs = gitLabApi.getCommitsApi().getDiff(project.getId(), commits.get(0).getId()); List<Diff> diffs = gitLabApi.getCommitsApi().getDiff(testProject.getId(), commits.get(0).getId());
assertNotNull(diffs); assertNotNull(diffs);
assertTrue(diffs.size() > 0); assertTrue(diffs.size() > 0);
...@@ -107,19 +114,18 @@ public class TestCommitsApi { ...@@ -107,19 +114,18 @@ public class TestCommitsApi {
@Test @Test
public void testComments() throws GitLabApiException { public void testComments() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(testProject);
assertNotNull(project);
List<Commit> commits = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(0), new Date()); List<Commit> commits = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(0), new Date());
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
String note = "This is a note."; String note = "This is a note.";
Comment addedComment = gitLabApi.getCommitsApi().addComment(project.getId(), commits.get(0).getId(), note); Comment addedComment = gitLabApi.getCommitsApi().addComment(testProject.getId(), commits.get(0).getId(), note);
assertNotNull(addedComment); assertNotNull(addedComment);
assertEquals(note, addedComment.getNote()); assertEquals(note, addedComment.getNote());
List<Comment> comments = gitLabApi.getCommitsApi().getComments(project.getId(), commits.get(0).getId()); List<Comment> comments = gitLabApi.getCommitsApi().getComments(testProject.getId(), commits.get(0).getId());
assertNotNull(comments); assertNotNull(comments);
assertTrue(comments.size() > 0); assertTrue(comments.size() > 0);
} }
...@@ -127,26 +133,25 @@ public class TestCommitsApi { ...@@ -127,26 +133,25 @@ public class TestCommitsApi {
@Test @Test
public void testCommitsSince() throws GitLabApiException { public void testCommitsSince() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(testProject);
assertNotNull(project);
List<Commit> commits = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(), null); List<Commit> commits = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(), null);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.isEmpty()); assertTrue(commits.isEmpty());
commits = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(0), new Date()); commits = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(0), new Date());
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commits = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(0), new Date(), 1, 10); commits = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(0), new Date(), 1, 10);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(), null, 10); Pager<Commit> pager = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(), null, 10);
assertNotNull(pager); assertNotNull(pager);
assertTrue(pager.getTotalItems() == 0); assertTrue(pager.getTotalItems() == 0);
pager = gitLabApi.getCommitsApi().getCommits(project.getId(), null, new Date(0), null, 10); pager = gitLabApi.getCommitsApi().getCommits(testProject.getId(), null, new Date(0), null, 10);
assertNotNull(pager); assertNotNull(pager);
assertTrue(pager.getTotalItems() > 0); assertTrue(pager.getTotalItems() > 0);
} }
...@@ -154,34 +159,34 @@ public class TestCommitsApi { ...@@ -154,34 +159,34 @@ public class TestCommitsApi {
@Test @Test
public void testCommitsSinceWithPath() throws GitLabApiException { public void testCommitsSinceWithPath() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); assertNotNull(testProject);
assertNotNull(project);
List<Commit> commits = gitLabApi.getCommitsApi().getCommits( List<Commit> commits = gitLabApi.getCommitsApi().getCommits(
project.getId(), null, new Date(0), new Date(), TEST_PROJECT_SUBDIRECTORY_PATH); testProject.getId(), null, new Date(0), new Date(), TEST_PROJECT_SUBDIRECTORY_PATH);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
} }
@Test @Test
public void testCommitsByPath() throws GitLabApiException { public void testCommitsByPath() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(testProject);
CommitsApi commitsApi = gitLabApi.getCommitsApi(); CommitsApi commitsApi = gitLabApi.getCommitsApi();
List<Commit> commits = commitsApi.getCommits(project.getId(), "master", null); List<Commit> commits = commitsApi.getCommits(testProject.getId(), "master", null);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commits = commitsApi.getCommits(project.getId(), "master", "README"); commits = commitsApi.getCommits(testProject.getId(), "master", "README");
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commitsApi = gitLabApi.getCommitsApi(); commitsApi = gitLabApi.getCommitsApi();
commits = commitsApi.getCommits(project.getId(), "master", "README.md"); commits = commitsApi.getCommits(testProject.getId(), "master", "README.md");
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
commits = commitsApi.getCommits(project.getId(), "master", TEST_PROJECT_SUBDIRECTORY_PATH); commits = commitsApi.getCommits(testProject.getId(), "master", TEST_PROJECT_SUBDIRECTORY_PATH);
assertNotNull(commits); assertNotNull(commits);
assertTrue(commits.size() > 0); assertTrue(commits.size() > 0);
} }
......
...@@ -40,6 +40,8 @@ public class TestEventsApi { ...@@ -40,6 +40,8 @@ public class TestEventsApi {
} }
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static Project testProject;
private static User testUser;
public TestEventsApi() { public TestEventsApi() {
super(); super();
...@@ -67,6 +69,19 @@ public class TestEventsApi { ...@@ -67,6 +69,19 @@ public class TestEventsApi {
if (problems.isEmpty()) { if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
try {
testProject = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
} catch (GitLabApiException gle) {
System.err.print(gle.getMessage());
}
try {
testUser = gitLabApi.getUserApi().getCurrentUser();
} catch (GitLabApiException gle) {
System.err.print(gle.getMessage());
}
} else { } else {
System.err.print(problems); System.err.print(problems);
} }
...@@ -77,15 +92,15 @@ public class TestEventsApi { ...@@ -77,15 +92,15 @@ public class TestEventsApi {
assumeTrue(gitLabApi != null); assumeTrue(gitLabApi != null);
} }
@Test // This is commented out because it was causing a "Too Many Requests" error from gitlab.com, thus causing the tests to fail
public void testGetAuthenticatedUserEvents() throws GitLabApiException { // @Test
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null); // public void testGetAuthenticatedUserEvents() throws GitLabApiException {
assertNotNull(events); // List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null);
} // assertNotNull(events);
// }
@Test @Test
public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException { public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException {
Date after = new Date(0); Date after = new Date(0);
Date now = new Date(); Date now = new Date();
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, now, after, null); List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, now, after, null);
...@@ -98,21 +113,15 @@ public class TestEventsApi { ...@@ -98,21 +113,15 @@ public class TestEventsApi {
@Test @Test
public void testGetUserEvents() throws GitLabApiException { public void testGetUserEvents() throws GitLabApiException {
assertNotNull(testUser);
User user = gitLabApi.getUserApi().getCurrentUser(); List<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), null, null, null, null, null);
assertNotNull(user);
List<Event> events = gitLabApi.getEventsApi().getUserEvents(user.getId(), null, null, null, null, null);
assertNotNull(events); assertNotNull(events);
} }
@Test @Test
public void testGetProjectEvents() throws GitLabApiException { public void testGetProjectEvents() throws GitLabApiException {
assertNotNull(testProject);
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); List<Event> events = gitLabApi.getEventsApi().getProjectEvents(testProject.getId(), null, null, null, null, null);
assertNotNull(project);
List<Event> events = gitLabApi.getEventsApi().getProjectEvents(project.getId(), null, null, null, null, null);
assertNotNull(events); assertNotNull(events);
} }
...@@ -122,23 +131,18 @@ public class TestEventsApi { ...@@ -122,23 +131,18 @@ public class TestEventsApi {
assertNotNull(events); assertNotNull(events);
} }
@Test // This is commented out because it was causing a "Too Many Requests" error from gitlab.com, thus causing the tests to fail
public void testPagedGetUserEvents() throws GitLabApiException { // @Test
// public void testPagedGetUserEvents() throws GitLabApiException {
User user = gitLabApi.getUserApi().getCurrentUser(); // assertNotNull(testUser);
assertNotNull(user); // Pager<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), null, null, null, null, null, 10);
// assertNotNull(events);
Pager<Event> events = gitLabApi.getEventsApi().getUserEvents(user.getId(), null, null, null, null, null, 10); // }
assertNotNull(events);
}
@Test @Test
public void testPagedGetProjectEvents() throws GitLabApiException { public void testPagedGetProjectEvents() throws GitLabApiException {
assertNotNull(testProject);
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); Pager<Event> events = gitLabApi.getEventsApi().getProjectEvents(testProject.getId(), null, null, null, null, null, 10);
assertNotNull(project);
Pager<Event> events = gitLabApi.getEventsApi().getProjectEvents(project.getId(), null, null, null, null, null, 10);
assertNotNull(events); assertNotNull(events);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment