Skip to content

Commit c23a7e5

Browse files
committed
Merge branch '669-get-user'
2 parents 971e9a7 + ebef328 commit c23a7e5

File tree

10 files changed

+201
-5
lines changed

10 files changed

+201
-5
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v2/users/ReactorUsers.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.cloudfoundry.client.v2.users.CreateUserResponse;
2121
import org.cloudfoundry.client.v2.users.DeleteUserRequest;
2222
import org.cloudfoundry.client.v2.users.DeleteUserResponse;
23+
import org.cloudfoundry.client.v2.users.GetUserRequest;
24+
import org.cloudfoundry.client.v2.users.GetUserResponse;
2325
import org.cloudfoundry.client.v2.users.ListUsersRequest;
2426
import org.cloudfoundry.client.v2.users.ListUsersResponse;
2527
import org.cloudfoundry.client.v2.users.SummaryUserRequest;
@@ -60,6 +62,12 @@ public Mono<DeleteUserResponse> delete(DeleteUserRequest request) {
6062
.checkpoint();
6163
}
6264

65+
@Override
66+
public Mono<GetUserResponse> get(GetUserRequest request) {
67+
return get(request, GetUserResponse.class, builder -> builder.pathSegment("v2", "users", request.getUserId()))
68+
.checkpoint();
69+
}
70+
6371
@Override
6472
public Mono<ListUsersResponse> list(ListUsersRequest request) {
6573
return get(request, ListUsersResponse.class, builder -> builder.pathSegment("v2", "users"))

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v2/users/ReactorUsersTest.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.cloudfoundry.client.v2.users.CreateUserRequest;
2323
import org.cloudfoundry.client.v2.users.CreateUserResponse;
2424
import org.cloudfoundry.client.v2.users.DeleteUserRequest;
25+
import org.cloudfoundry.client.v2.users.GetUserRequest;
26+
import org.cloudfoundry.client.v2.users.GetUserResponse;
2527
import org.cloudfoundry.client.v2.users.ListUsersRequest;
2628
import org.cloudfoundry.client.v2.users.ListUsersResponse;
2729
import org.cloudfoundry.client.v2.users.SummaryUserRequest;
@@ -117,6 +119,48 @@ public void delete() {
117119
.verify(Duration.ofSeconds(5));
118120
}
119121

122+
@Test
123+
public void get() {
124+
mockRequest(InteractionContext.builder()
125+
.request(TestRequest.builder()
126+
.method(GET).path("/v2/users/uaa-id-317")
127+
.build())
128+
.response(TestResponse.builder()
129+
.status(OK)
130+
.payload("fixtures/client/v2/users/GET_{id}_response.json")
131+
.build())
132+
.build());
133+
134+
this.users
135+
.get(GetUserRequest.builder()
136+
.userId("uaa-id-317")
137+
.build())
138+
.as(StepVerifier::create)
139+
.expectNext(GetUserResponse.builder()
140+
.metadata(Metadata.builder()
141+
.createdAt("2016-06-08T16:41:37Z")
142+
.id("uaa-id-317")
143+
.updatedAt("2016-06-08T16:41:26Z")
144+
.url("/v2/users/uaa-id-317")
145+
.build())
146+
.entity(UserEntity.builder()
147+
.active(false)
148+
.admin(false)
149+
.auditedOrganizationsUrl("/v2/users/uaa-id-317/audited_organizations")
150+
.auditedSpacesUrl("/v2/users/uaa-id-317/audited_spaces")
151+
.billingManagedOrganizationsUrl("/v2/users/uaa-id-317/billing_managed_organizations")
152+
.defaultSpaceUrl("/v2/spaces/fc898723-2192-42d9-9567-c0b2e03a3169")
153+
.defaultSpaceId("fc898723-2192-42d9-9567-c0b2e03a3169")
154+
.managedOrganizationsUrl("/v2/users/uaa-id-317/managed_organizations")
155+
.managedSpacesUrl("/v2/users/uaa-id-317/managed_spaces")
156+
.organizationsUrl("/v2/users/uaa-id-317/organizations")
157+
.spacesUrl("/v2/users/uaa-id-317/spaces")
158+
.build())
159+
.build())
160+
.expectComplete()
161+
.verify(Duration.ofSeconds(5));
162+
}
163+
120164
@Test
121165
public void list() {
122166
mockRequest(InteractionContext.builder()
@@ -139,9 +183,9 @@ public void list() {
139183
.totalPages(1)
140184
.resource(UserResource.builder()
141185
.metadata(Metadata.builder()
186+
.createdAt("2015-12-22T18:28:01Z")
142187
.id("uaa-id-133")
143188
.url("/v2/users/uaa-id-133")
144-
.createdAt("2015-12-22T18:28:01Z")
145189
.build())
146190
.entity(UserEntity.builder()
147191
.active(false)
@@ -160,9 +204,9 @@ public void list() {
160204
.build())
161205
.resource(UserResource.builder()
162206
.metadata(Metadata.builder()
207+
.createdAt("2015-12-22T18:28:01Z")
163208
.id("uaa-id-134")
164209
.url("/v2/users/uaa-id-134")
165-
.createdAt("2015-12-22T18:28:01Z")
166210
.build())
167211
.entity(UserEntity.builder()
168212
.active(true)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"metadata": {
3+
"guid": "uaa-id-317",
4+
"url": "/v2/users/uaa-id-317",
5+
"created_at": "2016-06-08T16:41:37Z",
6+
"updated_at": "2016-06-08T16:41:26Z"
7+
},
8+
"entity": {
9+
"admin": false,
10+
"active": false,
11+
"default_space_guid": "fc898723-2192-42d9-9567-c0b2e03a3169",
12+
"default_space_url": "/v2/spaces/fc898723-2192-42d9-9567-c0b2e03a3169",
13+
"spaces_url": "/v2/users/uaa-id-317/spaces",
14+
"organizations_url": "/v2/users/uaa-id-317/organizations",
15+
"managed_organizations_url": "/v2/users/uaa-id-317/managed_organizations",
16+
"billing_managed_organizations_url": "/v2/users/uaa-id-317/billing_managed_organizations",
17+
"audited_organizations_url": "/v2/users/uaa-id-317/audited_organizations",
18+
"managed_spaces_url": "/v2/users/uaa-id-317/managed_spaces",
19+
"audited_spaces_url": "/v2/users/uaa-id-317/audited_spaces"
20+
}
21+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v2/users/Users.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public interface Users {
3636
*/
3737
Mono<DeleteUserResponse> delete(DeleteUserRequest request);
3838

39+
/**
40+
* Makes the <a href="http://apidocs.cloudfoundry.org/latest-release/users/retrieve_a_particular_user.html">Retrieve a Particular User</a> request
41+
*
42+
* @param request the Retrieve a Particular User request
43+
* @return the response from the Retrieve a Particular User request
44+
*/
45+
Mono<GetUserResponse> get(GetUserRequest request);
46+
3947
/**
4048
* Makes the <a href="http://apidocs.cloudfoundry.org/latest-release/users/list_all_users.html">List all Users</a> request
4149
*
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v2.users;
18+
19+
import com.fasterxml.jackson.annotation.JsonIgnore;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The request payload for the Get User operation
24+
*/
25+
@Value.Immutable
26+
abstract class _GetUserRequest {
27+
28+
/**
29+
* The user id
30+
*/
31+
@JsonIgnore
32+
abstract String getUserId();
33+
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v2.users;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The response payload for the Get User operation
24+
*/
25+
@JsonDeserialize
26+
@Value.Immutable
27+
abstract class _GetUserResponse extends AbstractUserResource {
28+
29+
}

cloudfoundry-client/src/test/java/org/cloudfoundry/client/v2/users/CreateUserRequestTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ public void valid() {
3434
.uaaId("test-uaa-id")
3535
.build();
3636
}
37+
3738
}

cloudfoundry-client/src/test/java/org/cloudfoundry/client/v2/users/DeleteUserRequestTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public void valid() {
3333
.userId("test-user-id")
3434
.build();
3535
}
36+
3637
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2013-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v2.users;
18+
19+
import org.junit.Test;
20+
21+
public final class GetUserRequestTest {
22+
23+
@Test(expected = IllegalStateException.class)
24+
public void noUserId() {
25+
GetUserRequest.builder()
26+
.build();
27+
}
28+
29+
@Test
30+
public void valid() {
31+
GetUserRequest.builder()
32+
.userId("test-user-id")
33+
.build();
34+
}
35+
36+
}

integration-test/src/test/java/org/cloudfoundry/client/v2/UsersTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.cloudfoundry.client.v2.users.CreateUserRequest;
2424
import org.cloudfoundry.client.v2.users.CreateUserResponse;
2525
import org.cloudfoundry.client.v2.users.DeleteUserRequest;
26+
import org.cloudfoundry.client.v2.users.GetUserRequest;
2627
import org.cloudfoundry.client.v2.users.ListUsersRequest;
2728
import org.cloudfoundry.client.v2.users.SummaryUserRequest;
2829
import org.cloudfoundry.client.v2.users.UpdateUserRequest;
@@ -36,6 +37,7 @@
3637
import reactor.core.publisher.Flux;
3738
import reactor.core.publisher.Mono;
3839
import reactor.test.StepVerifier;
40+
import reactor.util.function.Tuples;
3941

4042
import java.time.Duration;
4143
import java.util.concurrent.TimeoutException;
@@ -158,11 +160,23 @@ public void deleteNoAsync() throws TimeoutException, InterruptedException {
158160
.verify(Duration.ofMinutes(5));
159161
}
160162

161-
//TODO: Await https://github.com/cloudfoundry/cf-java-client/issues/669
162-
@Ignore("Await https://github.com/cloudfoundry/cf-java-client/issues/669")
163163
@Test
164164
public void get() throws TimeoutException, InterruptedException {
165-
//
165+
String spaceName = this.nameFactory.getSpaceName();
166+
String userId = this.nameFactory.getUserId();
167+
168+
this.organizationId
169+
.then(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName))
170+
.then(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId)
171+
.then(this.cloudFoundryClient.users()
172+
.get(GetUserRequest.builder()
173+
.userId(userId)
174+
.build())
175+
.map(response -> Tuples.of(spaceId, response.getEntity().getDefaultSpaceId()))))
176+
.as(StepVerifier::create)
177+
.consumeNextWith(tupleEquality())
178+
.expectComplete()
179+
.verify(Duration.ofMinutes(5));
166180
}
167181

168182
@Test

0 commit comments

Comments
 (0)