Skip to content

Commit

Permalink
Fix tests failed since ids migration from Integer to Long
Browse files Browse the repository at this point in the history
  • Loading branch information
jabby committed Mar 15, 2022
1 parent 09ed795 commit cf58df4
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 50 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/gitlab4j/api/AbstractApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public AbstractApi(GitLabApi gitLabApi) {
* Returns the project ID or path from the provided Integer, String, or Project instance.
*
* @param obj the object to determine the ID or path from
* @return the project ID or path from the provided Integer, String, or Project instance
* @return the project ID or path from the provided Long, String, or Project instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getProjectIdOrPath(Object obj) throws GitLabApiException {

if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Integer) {
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
Expand All @@ -60,22 +60,22 @@ public Object getProjectIdOrPath(Object obj) throws GitLabApiException {

} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a Project instance"));
" instance, must be Long, String, or a Project instance"));
}
}

/**
* Returns the group ID or path from the provided Integer, String, or Group instance.
*
* @param obj the object to determine the ID or path from
* @return the group ID or path from the provided Integer, String, or Group instance
* @return the group ID or path from the provided Long, String, or Group instance
* @throws GitLabApiException if any exception occurs during execution
*/
public Object getGroupIdOrPath(Object obj) throws GitLabApiException {

if (obj == null) {
throw (new RuntimeException("Cannot determine ID or path from null object"));
} else if (obj instanceof Integer) {
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
Expand All @@ -95,7 +95,7 @@ public Object getGroupIdOrPath(Object obj) throws GitLabApiException {

} else {
throw (new RuntimeException("Cannot determine ID or path from provided " + obj.getClass().getSimpleName() +
" instance, must be Integer, String, or a Group instance"));
" instance, must be Long, String, or a Group instance"));
}
}

