Skip to content

Commit f5655e8

Browse files
committed
Merge branch '1079-v3-roles' into 4.x
2 parents f153c81 + 52a0557 commit f5655e8

File tree

26 files changed

+1515
-0
lines changed

26 files changed

+1515
-0
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.cloudfoundry.client.v3.organizations.OrganizationsV3;
6262
import org.cloudfoundry.client.v3.packages.Packages;
6363
import org.cloudfoundry.client.v3.processes.Processes;
64+
import org.cloudfoundry.client.v3.roles.RolesV3;
6465
import org.cloudfoundry.client.v3.routes.RoutesV3;
6566
import org.cloudfoundry.client.v3.serviceInstances.ServiceInstancesV3;
6667
import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3;
@@ -114,6 +115,7 @@
114115
import org.cloudfoundry.reactor.client.v3.organizations.ReactorOrganizationsV3;
115116
import org.cloudfoundry.reactor.client.v3.packages.ReactorPackages;
116117
import org.cloudfoundry.reactor.client.v3.processes.ReactorProcesses;
118+
import org.cloudfoundry.reactor.client.v3.roles.ReactorRolesV3;
117119
import org.cloudfoundry.reactor.client.v3.routes.ReactorRoutesV3;
118120
import org.cloudfoundry.reactor.client.v3.servicebindings.ReactorServiceBindingsV3;
119121
import org.cloudfoundry.reactor.client.v3.serviceinstances.ReactorServiceInstancesV3;
@@ -301,6 +303,12 @@ public ResourceMatch resourceMatch() {
301303
return new ReactorResourceMatch(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags());
302304
}
303305

