Skip to content

Commit 327e239

Browse files
damzogJochen Damzog
authored andcommitted
Adding user resource for v3
1 parent 59c0640 commit 327e239

File tree

22 files changed

+1001
-0
lines changed

22 files changed

+1001
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2013-2021 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.reactor.client.v3.users;
18+
19+
import org.cloudfoundry.client.v3.users.*;
20+
import org.cloudfoundry.reactor.ConnectionContext;
21+
import org.cloudfoundry.reactor.TokenProvider;
22+
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
23+
import reactor.core.publisher.Mono;
24+
25+
import java.util.Map;
26+
27+
/**
28+
* The Reactor-based implementation of {@link UsersV3}
29+
*/
30+
public class ReactorUsersV3 extends AbstractClientV3Operations implements UsersV3 {
31+
32+
/**
33+
* Creates an instance
34+
*
35+
* @param connectionContext the {@link ConnectionContext} to use when communicating with the server
36+
* @param root the root URI of the server. Typically, something like {@code https://api.cloudfoundry.your.company.com}.
37+
* @param tokenProvider the {@link TokenProvider} to use when communicating with the server
38+
* @param requestTags map with custom http headers which will be added to web request
39+
*/
40+
public ReactorUsersV3(
41+
ConnectionContext connectionContext,
42+
Mono<String> root,
43+
TokenProvider tokenProvider,
44+
Map<String, String> requestTags) {
45+
super(connectionContext, root, tokenProvider, requestTags);
46+
}
47+
48+
@Override
49+
public Mono<CreateUserResponse> create(CreateUserRequest request) {
50+
return post(
51+
request,
52+
CreateUserResponse.class,
53+
builder -> builder.pathSegment("users"))
54+
.checkpoint();
55+
}
56+
57+
@Override
58+
public Mono<GetUserResponse> get(GetUserRequest request) {
59+
return get(
60+
request,
61+
GetUserResponse.class,
62+
builder -> builder.pathSegment("users", request.getUserId()))
63+
.checkpoint();
64+
}
65+
66+
@Override
67+
public Mono<UpdateUserResponse> update(UpdateUserRequest request) {
68+
return patch(
69+
request,
70+
UpdateUserResponse.class,
71+
builder -> builder.pathSegment("users", request.getUserId()))
72+
.checkpoint();
73+
}
74+
75+
@Override
76+
public Mono<Void> delete(DeleteUserRequest request) {
77+
return delete(
78+
request,
79+
Void.class,
80+
builder -> builder.pathSegment("users", request.getUserId()))
81+
.checkpoint();
82+
}
83+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*
2+
* Copyright 2013-2021 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+
package org.cloudfoundry.reactor.client.v3.users;
17+
18+
import org.cloudfoundry.client.v3.Link;
19+
import org.cloudfoundry.client.v3.Metadata;
20+
import org.cloudfoundry.client.v3.users.*;
21+
import org.cloudfoundry.reactor.InteractionContext;
22+
import org.cloudfoundry.reactor.TestRequest;
23+
import org.cloudfoundry.reactor.TestResponse;
24+
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
25+
import org.junit.jupiter.api.Test;
26+
import reactor.test.StepVerifier;
27+
28+
import java.time.Duration;
29+
import java.util.Collections;
30+
import java.util.Map;
31+
32+
import static io.netty.handler.codec.http.HttpMethod.*;
33+
import static io.netty.handler.codec.http.HttpResponseStatus.*;
34+
35+
final class ReactorUsersTest extends AbstractClientApiTest {
36+
private final ReactorUsersV3 users =
37+
new ReactorUsersV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap());
38+
39+
@Test
40+
void create() {
41+
mockRequest(
42+
InteractionContext.builder()
43+
.request(
44+
TestRequest.builder()
45+
.method(POST)
46+
.path("/users")
47+
.payload(
48+
"fixtures/client/v3/users/POST_request.json")
49+
.build())
50+
.response(
51+
TestResponse.builder()
52+
.status(CREATED)
53+
.payload(
54+
"fixtures/client/v3/users/POST_response.json")
55+
.build())
56+
.build());
57+
58+
this.users
59+
.create(CreateUserRequest.builder()
60+
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
61+
.build()
62+
)
63+
.as(StepVerifier::create)
64+
.expectNext(
65+
CreateUserResponse.builder()
66+
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
67+
.createdAt("2019-03-08T01:06:19Z")
68+
.updatedAt("2019-03-08T01:06:19Z")
69+
.username("some-name")
70+
.presentationName("some-name")
71+
.origin("uaa")
72+
.metadata(
73+
Metadata.builder()
74+
.putAllAnnotations(Collections.emptyMap())
75+
.putAllLabels(Collections.emptyMap())
76+
.build())
77+
.link(
78+
"self",
79+
Link.builder()
80+
.href(
81+
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
82+
.build())
83+
.build()
84+
)
85+
.expectComplete()
86+
.verify(Duration.ofSeconds(5));
87+
}
88+
89+
@Test
90+
void get() {
91+
mockRequest(
92+
InteractionContext.builder()
93+
.request(
94+
TestRequest.builder()
95+
.method(GET)
96+
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
97+
.build())
98+
.response(
99+
TestResponse.builder()
100+
.status(OK)
101+
.payload(
102+
"fixtures/client/v3/users/GET_{id}_response.json")
103+
.build())
104+
.build());
105+
106+
this.users
107+
.get(GetUserRequest.builder()
108+
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
109+
.build()
110+
)
111+
.as(StepVerifier::create)
112+
.expectNext(
113+
GetUserResponse.builder()
114+
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
115+
.createdAt("2019-03-08T01:06:19Z")
116+
.updatedAt("2019-03-08T01:06:19Z")
117+
.username("some-name")
118+
.presentationName("some-name")
119+
.origin("uaa")
120+
.metadata(
121+
Metadata.builder()
122+
.putAllAnnotations(Collections.emptyMap())
123+
.putAllLabels(Collections.emptyMap())
124+
.build())
125+
.link(
126+
"self",
127+
Link.builder()
128+
.href(
129+
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
130+
.build())
131+
.build()
132+
)
133+
.expectComplete()
134+
.verify(Duration.ofSeconds(5));
135+
}
136+
137+
@Test
138+
void update() {
139+
mockRequest(
140+
InteractionContext.builder()
141+
.request(
142+
TestRequest.builder()
143+
.method(PATCH)
144+
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
145+
.payload(
146+
"fixtures/client/v3/users/PATCH_{id}_request.json")
147+
.build())
148+
.response(
149+
TestResponse.builder()
150+
.status(CREATED)
151+
.payload(
152+
"fixtures/client/v3/users/PATCH_{id}_response.json")
153+
.build())
154+
.build());
155+
156+
this.users
157+
.update(UpdateUserRequest.builder()
158+
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
159+
.metadata(Metadata.builder()
160+
.putAllAnnotations(Map.of("note", "detailed information"))
161+
.putAllLabels(Map.of("environment", "production"))
162+
.build())
163+
.build()
164+
)
165+
.as(StepVerifier::create)
166+
.expectNext(
167+
UpdateUserResponse.builder()
168+
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
169+
.createdAt("2019-03-08T01:06:19Z")
170+
.updatedAt("2019-03-08T01:06:19Z")
171+
.username("some-name")
172+
.presentationName("some-name")
173+
.origin("uaa")
174+
.metadata(Metadata.builder()
175+
.putAllAnnotations(Map.of("note", "detailed information"))
176+
.putAllLabels(Map.of("environment", "production"))
177+
.build())
178+
.link(
179+
"self",
180+
Link.builder()
181+
.href(
182+
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
183+
.build())
184+
.build()
185+
)
186+
.expectComplete()
187+
.verify(Duration.ofSeconds(5));
188+
}
189+
190+
@Test
191+
void delete() {
192+
mockRequest(
193+
InteractionContext.builder()
194+
.request(
195+
TestRequest.builder()
196+
.method(DELETE)
197+
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
198+
.build())
199+
.response(
200+
TestResponse.builder()
201+
.status(ACCEPTED)
202+
.build())
203+
.build());
204+
205+
this.users
206+
.delete(DeleteUserRequest.builder()
207+
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
208+
.build()
209+
)
210+
.as(StepVerifier::create)
211+
.expectComplete()
212+
.verify(Duration.ofSeconds(5));
213+
}
214+
215+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
3+
"created_at": "2019-03-08T01:06:19Z",
4+
"updated_at": "2019-03-08T01:06:19Z",
5+
"username": "some-name",
6+
"presentation_name": "some-name",
7+
"origin": "uaa",
8+
"metadata": {
9+
"labels": {},
10+
"annotations": {}
11+
},
12+
"links": {
13+
"self": {
14+
"href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
15+
}
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"metadata": {
3+
"labels": {
4+
"environment": "production"
5+
},
6+
"annotations": {
7+
"note": "detailed information"
8+
}
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
3+
"created_at": "2019-03-08T01:06:19Z",
4+
"updated_at": "2019-03-08T01:06:19Z",
5+
"username": "some-name",
6+
"presentation_name": "some-name",
7+
"origin": "uaa",
8+
"metadata": {
9+
"labels": {
10+
"environment": "production"
11+
},
12+
"annotations": {
13+
"note": "detailed information"
14+
}
15+
},
16+
"links": {
17+
"self": {
18+
"href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
19+
}
20+
}
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
3+
"created_at": "2019-03-08T01:06:19Z",
4+
"updated_at": "2019-03-08T01:06:19Z",
5+
"username": "some-name",
6+
"presentation_name": "some-name",
7+
"origin": "uaa",
8+
"metadata": {
9+
"labels": {},
10+
"annotations": {}
11+
},
12+
"links": {
13+
"self": {
14+
"href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
15+
}
16+
}
17+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.cloudfoundry.client.v3.spaces.SpacesV3;
7373
import org.cloudfoundry.client.v3.stacks.StacksV3;
7474
import org.cloudfoundry.client.v3.tasks.Tasks;
75+
import org.cloudfoundry.client.v3.users.UsersV3;
7576

7677
/**
7778
* Main entry point to the Cloud Foundry Client API
@@ -363,4 +364,9 @@ public interface CloudFoundryClient {
363364
* Main entry point to the Cloud Foundry Users Client API
364365
*/
365366
Users users();
367+
368+
/**
369+
* Main entry point to the Cloud Foundry Users Client API
370+
*/
371+
UsersV3 usersV3();
366372
}

0 commit comments

Comments
 (0)