Expand All @@ -110,7 +110,7 @@ public Object getUserIdOrUsername(Object obj) throws GitLabApiException {

if (obj == null) {
throw (new RuntimeException("Cannot determine ID or username from null object"));
} else if (obj instanceof Integer) {
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
Expand Down Expand Up @@ -145,7 +145,7 @@ public Object getLabelIdOrName(Object obj) throws GitLabApiException {

if (obj == null) {
throw (new RuntimeException("Cannot determine ID or name from null object"));
} else if (obj instanceof Integer) {
} else if (obj instanceof Long) {
return (obj);
} else if (obj instanceof String) {
return (urlEncode(((String) obj).trim()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/gitlab4j/api/GroupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ public Group updateGroup(Object groupIdOrPath, String name, String path, String
* @return the created Group instance
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 5.0, replaced by {@link #addGroup(String, String, String, Visibility,
* Boolean, Boolean, Integer)}
* Boolean, Boolean, Long)}
*/
@Deprecated
public Group addGroup(String name, String path, String description, Boolean membershipLock,
Expand Down Expand Up @@ -683,7 +683,7 @@ public Group addGroup(String name, String path, String description, Boolean memb
* @return the updated Group instance
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 5.0, replaced by {@link #updateGroup(Object, String, String, String,
* Visibility, Boolean, Boolean, Integer)}
* Visibility, Boolean, Boolean, Long)}
*/
@Deprecated
public Group updateGroup(Object groupIdOrPath, String name, String path, String description, Boolean membershipLock,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/gitlab4j/api/JobApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Stream<Job> getJobsStream(Object projectIdOrPath, JobScope scope) throws
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Job> getJobsForPipeline(Object projectIdOrPath, int pipelineId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "jobs");
return (response.readEntity(new GenericType<List<Job>>() {}));
}
Expand Down Expand Up @@ -466,7 +466,7 @@ public String getTrace(Object projectIdOrPath, Long jobId) throws GitLabApiExcep
* @param jobId the ID to cancel job
* @return job instance which just canceled
* @throws GitLabApiException if any exception occurs during execution
* @deprecated replaced by {@link #cancelJob(Object, Integer)}
* @deprecated replaced by {@link #cancelJob(Object, Long)}
*/
@Deprecated
public Job cancleJob(Object projectIdOrPath, Long jobId) throws GitLabApiException {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/gitlab4j/api/NotesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public NotesApi(GitLabApi gitLabApi) {
* @param issueIid the issue ID to get the notes for
* @return a list of the issues's notes
* @throws GitLabApiException if any exception occurs
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer)}
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Long)}
*/
@Deprecated
public List<Note> getNotes(Object projectIdOrPath, Long issueIid) throws GitLabApiException {
Expand All @@ -42,7 +42,7 @@ public List<Note> getNotes(Object projectIdOrPath, Long issueIid) throws GitLabA
* @param perPage the number of notes per page
* @return the list of notes in the specified range
* @throws GitLabApiException if any exception occurs
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer, int, int)}
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Long, int, int)}
*/
@Deprecated
public List<Note> getNotes(Object projectIdOrPath, Long issueIid, int page, int perPage) throws GitLabApiException {
Expand All @@ -59,7 +59,7 @@ public List<Note> getNotes(Object projectIdOrPath, Long issueIid, int page, int
* @param itemsPerPage the number of notes per page
* @return the list of notes in the specified range
* @throws GitLabApiException if any exception occurs
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer, int)}
* @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Long, int)}
*/
@Deprecated
public Pager<Note> getNotes(Object projectIdOrPath, Long issueIid, int itemsPerPage) throws GitLabApiException {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ public Project createProject(String name, Long namespaceId, String description,
* @param importUrl The Import URL for the project, otherwise null
* @return the GitLab Project
* @throws GitLabApiException if any exception occurs
* @deprecated As of release 4.2.0, replaced by {@link #createProject(String, Integer, String, Boolean, Boolean,
* @deprecated As of release 4.2.0, replaced by {@link #createProject(String, Long, String, Boolean, Boolean,
* Boolean, Boolean, Visibility, Integer, String)}
*/
@Deprecated
Expand Down Expand Up @@ -2268,7 +2268,7 @@ public Stream<Issue> getIssuesStream(Object projectIdOrPath) throws GitLabApiExc
* @param issueId the internal ID of a project's issue
* @return the specified Issue instance
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Object, Integer)}
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Object, Long)}
*/
@Deprecated
public Issue getIssue(Object projectIdOrPath, Long issueId) throws GitLabApiException {
Expand All @@ -2284,7 +2284,7 @@ public Issue getIssue(Object projectIdOrPath, Long issueId) throws GitLabApiExce
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @param issueId the internal ID of a project's issue
* @throws GitLabApiException if any exception occurs
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Object, Integer)}
* @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Object, Long)}
*/
@Deprecated
public void deleteIssue(Object projectIdOrPath, Long issueId) throws GitLabApiException {
Expand Down Expand Up @@ -2605,6 +2605,8 @@ public FileUpload uploadFile(Object projectIdOrPath, File fileToUpload, String m
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param inputStream the data to upload, required
* @param filename The filename of the file to upload
* @param mediaType unused; will be removed in the next major version
* @return a FileUpload instance with information on the just uploaded file
* @throws GitLabApiException if any exception occurs
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gitlab4j/api/RunnersApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public Runner enableRunner(Object projectIdOrPath, Long runnerId) throws GitLabA

/**
* Disable a specific runner from the project. It works only if the project isn't the only project associated with
* the specified runner. If so, an error is returned. Use the {@link #removeRunner(Integer)} instead.
* the specified runner. If so, an error is returned. Use the {@link #removeRunner(Long)} instead.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/runners/:runner_id</code></pre>
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/gitlab4j/api/models/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.node.ValueNode;
Expand Down Expand Up @@ -145,7 +146,7 @@ public void setActualId(ValueNode id) {
actualId = id;
if (actualId instanceof TextNode) {
externalId = actualId.asText();
} else if (actualId instanceof LongNode) {
} else if (actualId instanceof IntNode || actualId instanceof LongNode) {
this.id = actualId.asLong();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/gitlab4j/api/TestCommitDiscussionsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ public void setUp() throws Exception {

@Test
public void testGetCommitDiscussionsByList() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussions(1, COMMIT_SHA);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussions(1L, COMMIT_SHA);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "commit-discussions.json"));
}

@Test
public void testGetCommitDiscussionsByListWithMaxItems() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussions(1, COMMIT_SHA, 20);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussions(1L, COMMIT_SHA, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "commit-discussions.json"));
}

@Test
public void testGetCommitDiscussionsByPager() throws Exception {
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussionsPager(1, COMMIT_SHA, 20);
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getCommitDiscussionsPager(1L, COMMIT_SHA, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions.all(), "commit-discussions.json"));
}

@Test
public void testGetCommitDiscussionsByStream() throws Exception {
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getCommitDiscussionsStream(1, COMMIT_SHA);
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getCommitDiscussionsStream(1L, COMMIT_SHA);
assertNotNull(stream);
List<Discussion> discussions = stream.collect(Collectors.toList());
assertTrue(compareJson(discussions, "commit-discussions.json"));
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/gitlab4j/api/TestEpicDiscussionsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ public void setUp() throws Exception {

@Test
public void testGetEpicDiscussionsByList() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussions(1, 1L);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussions(1L, 1L);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "epic-discussions.json"));
}

@Test
public void testGetEpicDiscussionsByListWithMaxItems() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussions(1, 1L, 20);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussions(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "epic-discussions.json"));
}

@Test
public void testGetEpicDiscussionsByPager() throws Exception {
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussionsPager(1, 1L, 20);
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getEpicDiscussionsPager(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions.all(), "epic-discussions.json"));
}

@Test
public void testGetEpicDiscussionsByStream() throws Exception {
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getEpicDiscussionsStream(1, 1L);
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getEpicDiscussionsStream(1L, 1L);
assertNotNull(stream);
List<Discussion> discussions = stream.collect(Collectors.toList());
assertTrue(compareJson(discussions, "epic-discussions.json"));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/gitlab4j/api/TestGitLabApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

/**
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
*
*
* TEST_NAMESPACE
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category(IntegrationTest.class)
Expand Down Expand Up @@ -76,7 +76,7 @@ public void beforeMethod() {
public void testNotFoundError() throws GitLabApiException {

try {
gitLabApi.getProjectApi().getProject(123456789);
gitLabApi.getProjectApi().getProject(123456789L);
fail("GitLabApiException not thrown");
} catch (GitLabApiException gae) {
assertFalse(gae.hasValidationErrors());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/gitlab4j/api/TestGroupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void getOptionalGroup() {
assertTrue(optional.isPresent());
assertEquals(testGroup.getId(), optional.get().getId());

optional = gitLabApi.getGroupApi().getOptionalGroup(12345);
optional = gitLabApi.getGroupApi().getOptionalGroup(12345L);
assertNotNull(optional);
assertFalse(optional.isPresent());
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), GitLabApi.getOptionalException(optional).getHttpStatus());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/gitlab4j/api/TestIssueDiscussionsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ public void setUp() throws Exception {

@Test
public void testGetIssueDiscussionsByList() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussions(1, 1L);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussions(1L, 1L);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "issue-discussions.json"));
}

@Test
public void testGetIssueDiscussionsByListWithMaxItems() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussions(1, 1L, 20);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussions(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "issue-discussions.json"));
}

@Test
public void testGetIssueDiscussionsByPager() throws Exception {
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussionsPager(1, 1L, 20);
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getIssueDiscussionsPager(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions.all(), "issue-discussions.json"));
}

@Test
public void testGetIssueDiscussionsByStream() throws Exception {
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getIssueDiscussionsStream(1, 1L);
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getIssueDiscussionsStream(1L, 1L);
assertNotNull(stream);
List<Discussion> discussions = stream.collect(Collectors.toList());
assertTrue(compareJson(discussions, "issue-discussions.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ public void setUp() throws Exception {

@Test
public void testGetMergeRequestDiscussionsByList() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussions(1, 1L);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussions(1L, 1L);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "merge-request-discussions.json"));
}

@Test
public void testGetMergeRequestDiscussionsByListMaxItems() throws Exception {
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussions(1, 1L, 20);
List<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussions(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions, "merge-request-discussions.json"));
}

@Test
public void testGetMergeRequestDiscussionsByPager() throws Exception {
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussionsPager(1, 1L, 20);
Pager<Discussion> discussions = new DiscussionsApi(gitLabApi).getMergeRequestDiscussionsPager(1L, 1L, 20);
assertNotNull(discussions);
assertTrue(compareJson(discussions.all(), "merge-request-discussions.json"));
}

@Test
public void testGetMergeRequestDiscussionsByStream() throws Exception {
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getMergeRequestDiscussionsStream(1, 1L);
Stream<Discussion> stream = new DiscussionsApi(gitLabApi).getMergeRequestDiscussionsStream(1L, 1L);
assertNotNull(stream);
List<Discussion> discussions = stream.collect(Collectors.toList());
assertTrue(compareJson(discussions, "merge-request-discussions.json"));
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/gitlab4j/api/TestPackageApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public void getPackagesStream() throws GitLabApiException {
.withOrderBy(Constants.PackageOrderBy.CREATED_AT)
.withSortOder(Constants.SortOrder.DESC);



Optional<Package> lastPackage = packagesApi.getPackagesStream(testProject.getId(),filter).findAny();

assertTrue(lastPackage.isPresent());
Expand Down
Loading

0 comments on commit cf58df4

Please sign in to comment.