306+
@Override
307+
@Value.Derived
308+
public RolesV3 rolesV3() {
309+
return new ReactorRolesV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags());
310+
}
311+
304312
@Override
305313
@Value.Derived
306314
public RouteMappings routeMappings() {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2013-2020 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.roles;
18+
19+
import org.cloudfoundry.client.v3.roles.CreateRoleRequest;
20+
import org.cloudfoundry.client.v3.roles.CreateRoleResponse;
21+
import org.cloudfoundry.client.v3.roles.DeleteRoleRequest;
22+
import org.cloudfoundry.client.v3.roles.GetRoleRequest;
23+
import org.cloudfoundry.client.v3.roles.GetRoleResponse;
24+
import org.cloudfoundry.client.v3.roles.ListRolesRequest;
25+
import org.cloudfoundry.client.v3.roles.ListRolesResponse;
26+
import org.cloudfoundry.client.v3.roles.RolesV3;
27+
import org.cloudfoundry.reactor.ConnectionContext;
28+
import org.cloudfoundry.reactor.TokenProvider;
29+
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
30+
import reactor.core.publisher.Mono;
31+
32+
import java.util.Map;
33+
34+
/**
35+
* The Reactor-based implementation of {@link RolesV3}
36+
*/
37+
public final class ReactorRolesV3 extends AbstractClientV3Operations implements RolesV3 {
38+
39+
/**
40+
* Creates an instance
41+
*
42+
* @param connectionContext the {@link ConnectionContext} to use when communicating with the server
43+
* @param root the root URI of the server. Typically something like {@code https://api.run.pivotal.io}.
44+
* @param tokenProvider the {@link TokenProvider} to use when communicating with the server
45+
* @param requestTags map with custom http headers which will be added to web request
46+
*/
47+
public ReactorRolesV3(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider, Map<String, String> requestTags) {
48+
super(connectionContext, root, tokenProvider, requestTags);
49+
}
50+
51+
@Override
52+
public Mono<CreateRoleResponse> create(CreateRoleRequest request) {
53+
return post(request, CreateRoleResponse.class, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("roles"))
54+
.checkpoint();
55+
}
56+
57+
@Override
58+
public Mono<String> delete(DeleteRoleRequest request) {
59+
return delete(request, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("roles", request.getRoleId()))
60+
.checkpoint();
61+
}
62+
63+
@Override
64+
public Mono<GetRoleResponse> get(GetRoleRequest request) {
65+
return get(request, GetRoleResponse.class, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("roles", request.getRoleId()))
66+
.checkpoint();
67+
}
68+
69+
@Override
70+
public Mono<ListRolesResponse> list(ListRolesRequest request) {
71+
return get(request, ListRolesResponse.class, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("roles"))
72+
.checkpoint();
73+
}
74+
75+
}

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/ReactorCloudFoundryClientTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public void resourceMatch() {
140140
assertThat(this.client.resourceMatch()).isNotNull();
141141
}
142142

143+
@Test
144+
public void rolesV3() {
145+
assertThat(this.client.rolesV3()).isNotNull();
146+
}
147+
143148
@Test
144149
public void routeMappings() {
145150
assertThat(this.client.routeMappings()).isNotNull();
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
/*
2+
* Copyright 2013-2020 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.roles;
18+
19+
import org.cloudfoundry.client.v3.Link;
20+
import org.cloudfoundry.client.v3.Pagination;
21+
import org.cloudfoundry.client.v3.Relationship;
22+
import org.cloudfoundry.client.v3.ToOneRelationship;
23+
import org.cloudfoundry.client.v3.roles.CreateRoleRequest;
24+
import org.cloudfoundry.client.v3.roles.CreateRoleResponse;
25+
import org.cloudfoundry.client.v3.roles.DeleteRoleRequest;
26+
import org.cloudfoundry.client.v3.roles.GetRoleRequest;
27+
import org.cloudfoundry.client.v3.roles.GetRoleResponse;
28+
import org.cloudfoundry.client.v3.roles.ListRolesRequest;
29+
import org.cloudfoundry.client.v3.roles.ListRolesResponse;
30+
import org.cloudfoundry.client.v3.roles.RoleRelationships;
31+
import org.cloudfoundry.client.v3.roles.RoleResource;
32+
import org.cloudfoundry.client.v3.roles.RoleType;
33+
import org.cloudfoundry.reactor.InteractionContext;
34+
import org.cloudfoundry.reactor.TestRequest;
35+
import org.cloudfoundry.reactor.TestResponse;
36+
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
37+
import org.junit.Test;
38+
import reactor.test.StepVerifier;
39+
40+
import java.time.Duration;
41+
import java.util.Collections;
42+
43+
import static io.netty.handler.codec.http.HttpMethod.DELETE;
44+
import static io.netty.handler.codec.http.HttpMethod.GET;
45+
import static io.netty.handler.codec.http.HttpMethod.POST;
46+
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
47+
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
48+
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
49+
50+
public class ReactorRolesV3Test extends AbstractClientApiTest {
51+
52+
private final ReactorRolesV3 roles = new ReactorRolesV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap());
53+
54+
@Test
55+
public void create() {
56+
mockRequest(InteractionContext.builder()
57+
.request(TestRequest.builder()
58+
.method(POST).path("/roles")
59+
.payload("fixtures/client/v3/roles/POST_request.json")
60+
.build())
61+
.response(TestResponse.builder()
62+
.status(CREATED)
63+
.payload("fixtures/client/v3/roles/POST_response.json")
64+
.build())
65+
.build());
66+
67+
this.roles.create(CreateRoleRequest.builder()
68+
.type(RoleType.ORGANIZATION_AUDITOR)
69+
.relationships(RoleRelationships.builder()
70+
.user(ToOneRelationship.builder()
71+
.data(Relationship.builder()
72+
.id("test-user-id")
73+
.build())
74+
.build())
75+
.organization(ToOneRelationship.builder()
76+
.data(Relationship.builder()
77+
.id("test-organization-id")
78+
.build())
79+
.build())
80+
.build())
81+
.build())
82+
.as(StepVerifier::create)
83+
.expectNext(CreateRoleResponse.builder()
84+
.id("40557c70-d1bd-4976-a2ab-a85f5e882418")
85+
.createdAt("2019-10-10T17:19:12Z")
86+
.updatedAt("2019-10-10T17:19:12Z")
87+
.type(RoleType.ORGANIZATION_AUDITOR)
88+
.relationships(RoleRelationships.builder()
89+
.organization(ToOneRelationship.builder()
90+
.data(Relationship.builder()
91+
.id("test-organization-id")
92+
.build())
93+
.build())
94+
.user(ToOneRelationship.builder()
95+
.data(Relationship.builder()
96+
.id("test-user-id")
97+
.build())
98+
.build())
99+
.space(ToOneRelationship.builder()
100+
.build())
101+
.build())
102+
.link("self", Link.builder()
103+
.href("https://api.example.org/v3/roles/40557c70-d1bd-4976-a2ab-a85f5e882418")
104+
.build())
105+
.link("user", Link.builder()
106+
.href("https://api.example.org/v3/users/test-user-id")
107+
.build())
108+
.link("organization", Link.builder()
109+
.href("https://api.example.org/v3/organizations/test-organization-id")
110+
.build())
111+
.build())
112+
.expectComplete()
113+
.verify(Duration.ofSeconds(5));
114+
}
115+
116+
@Test
117+
public void delete() {
118+
mockRequest(InteractionContext.builder()
119+
.request(TestRequest.builder()
120+
.method(DELETE).path("/roles/test-role-id")
121+
.build())
122+
.response(TestResponse.builder()
123+
.status(ACCEPTED)
124+
.header("Location", "https://api.example.org/v3/jobs/test-role-id")
125+
.build())
126+
.build());
127+
128+
this.roles
129+
.delete(DeleteRoleRequest.builder()
130+
.roleId("test-role-id")
131+
.build())
132+
.as(StepVerifier::create)
133+
.expectNext("test-role-id")
134+
.expectComplete()
135+
.verify(Duration.ofSeconds(5));
136+
}
137+
138+
@Test
139+
public void get() {
140+
mockRequest(InteractionContext.builder()
141+
.request(TestRequest.builder()
142+
.method(GET).path("/roles/40557c70-d1bd-4976-a2ab-a85f5e882418")
143+
.build())
144+
.response(TestResponse.builder()
145+
.status(OK)
146+
.payload("fixtures/client/v3/roles/GET_{id}_response.json")
147+
.build())
148+
.build());
149+
150+
this.roles
151+
.get(GetRoleRequest.builder()
152+
.roleId("40557c70-d1bd-4976-a2ab-a85f5e882418")
153+
.build())
154+
.as(StepVerifier::create)
155+
.expectNext(GetRoleResponse.builder()
156+
.id("40557c70-d1bd-4976-a2ab-a85f5e882418")
157+
.type(RoleType.ORGANIZATION_AUDITOR)
158+
.createdAt("2019-10-10T17:19:12Z")
159+
.updatedAt("2019-10-10T17:19:12Z")
160+
.relationships(RoleRelationships.builder()
161+
.organization(ToOneRelationship.builder()
162+
.data(Relationship.builder()
163+
.id("test-organization-id")
164+
.build())
165+
.build())
166+
.user(ToOneRelationship.builder()
167+
.data(Relationship.builder()
168+
.id("test-user-id")
169+
.build())
170+
.build())
171+
.space(ToOneRelationship.builder()
172+
.build())
173+
.build())
174+
.link("self", Link.builder()
175+
.href("https://api.example.org/v3/roles/40557c70-d1bd-4976-a2ab-a85f5e882418")
176+
.build())
177+
.link("user", Link.builder()
178+
.href("https://api.example.org/v3/users/test-user-id")
179+
.build())
180+
.link("organization", Link.builder()
181+
.href("https://api.example.org/v3/organizations/test-organization-id")
182+
.build())
183+
.build())
184+
.expectComplete()
185+
.verify(Duration.ofSeconds(5));
186+
}
187+
188+
@Test
189+
public void list() {
190+
mockRequest(InteractionContext.builder()
191+
.request(TestRequest.builder()
192+
.method(GET).path("/roles")
193+
.build())
194+
.response(TestResponse.builder()
195+
.status(OK)
196+
.payload("fixtures/client/v3/roles/GET_response.json")
197+
.build())
198+
.build());
199+
200+
this.roles.list(ListRolesRequest.builder().build())
201+
.as(StepVerifier::create)
202+
.expectNext(ListRolesResponse.builder()
203+
.pagination(Pagination.builder()
204+
.totalResults(3)
205+
.totalPages(2)
206+
.first(Link.builder()
207+
.href("https://api.example.org/v3/roles?page=1&per_page=2")
208+
.build())
209+
.last(Link.builder()
210+
.href("https://api.example.org/v3/roles?page=2&per_page=2")
211+
.build())
212+
.next(Link.builder()
213+
.href("https://api.example.org/v3/roles?page=2&per_page=2")
214+
.build())
215+
.build())
216+
.resource(RoleResource.builder()
217+
.id("40557c70-d1bd-4976-a2ab-a85f5e882418")
218+
.createdAt("2019-10-10T17:19:12Z")
219+
.updatedAt("2019-10-10T17:19:12Z")
220+
.type(RoleType.ORGANIZATION_AUDITOR)
221+
.relationships(RoleRelationships.builder()
222+
.organization(ToOneRelationship.builder()
223+
.data(Relationship.builder()
224+
.id("test-organization-id")
225+
.build())
226+
.build())
227+
.user(ToOneRelationship.builder()
228+
.data(Relationship.builder()
229+
.id("test-user-id")
230+
.build())
231+
.build())
232+
.space(ToOneRelationship.builder()
233+
.build())
234+
.build())
235+
.link("self", Link.builder()
236+
.href("https://api.example.org/v3/roles/40557c70-d1bd-4976-a2ab-a85f5e882418")
237+
.build())
238+
.link("user", Link.builder()
239+
.href("https://api.example.org/v3/users/test-user-id")
240+
.build())
241+
.link("organization", Link.builder()
242+
.href("https://api.example.org/v3/organizations/test-organization-id")
243+
.build())
244+
.build())
245+
.resource(RoleResource.builder()
246+
.id("12347c70-d1bd-4976-a2ab-a85f5e882418")
247+
.createdAt("2047-11-10T17:19:12Z")
248+
.updatedAt("2047-11-10T17:19:12Z")
249+
.type(RoleType.SPACE_AUDITOR)
250+
.relationships(RoleRelationships.builder()
251+
.space(ToOneRelationship.builder()
252+
.data(Relationship.builder()
253+
.id("test-space-id")
254+
.build())
255+
.build())
256+
.user(ToOneRelationship.builder()
257+
.data(Relationship.builder()
258+
.id("test-user-id")
259+
.build())
260+
.build())
261+
.organization(ToOneRelationship.builder()
262+
.build())
263+
.build())
264+
.link("self", Link.builder()
265+
.href("https://api.example.org/v3/roles/12347c70-d1bd-4976-a2ab-a85f5e882418")
266+
.build())
267+
.link("user", Link.builder()
268+
.href("https://api.example.org/v3/users/test-user-id")
269+
.build())
270+
.link("space", Link.builder()
271+
.href("https://api.example.org/v3/spaces/test-space-id")
272+
.build())
273+
.build())
274+
.build())
275+
.expectComplete()
276+
.verify(Duration.ofSeconds(5));
277+
}
278+
279+
}

0 commit comments

Comments
 (0)