-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UserApi Development Initialized #189
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/cdancy/bitbucket/rest/features/UserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.cdancy.bitbucket.rest.features; | ||
|
||
import com.cdancy.bitbucket.rest.annotations.Documentation; | ||
import com.cdancy.bitbucket.rest.domain.admin.UserPage; | ||
import com.cdancy.bitbucket.rest.fallbacks.BitbucketFallbacks; | ||
import com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter; | ||
import org.jclouds.javax.annotation.Nullable; | ||
import org.jclouds.rest.annotations.Fallback; | ||
import org.jclouds.rest.annotations.RequestFilters; | ||
|
||
import javax.inject.Named; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@RequestFilters(BitbucketAuthenticationFilter.class) | ||
@Path("/rest/api/{jclouds.api-version}/users") | ||
@SuppressWarnings("PMD.AvoidDuplicateLiterals") | ||
public interface UserApi { | ||
|
||
@Named("user:get-user") | ||
@Documentation({"https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp362"}) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Path("") | ||
@Fallback(BitbucketFallbacks.UserPageOnError.class) | ||
@GET | ||
UserPage users(@Nullable @QueryParam("filter") String filter, | ||
@Nullable @QueryParam("group") String group, | ||
@Nullable @QueryParam("permission") String globalRole, | ||
@Nullable @QueryParam("permission.1") String projectRole, | ||
@Nullable @QueryParam("permission.1.projectKey") String projProjectKey, | ||
@Nullable @QueryParam("permission.1.projectId") String projProjectId, | ||
@Nullable @QueryParam("permission.2") String repoRole, | ||
@Nullable @QueryParam("permission.2.projectKey") String repoProjectKey, | ||
@Nullable @QueryParam("permission.3.projectId") String repoPrrojectId, | ||
@Nullable @QueryParam("start") Integer start, | ||
@Nullable @QueryParam("limit") Integer limit); | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/cdancy/bitbucket/rest/features/UserApiLiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.cdancy.bitbucket.rest.features; | ||
|
||
import com.cdancy.bitbucket.rest.BaseBitbucketApiLiveTest; | ||
import com.cdancy.bitbucket.rest.TestUtilities; | ||
import com.cdancy.bitbucket.rest.domain.admin.UserPage; | ||
import com.cdancy.bitbucket.rest.domain.pullrequest.User; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Test(groups = "live", testName = "UserApiLiveTest", singleThreaded = true) | ||
public class UserApiLiveTest extends BaseBitbucketApiLiveTest { | ||
|
||
@Test | ||
public void testListUsers() { | ||
final User user = TestUtilities.getDefaultUser(this.bitbucketAuthentication, this.api); | ||
final UserPage userPage = api().users(user.slug(), defaultBitbucketGroup, null, null, | ||
null, null, null, null, null, null, null);//Further testing required | ||
assertThat(userPage).isNotNull(); | ||
assertThat(userPage.size() > 0).isTrue(); | ||
} | ||
|
||
public void testListUsersOnError() { | ||
final UserPage userPage = api().users(TestUtilities.randomString(), TestUtilities.randomString(), null, | ||
null, null, null, null, null, null, null, null); | ||
assertThat(userPage).isNotNull(); | ||
assertThat(userPage.size() == 0).isTrue(); | ||
} | ||
|
||
private UserApi api() { | ||
return api.userApi(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/test/java/com/cdancy/bitbucket/rest/features/UserApiMockTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.cdancy.bitbucket.rest.features; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Map; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import com.cdancy.bitbucket.rest.BaseBitbucketMockTest; | ||
import com.cdancy.bitbucket.rest.BitbucketApi; | ||
import com.cdancy.bitbucket.rest.BitbucketApiMetadata; | ||
import com.cdancy.bitbucket.rest.domain.admin.UserPage; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.squareup.okhttp.mockwebserver.MockResponse; | ||
import com.squareup.okhttp.mockwebserver.MockWebServer; | ||
|
||
@Test(groups = "unit", testName = "UserApiMockTest") | ||
public class UserApiMockTest extends BaseBitbucketMockTest { | ||
|
||
private final String restApiPath = "/rest/api/"; | ||
private final String getMethod = "GET"; | ||
private final String admin = "ADMIN"; | ||
private final String group = "stash-users"; | ||
|
||
|
||
public void testUserListUsers() throws Exception { | ||
|
||
|
||
final MockWebServer server = mockWebServer(); | ||
|
||
server.enqueue(new MockResponse() | ||
.setBody(payloadFromResource("/user-list-users.json")) | ||
.setResponseCode(200)); | ||
try (final BitbucketApi baseApi = api(server.getUrl("/"))) { | ||
|
||
final UserPage up = baseApi.userApi().users("jcitizen", group, admin, null, | ||
null, null, null, null, null, 0, 2); | ||
assertThat(up).isNotNull(); | ||
assertThat(up.errors()).isEmpty(); | ||
assertThat(up.size() == 1).isTrue(); | ||
assertThat(up.values().get(0).slug().equals("jcitizen")).isTrue(); | ||
|
||
final Map<String, ?> queryParams = ImmutableMap.of("filter", "jcitizen", | ||
"group", group, "permission", admin,"start",0,"limit",2); | ||
assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION | ||
+ "/users", queryParams); | ||
} finally { | ||
server.shutdown(); | ||
} | ||
} | ||
|
||
public void testUserListUsersOnError() throws Exception { | ||
final MockWebServer server = mockWebServer(); | ||
|
||
server.enqueue(new MockResponse().setBody(payloadFromResource("/user-list-users-error.json")).setResponseCode(401)); | ||
final BitbucketApi baseApi = api(server.getUrl("/")); | ||
try { | ||
final UserPage up = baseApi.userApi().users("blah blah", group, admin, null, | ||
null, null, null, null, null, 0, 2); | ||
assertThat(up).isNotNull(); | ||
assertThat(up.errors()).isNotEmpty(); | ||
|
||
final Map<String, ?> queryParams = ImmutableMap.of("filter", "blah%20blah", | ||
"group", group, "permission", admin,"start",0,"limit",2); | ||
assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION | ||
+ "/users", queryParams); | ||
} finally { | ||
baseApi.close(); | ||
server.shutdown(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"context": null, | ||
"message": "Authentication failed. Please check your credentials and try again.", | ||
"exceptionName": "com.atlassian.bitbucket.auth.IncorrectPasswordAuthenticationException" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
{ | ||
"size": 1, | ||
"limit": 25, | ||
"isLastPage": true, | ||
"values": [ | ||
{ | ||
"name": "jcitizen", | ||
"emailAddress": "[email protected]", | ||
"id": 101, | ||
"displayName": "Jane Citizen", | ||
"active": true, | ||
"slug": "jcitizen", | ||
"type": "NORMAL", | ||
"links": { | ||
"self": [ | ||
{ | ||
"href": "https://bitbucket.acme.com/users/jcitizen" | ||
} | ||
] | ||
} | ||
} | ||
|
||
], | ||
"start": 0 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we could have N number of these which is going to make this a bit unruly and also limit folks if we only specify 3. We'll probably have to create an optional Binder which will take in a list of of these "permission objects" which we will then have to inject the values as query-params. Take a look HERE and poke around the code base to see how we do this type of thing elsewhere. Let me know if you have any questions. Looks good so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I misunderstood the documentation I thought permission was for global 1 was for project permissions and 2 for repo etc.. I didn't recognize they were the same thing but different filters.
I looked into what you told me, isn't that a way to bind some data to the payload? which is as much as I know should not be used with GET requests as their body is not processed? Please correct me if I misunderstood anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore the class name ... you can alter the request in general and append new query params/etc. Take a look at the below code where we do something like this:
https://github.com/cdancy/jenkins-rest/blob/master/src/main/java/com/cdancy/jenkins/rest/filters/ScrubNullFolderParam.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry I have to postpone it to the next Friday, as am having my midterm exams this week and I got a lot of studying to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajammil of course and take your time.